Programming Question


Let’s say you had a program for looking up the businesses in a given city.  Each business location serves a set of zip codes.  It performs perfectly when you enter a zip code, of course, but when you try by city name, there’s a problem.

Some city names are reused in the USA.  Big country, so we have several Parises, a few dozen Auburns, and probably more than fifty Riversides.  Of these cities, there is often a more notable one – the one you were trying to find.  You want the Pittsburgh in PA, not the Pittsburgh in Florida or whatever.

But the program, when searched by name, comes back with every result except the most popular one.  You get the Santa Fe from Montana Nebraska and New Jersey, but not the one from New Mexico.

Why would this happen?  Feels to this nonexpert there’d be a simple obvious reason and fix.  Totally theoretical, can’t show u the code, what do you think?

Comments

  1. OverlappingMagisteria says

    I had a GPS that did this. It knows that Boston, MA is 10 miles away, but maybe I really want to drive 1,500 miles to Boston, Missouri.

    Could be a lot of reasons, but mostly it comes down to not sorting the results in any logical way. It searches its database for all cities that match. My GPS should sort by distance. Your program should sort by popularity (although keeping an extra value for popularity of every town is probably too much hassle for most smaller developers). Instead, it returns the results unsorted. It might be the order they happen to be in the database.

    Not sure why the main city does not show up at all. Perhaps the city you actually want is so far down it doesn’t bother to list it? It might only request the top X results?

  2. mordred says

    Doesn’t sound to me as a problem that needs a complicated algorithm, but rather more information. If your city database contains the number of inhabitants of each location it would be simple to sort the results by this number and return the most populous places first.

    On the other hand the strange behaviour you describe could come from someone sorting the cities in exactly the wrong order and then cuttting of the number of results before the more populous cities show up.

    That sorting could happen accidently, if someone imported a list of cities that was sorted by the number of inhabitants starting with the biggest, they might end up physically stored in ascending order. Depending on the database used and the way it is queried by the software, the results could then be returned in exactly that order.

  3. pete says

    The other thing to check is the spelling/case of the largest city of that name. If you look up by a known postal code in the largest city, then see how the name is displayed – often with imported data there is some strangeness about spellings that makes them invisible.

    Or as mordred suggested, a sorting followed by an off by one error so that the last item (or first item) in the list is omitted from the display.

    Or you could put it down to someone thinking that if you are searching by name,then you should be using the districts in the large city, not the city name

  4. lochaber says

    a bit off-topic, so apologies if this deserves deletion or a smackdown or whatever…

    But, a while back, I believe you had a post about computers, and I mentioned Framework.

    Anyways… I had a recent scare with the trackpad/keyboard on my latest laptop, and had been thinking about getting a new computer, and had a recent raise, and a lot of work travel this summer (get up to X amount of food reimbursed), so I went and purchased a Framework 16 (got the RAM and SSD separately as everyone advises, saves a couple hundred or so)

    Haven’t been using it long, and still in the set up process (using a linux distro I’m not familiar with, so a bit of a learning curve with the random odds and ends), but with the whole modular/repair-ability thing, I expected it to be rather bulky, but it’s actually slightly more compact than my previous laptop.

    Not a whole lot to be obvious off-the-bat, but if anyone is interested, I wouldn’t mind relating my experience with this computer in the future. I’m already low-key considering buying backup/replacement keyboard and trackpad components, just to have a backup on hand, since that’s a pretty cheap fix, and has failed in a couple of my previous laptops.

  5. moarscienceplz says

    Just a guess, but if you first searched a zip code in Santa Fe, NM and then searched for a city named Santa Fe, the search engine might conclude that you were not satisfied with results from Santa Fe, NM, and would block further results from that city. I would try searching first for Albuquerque (not much chance of a duplicate there) and then search Santa Fe. If you get the one in NM as the first result that would at least show the database knows that one, but is sometimes hiding that result for some reason.

  6. says

    if it helps, this is a web-based program originally designed to work in internet exploder but runs equally in chromium browsers, idk if it uses css or java or hamsters, and it runs off intranet.

    while truncated list ideas is sound, it’s not consistent with my experience. i’ve seen a list of two which omitted the most popular/populous city, and lists of four which did the same.

    also, sometimes it randomly works right, which causes my employer to deprioritize a fix. just drives me up a wall having to google zip codes whenever a client asks for the servicing location in city X.

  7. says

    re: districts, we all know the neighborhoods of nyc, but I couldn’t name one in phoenix, so doubt that’s it.
    re: populace, i doubt the very rudimentary program includes that info, but can’t rule it out.
    re: including state in search, i might try it.
    re: OT computering, that’s fine, thx for the info.

  8. another stewart says

    An alternative to the prominent one being too far down the list (that’s likely to be inconsistent – try a name which only occurs a few times in the US) is that they are sorted sensibly, but the display code starts at index 1 rather than index 0.

  9. Bekenstein Bound says

    Just throwing this out there, as no one else has suggested it yet: sorting by populace combined with integer overflow. If the data type used for the populace when sorting is too small, the largest cities could end up as negative numbers, which it might then discard as erroneous, or else would end up sorting to the very bottom of the list when you wanted them at the top.

    What happens if you search for a town name where the largest one still only has thousands, or for a completely unique city name that has millions?

  10. says

    i keep forgetting to try that. it’s one of those things where it pops up a list of results as you type, and narrows it down. my assumption has been that if the city i want is not in the list, it won’t show if i hit enter. i don’t know.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.