Answer the question
In order to leave comments, you need to log in
How to set PHP + MySQL search relevancy?
Good afternoon.
Search example - https://4ip.info/
Enter "iphone 6", returns everything containing iphone 6 or iphone 6s , but does not return, for example, from the string, iPhone 7 1960 mAh, orig.
The same goes for "6 iphone" .
Searching for structures like '%iphone%' and like '6' will find a bunch of extra stuff. Full-text search generally scores on the number 6. Sphinx will also chew the figure, most likely.
There is an idea with a dictionary, but I hope that it is possible to organize it somehow easier.
I would appreciate suggestions, thanks.
Answer the question
In order to leave comments, you need to log in
I solved the problem in the framework of php + mysql. Search is not loaded on the site. Here is the solution:
Started a dictionary of models.
<?
$slovar = array(
'iphone 6' => 'iphone 6',
'6 iphone' => 'iphone 6',
'iphone 6s' => 'iphone 6s',
'6s iphone' => 'iphone 6s',
'iphone 7' => 'iphone 7',
'7 iphone' => 'iphone 7',
'iphone 7s' => 'iphone 7s',
'7s iphone' => 'iphone 7s',
);
$tmp = substr( $tmp, 0, 40 ); //обрезаем строку
//делаем массив с подчеркиваниями
foreach($slovar as $k=>$v){
$arr1[] = $k;
$arr2[] = str_replace(" ", "_", $v);
}
//заменяем в поисковом запросе словосочетания
$tmp = str_replace($arr1, $arr2, $tmp);
//бьем поисковую строку на пробелы
$tmp = explode( ' ', $tmp );
//пробелы заменяем на конструкцию SQL
$where = "`title` LIKE '%" . implode ( "%' AND `title` LIKE '%", $tmp ) . "%'";
//возвращаем в запрос обратно пробелы
$where = str_replace("_", " ", $where);
Sphinx will also chew the figure, most likely.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question