Giter Site home page Giter Site logo

Can we have search about city-state HOT 2 OPEN

thecodecrate avatar thecodecrate commented on July 21, 2024 1
Can we have search

from city-state.

Comments (2)

loureirorg avatar loureirorg commented on July 21, 2024

sorry for the long delay @ovamsikrishna. It's a great idea, it can be useful on autocomplete inputs. I'm just not sure on how to make this.

Currently we have about 87k cities around the world. So, let's say that we have an array with all these cities on memory, an array of strings like "Ananindeua,Para,Brazil" - this would cosume more than 8MB. On a simple implementation, the CS.search method could test each city against an regex, but this would spend around 87.000 regex calls each time, which can lead to performance issues - mainly if you want to use it with some "autocomplete ajax" feature.

One way to improve the results would be by installing the CityState on the user's database. Curently we are using a simple yml file as database (as there's no need to perform any complex query). But this would require one more step on the user perspective (to install the database) and also it will increase the script complexity.

Another way to implement this is to make a sort of FTS (full text search) engine inside the gem. It can be something like a txt file with all cities (eg: "Ananindeua,Para,Brazil", one per line). And another file indexing this (a graph tree, maybe).

For the simplicity sake, I think the simple "87k regex calls" would be the best choice - not the best, but the more feasible (unless you have a lots of spare time). Unfortunatelly I don't have much time to implement this (although I believe that it will be just an ".each" with 2 lines of code, plus some tests), but I'll try to implement as soon as possible (as I believe it's a good idea).

PS: feel free to suggest another approaches or to implement by yourself and send these changes as a PR.

from city-state.

vamsi-krishna-E0029 avatar vamsi-krishna-E0029 commented on July 21, 2024

@loureirorg Well, these were the options I had in my mind before asking this question. As of now we are doing the "k regex calls". We are having an array of strings as you said. If a gem using the open source like Maxmind can do this I thought I can avoid all these functionalities in the application level. If Maxmind can give such API then it would be damn easier. I may not go for a PR as I don't have much time to spend in this area. But, will definitely let you know if I have a better approach.

from city-state.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.