Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve place search speed by ~10x #1236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

leekleak
Copy link
Contributor

@leekleak leekleak commented Jan 21, 2025

I was testing to see why places search did not work for me but it seems like it was just incredibly sluggish.
The culprit was the around parameter which is very very slow for some reason. I changed it to use a bounding box and that had a huge impact where a simple search of around 4km went from 10s to less than 1 for me.

The only downside is that the radius setting is mostly inaccurate as bounding box parameters are degrees and not meters. I used an approximation where 0.00001deg is around 1.1m, so if the radius is set to 4km, the results will come from around 4.5km radius (actually more since the bounding box is a rectangle and not a circle, so at the extreme you could get results from up to 6.3km)

Not sure what to do with the setting though - maybe make the settings vague to reduce the impression of specificity... Or maybe the results should be filtered out and discarded if they are too far away.

@leekleak leekleak changed the title Improve place search speed by Improve place search speed by ~10x Jan 21, 2025
@shtrophic
Copy link
Contributor

The bounding box will have a different size at different latitudes and same settings, correct?

@leekleak
Copy link
Contributor Author

The bounding box will have a different size at different latitudes and same settings, correct?

Yes. When I looked at approximations the article claimed that the rate is steady in most inhabitable areas, however the more I think about it the less sense that makes. I'll add a conversion tommorow.

@shtrophic
Copy link
Contributor

There are some static convenience methods somewhere in the android.Location class for working with the earth ellipsoid... I don't remember for sure if that was its fully qualified name... Might help!

@leekleak
Copy link
Contributor Author

Seems like a pretty simple fix. I also added a check to throw away results outside the search radius.

@shtrophic
Copy link
Contributor

If it actually makes it possible to go to downtown new york and query "pizza" with a search radius of 10km, I'm all for it :)

LGTM 👍🏼

@leekleak
Copy link
Contributor Author

If it actually makes it possible to go to downtown new york and query "pizza" with a search radius of 10km, I'm all for it :)

It does!

Also, just another thing I noticed -- It seems like the results are also different (better!) than before. It looks like the search by name tag currently times out when looking for pizza at nyc leaving only results by brand tag, which are much more rare and thus much farther away.

@shtrophic
Copy link
Contributor

Makes sense.

Osm search could be improved still, ideally with something like a local cache of that bounding box, to run some more advanced queries on. I once had the idea to match for localized user searches and then translate that into a osm category, e.g. a user types "bäckerei", which will then be queries as category:bakery, and so on. Would probably take too much effort though, for such a niche feature... Anyway, thanks for taking the time and looking into my Osm code :)

@MM2-0
Copy link
Owner

MM2-0 commented Jan 27, 2025

I once had the idea to match for localized user searches and then translate that into a osm category, e.g. a user types "bäckerei", which will then be queries as category:bakery, and so on. Would probably take too much effort though, for such a niche feature..

We already have localized strings for the most important categories. Adding a reverse lookup string matching between string resource and OSM category and including that category in the overpass query actually sounds pretty doable. Not a bad idea at all.

@leekleak
Copy link
Contributor Author

leekleak commented Jan 27, 2025

Actually I think a better idea would be to have a little table of preset amenity types appear when searching (either automatically or whenever you select to specifically search locations). You click the type you want and it searches the nearby features. I think trying to guess what the user wants just from the search input (especially concerning localized text) can be mildly to extremely finicky.

@shtrophic
Copy link
Contributor

shtrophic commented Jan 27, 2025

I think trying to guess what the user wants just from the search input (especially concerning localized text) can be mildly to extremely finicky.

That's my concern as well. For example, for terms with accents, like "café" we would have to ask ourselves if we'd also accept "cafe". (And I'm sure there are more complicated cases.) Is that easily possible? After all, we cannot keep track of all variations in all languages. Or does weblate make this possible?

Actually I think a better idea would be to have a little table of preset amenity types appear when searching

That's more UI and we already have the filterbar... And I have the feeling that many users don't know how to use that correctly anyway?

@leekleak
Copy link
Contributor Author

Also, we can't expect an average user to know any osm tags. I myself would get a headache trying to figure out wheter I should write "Shop", "Store", "Grocery" or "Supermarket" as to me they mean the exact same thing.

That's more UI and we already have the filterbar...

Screenshot_20250127_221821_Kvaesitso.jpg

I imagined something like this popping up once you specify you will be searching places.

And I have the feeling that many users don't know how to use that correctly anyway?

Oh absolutely! I only understood that I had to press the "Online Results" to search places and wikipedia once I literally opened up the code of the app.

@MM2-0
Copy link
Owner

MM2-0 commented Jan 27, 2025

That's my concern as well. For example, for terms with accents, like "café" we would have to ask ourselves if we'd also accept "cafe". (And I'm sure there are more complicated cases.) Is that easily possible?

We already do that for the app search, all accents are stripped and some sort of fuzzy matching is applied.

Step 1: Read the available strings from resources and put them in a List<Pair<String, String>> with the appropriate category name as the second argument of each pair.

Step 2: Filter that list using the same string maching logic we apply when we are filtering the list of apps.

Step 3: Add the categories to the overpass query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants