VladOsadchyi
@VladOsadchyi
Студент

Полнотекстовый поиск по части слова?

Есть таблица
5c9cf02cebac0724468157.png
Есть ключ
5c9cf058e5585743733658.png
Есть запрос
SELECT * FROM `employees` WHERE `id` IN (SELECT `id` FROM `employees` WHERE MATCH(first_name, surname) AGAINST ('*Sur*' IN BOOLEAN MODE))


Если вводить surname с начала слова, н-р Sur, то поиск работает правильно, а если вводить средину или конец, н-р name, то поиск ничего не найдет. Как сделать, чтобы поиск работал по любой части слова, а не только по началу? Всем спасибо за помощь))

UPD: забыл уточнить, что поиск по имя + фамилия(н-р Иванов Иван), также должен работать. Не уточнил, потому что с этим не было проблем :)
  • Вопрос задан
  • 4665 просмотров
Решения вопроса 2
Immortal_pony
@Immortal_pony Куратор тега MySQL
Никак.
Полнотекстовый поиск не работает таким образом. Использовать звездочку перед словом невозможно.
Выдержка из документации:

The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators, it should be appended to the word to be affected. Words match if they begin with the word preceding the * operator.
If a word is specified with the truncation operator, it is not stripped from a boolean query, even if it is too short (as determined from the ft_min_word_len setting) or a stopword. This occurs because the word is not seen as too short or a stopword, but as a prefix that must be present in the document in the form of a word that begins with the prefix. Suppose that ft_min_word_len=4. Then a search for '+word +the*' will likely return fewer rows than a search for '+word +the':
The former query remains as is and requires both word and the* (a word starting with the) to be present in the document.
The latter query is transformed to +word (requiring only word to be present). the is both too short and a stopword, and either condition is enough to cause it to be ignored.


Используйте LIKE. Если у вас меньше 50000 записей о сотрудниках, то запрос с Like будет отрабатывать за пару сотен миллисекунд на любом железе.
Если же база действиельно большая, то берите Sphinx или ElasticSearch - средствами mysql эту проблему решить невозможно.
Ответ написан
romanko_vn
@romanko_vn
А может так field LIKE '%surname%', если правильно понял
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы