Comments (2)
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.
@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)
- New Feature Request; zipcode should also be there with cities.
- How to change db data locally?
- Some cities are not showing for some states HOT 1
- Unable to update from Rails console, changes lost after closing console HOT 1
- Ability to query cities by country name in addition to country code HOT 1
- Invalid data for GB HOT 1
- broken link
- NoMethodError: undefined method `present?' for :US:Symbol HOT 1
- missing city Surat
- Is there a plan to include timezone in?
- Singapore cities are missing but present in MaxMind DB HOT 2
- Typo correction "Tithari" should be changed to "Ithari" for Nepal HOT 2
- Failed to open TCP connection to geolite.maxmind.com:80 (getaddrinfo: No address associated with hostname) (SocketError) HOT 4
- Renaming a city or Delete city HOT 3
- How to access cities when tthere is no states present for a countrry.
- Permission errors on deploy
- "No such file or directory @ rb_sysopen <url>" when attempting update
- Not working with ruby 3.2 HOT 5
- Cannot list all existing cities to check if certain city exists or not right away
- Error "Did you mean? exist?" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from city-state.