pelias / api

HTTP API for Pelias Geocoder
http://pelias.io
MIT License
219 stars 162 forks source link

Use match_all for focus point queries #1485

Closed orangejulius closed 4 years ago

orangejulius commented 4 years ago

We handle the focus.point parameter by using the function_score Elasticsearch query. function_score requires a function, and a query.

For historical reasons, we use a match_phrase query based on some of the input text for this query. However, there's really no reason to do so, we want the function score for distance from the focus point to apply to all results, not just the subset of results that match the match_phrase query.

Usually, the subset of results that has the focus point scoring applied is almost 100% of all results, but not always, which can be very confusing.

orangejulius commented 4 years ago

Worth noting we already started using match_all quite a while ago for the other function_score query components (population and popularity) in https://github.com/pelias/api/pull/1356

orangejulius commented 4 years ago

Okay, because it's pretty easy for now, I ran this through our full test suite just because I wanted to make sure we weren't missing anything.

There are in fact some extremely small changes from this PR: Screenshot_2020-08-19_16-15-44

In both cases, a nearby result is now boosted higher than the "expected" result.

Thinking about it more, the logic before this PR was essentially "if a result is not a very good text match (all tokens in the input text present), don't give it a scoring boost for being close to the focus point".

There actually could be some validity to that sort of approach. But the way we were doing it is not the way, we would want to apply a lot more nuance and control. So this PR is good to go :)