Suppose there are such records in the Person database.

 + ---- + ------------------- +
 |  id |  fio | 
 + ---- + ------------------- +
 |  1 |  Petrov Alexey | 
 |  2 |  Andreev Valentin | 
 + ---- + ------------------- +

Then, using the usual filter Person.filter(fio__contains='Петров') we get the first entry. But if instead of a line Petrov to drive Alexei Petrov, then he will give us a zero result. The same applies to abbreviations, for example, if you drive in Petrov A. What to do in this situation.

  • one
    Split Fio into three columns and search for each separately? - andreymal
  • Or to organize a full-text search, depending on how smart the search is needed - andreymal
  • @andreymal, the search itself is organized in ember. When dividing each column by three, will it affect performance? Can you elaborate on full-text search? - zakiroof
  • Productivity plays a key role, there can be a lot of records - zakiroof
  • On a full-text search, this is google in the direction of Sphinx / Solr / ElasticSearch, my Sphinx on 10 million records works well - andreymal

1 answer 1

I didn’t get too much, I did it in a simple way:

 search_str = search_str.replace('.', ' ') search_str_split = search_str.split(' ') for item in search_str_split: query = Person.filter(fio__contains=item) 

When creating a user, I needed to display a message that a user with such a full name may already exist. If the user types Петров А. , then I simply remove the dot, divide the line into words, and check each word. If the user enters the full name back to before, then this method also works. I don’t know if it’s right, but as my grandfather said, “It works, don’t touch it.”