api icon indicating copy to clipboard operation
api copied to clipboard

Changed search behaviour with an empty ?categories parameter

Open NickStallman opened this issue 6 years ago • 4 comments

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?

NickStallman avatar Oct 17 '19 22:10 NickStallman

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?

missinglink avatar Oct 18 '19 07:10 missinglink

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?

missinglink avatar Oct 18 '19 07:10 missinglink

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.

NickStallman avatar Oct 18 '19 19:10 NickStallman

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 :)

missinglink avatar Oct 21 '19 21:10 missinglink