P
P
Pro_snap2015-05-01 11:56:38
Sphinx
Pro_snap, 2015-05-01 11:56:38

Sphinx, how to search by one common fio field?

We have a database where a full name is stored in one field, and the last name, first name or patronymic may be absent, it may simply be "Petrov". There is no time to remake the base, it is extensive.
You need to set the search relevance correctly. And adjust the weights for the last name, first name and patronymic, but how to do it with one field?
Now, when entering Ivanovs
Can output for example: Alekseev Andrey Ivanovich
And it is necessary that only Ivanovs be at the top, and the rest at the bottom.
Please help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pro_snap, 2015-05-01
@Pro_snap

The problem is that there can be only one of the components in the fio
Solution:
Settings on nodejs:

sphinx.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED2);
sphinx.SetRankingMode(SphinxClient.SPH_RANK_WORDCOUNT);
sphinx.SetSortMode(SphinxClient.SPH_SORT_EXTENDED, "@weight DESC");

sphinx config:
source source_test
{
 type   = pgsql

 sql_query  = SELECT id, fio FROM testTable
 sql_attr_string = fio
}

index index_test
{
 source   = test
 min_infix_len  = 3
 index_exact_words = 1
 infix_fields  = fio
 charset_type  = utf-8
}

and execute the query:
//формируем строку вида "^иванов*" | "*иванов*" и делаем запрос
var name = "\"^" + req.params.name + "*\" | \"*" + req.params.name + "*\"";
sphinx.Query(name, function (err, result) {
   ...
});

F
Fortop, 2015-05-01
@Fortop

^Ivanov
Provided that your last name is always the first one.
If this is not the case, then the problem is unsolvable.

P
Puma Thailand, 2015-05-01
@opium

Yes, in general, if your database has never been put in order, it is extremely difficult to set some kind of priority, that is, you must first search, and then do the necessary sorting in the program.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question