api
api copied to clipboard
Changed search behaviour with an empty ?categories parameter
Hey team!
I found this rather strange issue where I was sending an empty categories= parameter by default. Normally this works perfectly and doesn't seem to change the search results.
https://pelias.github.io/compare/#/v1/search%3Fcategories=&boundary.country=AU&layers=locality&size=1&text=crows+nest%252C+nsw "Gnows Nest, WA" is obviously not "Crows Nest, NSW".
Removing the empty ?categories and it works perfectly as expected: https://pelias.github.io/compare/#/v1/search%3Fboundary.country=AU&layers=locality&size=1&text=crows+nest%252C+nsw
It's an easy fix on my side but I can't figure out the mechanism which produces this behaviour, surely this is a bug?
That's very odd, I can't imagine what would be causing it.
We've had a few bugs reported with how the compare app handles encoding and decoding of the input box to the URL hash.
Is this specific to the compare app or is it the same behaviour using something like curl?
IIRC from when I did the PR for that, you should be able to simply write &categories& instead of &categories=& though the two forms should be equivalent.
Does changing that form make any difference to the behavior?
Yeah I know about the compare app's quirks. :) That's not the culprit, I found this on my pelias API directly and the compare app confirms it.
Including or excluding the = doesn't make a difference. If categories are there then it goes haywire on this example, remove it and it behaves perfectly. This is the only case I've noticed like this however. It could be tricky to find additional examples.
Agh, I think I know what's going on!
This is the line responsible: https://github.com/pelias/api/blob/master/routes/v1.js#L169
What's going on here is, if libpostal parsed the input and thinks it contains admin tokens then it queries placeholder in order to better localize the results.
But.. it doesn't do that if categories have been set because placeholder doesn't know about categories.
You can probably just update that predicate to detect when categories are empty :)