H
H
hesy2019-12-22 10:05:02
PHP
hesy, 2019-12-22 10:05:02

How to do a search by name?

Good afternoon.
I'm trying to search for a movie title in the database with the following SQL query:

// [name] => Проект засекречен / Проект «Синяя книга»
$connection->table('serials')
                  ->where('name', 'LIKE', '%синяя книга%')
                  ->get();

Zero results after execution .
BUT , if you leave only the "book" he will successfully find. And again BUT, if instead of "book" you make a request "blue" - the request will return nothing again.
Everything is bad with sql, so I ask you to tell me how to make a "search by name", where, for example, there is the name "Castle Rock", and you can score in the search as "Castle Rock" ..

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hesy, 2019-12-22
@hesy

After half a day, I found a solution to the problem.
I made a custom function for converting a string to lowercase, since lower() refused to work with Cyrillic.

... 

function mb_lower($str) {
    return mb_strtolower($str);
}

// Если используется PDO:SQLite
$db->sqliteCreateFunction('mb_lower', 'mb_lower', 1);

// Если используется расшриение SQLite3 
// $db->createFunction('mb_lower', 'mb_lower');

$sql = 'SELECT name, season, episode FROM serials WHERE mb_lower(name) LIKE mb_lower("%хОдЯчиЕе МеРТВЕЦЫ%")';

...

Now everything works as it should =)

D
Dmitry Shitskov, 2019-12-22
@Zarom

Could it be a case problem? Try a case-insensitive search and if it works, use the solution from the answer
https://stackoverflow.com/a/2876820

D
Dimonchik, 2019-12-22
@dimonchik2013

learn what % is in the query
then you will learn how to compose
'%blue%book%'
'blue%book%' - works faster
'blue%book%' etc.
with Karsluhe it is more difficult - this is done by fuzzy matching and synonyms in full-text search systems
and yes - in Muskul it is better to use www.mysql.ru/docs/man/Fulltext_Search.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question