Skip to content

We should improve substring searching for our Nominatim #454

Closed

Description

@jeffreyameyer

Bug description
What is happening?
Substring matches are not working super-well on OHM Nominatim right now.

For example, searching for "Oregon" does not return "Oregon Territory" in its results.

Strangely, searching on "Territory" or "Marino" seem to work just fine.

image

It's almost as if you are allowed to substring search on everything but the first word in the actual name string. Sarah has pointed out that Nominatim prefers full string matching, but I'm not sure how that's tunable. We should be sure to scour the docs.

What should be happening?
Searching for a substring of any name - including the first word in the name - should return all of the matching results.

Activity

  1. 1ec5 commented on Sep 22, 2022

    @1ec5
    Member

    Could the years at the end of these features’ names be tripping up Nominatim? Many geocoders have difficulty with, for instance, numeric street names, because after tokenization, it becomes unclear whether the number in the query is part of the street name or something else.

    Edit: In #455, @lonvia suggests a custom tokenizer to strip out these dates.

  2. lonvia commented on Sep 23, 2022

    @lonvia

    The strong preference of full-name matches is hard-coded and cannot be changed without changing the code. The logic goes: if there is a full-name match available, partial matches will not be shown. Usually you can get partial matches by using the button 'More results' but I see you have disabled that one.

    If you want to hack around the full-name restriction I recommend you do it in the rails code: check for the number of returned results and if it is too low for your taste, send another request with the more_url that comes with the result.

  3. danrademacher commented on Dec 28, 2022

    @danrademacher

    OK, very belated open issue review here. Updates to Nominatim in the fall led to this being much improved:
    image

    A search for "san marino" now catches all the things we want: https://www.openhistoricalmap.org/search?query=san%20marino#map=13/43.9425/12.4595&layers=O&date=1922-01-01&daterange=1922-01-01,2022-12-31

  4. jeffreyameyer commented on May 10, 2023

    @jeffreyameyer
    MemberAuthor

    This issues appears to have reemerged - maybe a missed catch-up item that needs to be added to a checklist?

    ---> No Oregon Territory in search results:
    https://www.openhistoricalmap.org/search?query=oregon#map=7/44.147/-120.520&layers=O&date=1859-11-22&daterange=1846-07-09,2023-12-31

    San Marino & a few other test results seem fine...

  5. danrademacher commented on May 16, 2023

    @danrademacher
    • Fix the link to OHM nomiatim
    • Figure out how to include "more results" in the return to OHM website
  6. danrademacher commented on May 16, 2023

    @danrademacher

    The OHM Nominatim link was fixed in OpenHistoricalMap/ohm-website@a753c13

  7. 8 remaining items

  8. danrademacher commented on Aug 8, 2023

    @danrademacher

    Notes on this:

    • The "More results" button is missing from our frontend. We don't want to restore that but instead:
    • We should load the full/all results into the sidebar and load those in sidebar
    • Make sure the link to Nominatim passes through the query params
  9. danrademacher commented on Aug 9, 2023

    @danrademacher

    Looking at the API calls here is interesting... I thought we'd just be able to swap from a "fewer, better results" to a "more, less good results" and have the latter include the former, but it's not clear that's the case.

    If I search for "Oakland" with this plain query string:
    https://nominatim.openhistoricalmap.org/search.html?q=oakland

    I get three results. The same as if I use this API endpint:
    https://nominatim-api.openhistoricalmap.org/search.php?q=oakland&polygon_geojson=1&format=jsonv2

    The only difference with More Results is that the first three "best matches" have been excluded:
    https://nominatim.openhistoricalmap.org/search.html?q=oakland&exclude_place_ids=149505%2C142380%2C146834
    and the API:
    https://nominatim-api.openhistoricalmap.org/search.php?q=oakland&polygon_geojson=1&exclude_place_ids=149505%2C142380%2C146834%2C272498%2C1178512%2C1259056%2C1243822%2C1220825%2C847593&format=jsonv2

    looking at the API docs, this seems to be the intended behavior:
    https://nominatim.org/release-docs/latest/api/Search/#result-limitation

    If you do not want certain OSM objects to appear in the search result, give a comma separated list of the place_ids you want to skip. This can be used to retrieve additional search results. For example, if a previous query only returned a few results, then including those here would cause the search to return other, less accurate, matches (if possible).

    OK, but where is the No Results button?

    Here it is in the html.erb:
    https://github.com/OpenHistoricalMap/ohm-website/blob/3dbfdf6b39ef261d412ca17bf77ebdfd05c24fa8/app/views/geocoder/results.html.erb#L13-L22

    Aha, but it was commented out for some reason... way back in 2021!

    https://github.com/OpenHistoricalMap/ohm-website/blame/3dbfdf6b39ef261d412ca17bf77ebdfd05c24fa8/app/controllers/geocoder_controller.rb#L100-L102

    So we can easily restore the More Results link by uncommenting those lines. I'll test that tomorrow.

    I don't see a way to just force the More Results to show up without the second click with the exclusions that force it to return "less desirable" results.

  10. danrademacher commented on Aug 9, 2023

    @danrademacher

    Continuing to file this under "nothing is simple"

    • Under localdev, Nominatim wasn't working for me -- it was hitting OSM Nominatim and returning 404. In my settings.local.yml (which is outside version control) I needed to change line 77nominatim_url: "https://nominatim.openhistoricalmap.org/"
    • That was easy, and now localdev is hitting nominatim.openhistoricalmap.org but still reporting Error contacting nominatim.openhistoricalmap.org: 404

    As a result, I can't test whether simply uncommenting those lines gets us the More Results button back, as a stopgap solution to this issue.

  11. danrademacher commented on Aug 12, 2023

    @danrademacher

    @Rub21 could you confirm if when you run the applicaiton locally, a simple Nominatim search returns results?

    I get this 404:
    image

    I can't quite figure out if this is just an artifact of my installation, or a problem in our localdev generally.

    It does make it hard to debug front-end nominatim issues.

  12. danrademacher commented on Aug 22, 2023

    @danrademacher

    From slack dm:

    you can do the following

    aws eks update-kubeconfig --region us-east-1 --name osmseed-production-v2
    kubectl cluster-info
    kubectl get pods
    kubectl port-forward production-nominatim-api-0 8080:8080
    

    it will forward the 8080 port http://localhost:8080/

    under the container , if you are using linux , you can use the same localhost:8080 but if you are using mac use host.docker.internal:8080

    I ran the aws and kubectl commands and now, on my mac, this link is working:
    http://localhost:8080/search.php?q=oakland&polygon_geojson=1&format=jsonv2 [returns same results as that query on Nominatim directly]
    this is not
    http://host.docker.internal:8080/search.php?q=oakland&polygon_geojson=1&format=jsonv2
    but no change in the behavior of the locally running website — still treats Nominatim as 404.
    Did Nominatim searching work locally for you with or without doing the above?

    Maybe I need to add host.docker.internal:8080 to my Docker configuration somewhere?

  13. danrademacher commented on Aug 22, 2023

    @danrademacher

    Just to clarify this ticket -- I am not trying to run Nominatim locally. I just want to hit the normal nominatim.openhistoricalmap.org endpoint from the local website.

  14. added theissue type on Mar 16, 2025
  15. 1ec5 commented on Jul 15, 2026

    @1ec5
    Member

    about Stanford it return 3 results, but not sure why it is not returning Stanford University, maybe need to re-check the config about amenity=university

    This has to do with importance. Nominatim considers rivers and streets s more important than a simple POI (which a university is). Clicking on 'Search for more results' and the university should appear. Nominatim uses wikipedia/wikidata tags to determine how well known an object is. This should work just fine for you, given that you seem to be using those tags in your database too. At least Stanford university has one. Make sure you download the importances. If your database is small enough, then you should be able to do the update mentioned in the 'Tip' box in reasonable time.

    This discussion showed that the issue was importance ranks, not substring matching. Closing in favor of #1401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions