I have a name in the document:
The lamp with the metal case

After processing, I get an array of words:

array ([0]=>Светильник [1]=>с [2]=>металлическим [3]=>корпусом) 

At the base I have the position:

 Светильник с металлическим корпусом Светильник с пластмассовым корпусом Светильник люминесцентный модель "СЛ-106" с плафоном и выключателем 

For a more or less adequate search, I came up with a construct like a horribly nested query:

 SELECT * FROM ( SELECT * FROM ( SELECT * FROM ( SELECT * FROM 'materials' WHERE 'title' LIKE 'Светильник%') WHERE 'title' LIKE '%c%') WHERE 'title' LIKE '%металлическим%') WHERE 'title' LIKE '%корпусом%' 

Those. the idea is to filter out the options sequentially starting with the first word in the line, etc.

Such a request, of course not a worker, just tried to convey a thought. Do not tell me how you can implement this in one request?

  • После обработки я получаю массив слов - explain this phrase. SQL basically does not know what an array is. Well and at the same time specify WHERE it is obtained this ... array. - Akina
  • Specify the question of the structure of the table materials . Is the phrase "lamp with a metal case" stored there as one line in the title field or split into 4 lines of the table? And specify the used DBMS (by syntax I assume that MySQL and the request is sent from PHP) - Herman Borisov

2 answers 2

You need to use full-text search, and, accordingly, a full-text index. This your orgy of nested queries, coupled with the widespread use of LIKE (which is a rather slow operation, since it scans all the lines) will kill any server if the base is large or there are a lot of words in the query.

  • Thanks for the advice! Rewrote the system under the full-text index. - OldKitty
  • Do not tell me how to perform a query of this type: SELECT * FROM (SELECT * FROM materials add AS - OldKitty

Did you mean it?

 SELECT * FROM 'materials' WHERE 'title' LIKE 'Светильник%' and 'title' LIKE '% c %' and 'title' LIKE '%металлическим%' and 'title' LIKE '%корпусом%'