How to search for postal code (ranges)?

Created on 8 June 2023, over 1 year ago
Updated 22 June 2023, over 1 year ago

I've got place information inside taxonomy terms.
Name = Place name (in a hierachy: state, county, town)
postal code (string fields, multiple values allowed) = postal code(s) of a town

Now, I'd like to search for:
9000
and ideally, I'd like to find every taxonomy term, which has postal codes starting with 9000

Now, I've learned from https://www.drupal.org/project/search_api/issues/3114833 that I should be using greater than.
So I'll find:
90001, 90002, 90003, ...

But I won't be able to find something close by, like 89999.

Additionally, if one place has two zip codes:
89990 and 90010
it seems like, I still receive this as a result (since my search would be right in between the two numbers).

Worse: If I sort the results by zip code, 89990 comes first - which I haven't entered at all.

What's a possible way out there?

One more thing:
Any ideas on how to integrate the zip code search with the proximity search from the geo field? Is that possible?

💬 Support request
Status

Fixed

Version

1.29

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @transmitter
  • Status changed to Fixed over 1 year ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    I’m sorry, your description is very confusing, so I’m not sure I got it all right. But I’ll try to answer your questions as best I can:

    But I won't be able to find something close by, like 89999.

    Of course not, you’re filtering for “greater than 9000”. If you want more complex logic, you’ll have to implement that yourself. E.g., filtering for “greater than 8999” might do what you want, depending on what that is. or you could place several filters combined by “OR”.

    Additionally, if one place has two zip codes:
    89990 and 90010
    it seems like, I still receive this as a result (since my search would be right in between the two numbers).

    Of course it will be a result, it matches your criteria. Again, if you want more complex logic, you’ll have to implement that yourself.
    There is no built-in way (as far as I know) of saying “where ALL values are greater than 9000”.

    Worse: If I sort the results by zip code, 89990 comes first - which I haven't entered at all.

    This, too, has no built-in way of solving, filtering is completely independent of sorting. Depending on the backend, it might be possible to always use the highest value for sorting, though, if that might help? But I doubt that that’s what you’re looking for.

    One more thing:
    Any ideas on how to integrate the zip code search with the proximity search from the geo field? Is that possible?

    You’ll need some way to translate the ZIP code to a latitude/longitude pair and then use Search API Location for indexing it and filtering on it.

    Please re-open if anything remains unclear.

  • Thank you very much - Search API Location seems to be the right solution. :)

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024