I looked through some kind of social network and found there an opportunity to search for a person by: name, age, city, country and gender. Interestingly, all this information can be inserted into a single text field, separated by a space. Then the search engine somehow analyzes it very accurately and returns a list of results.
On the one hand, it looks pretty simple: separate the query by space and find all the relevant tables to occur. So far, so good. but
- There are cities with names of more than 2 words, and the user can enter them differently , since this is free text.
- There are more than two words
Question:
How can we break up a query in such a way that we, of course, know what part of it should be sought where? that is, the name in the user table, the city in the city table, the country in the countries, etc.?
What i have done so far:
- populate the data source with all users
- Check if a country from tableexist countries is indicated in the request
- if exists, then filter the data source to have users only from this country
- Check if the Cities table in the query exists in the query
- if exists, then filter the data source to have users only from this city
etc. for each table, while each time we find a match in the table, we remove the part found from the query, leaving us with the freest parameter: name .
This seems to work if the user knew exactly how cities / countries, etc. are written in my db, but the reality is that the user can enter part of the city or mislead the city.
I do not know if I am really in the right direction with what I have done. This is just the starting point ...
PS: I just need a flow of algorithms, so the programming language is not really measured. Any idea or guide is more than welcome.
thanks
source share