The task, in general, is this:

It is necessary to display similar records based on headers from MySQL.

Probably familiar, in almost any CMS there is such a module, and poking around in the code is somehow lazy, and most of them are implemented on the basis of tags, but this method does not suit me. Throw ideas, at least with text, not necessarily code.

  • one
    idea №1 to see how it is implemented "in almost any CMS";) - Alex Kapustin

2 answers 2

Apparently, it means a search in the database in a text field (or varchar ) of similar words. For example:

 mysql_query("SELECT * FROM table WHERE title LIKE '%$part%'"); 

where title is the title.

For example:

 $z; // приходящая фраза (состоит из слов) foreach(explode(' ',$z) as $part){ if(strlen($part)>3){ // всякие мелкие слова не учитываем $part = mysql_real_escape_string($part); $res=mysql_query("SELECT * FROM table WHERE title LIKE '%$part%'"); //..... ну и тут детали // в общем, все записи которые будут - это те, которые содержат то что нужно } } 

$part is a word from the incoming header.

  • one
    Maybe this is what is meant, but this is clearly not the case. With large amounts of data you will kill the base on no such queries. Here at least indexing is needed. - Alex Kapustin
  • Yes, and another error in the code. mysql_real_excape_string -> mysql_real_escape_string . - Oleg
  • Yes, on large queries everything is more complicated. But then let's talk about memcached, distributed servers, MySQL loads, etc. That's what a way - to walk and troll the answers ... Write your answer, if you have "this is clearly not the case." And we will have a look here, as if YOU didn’t miss any “Yes, and another mistake ...” - Cooleronline
  • For good it is necessary to carry out the "language" transformation of each word (morphological? (I do not remember exactly)) i. discard endings and maybe some suffixes and prefixes. This should be done with the text placed in the database, as well as with the words of your query using the same algorithm. It is also advisable to use a kind of thematic dictionary (thesaurus) and work only with words from it (we eliminate garbage). In principle, you can make the completion of the thesaurus. Those. The "garbage" accumulates for a while, and then the system administrator makes a decision on the replenishment of the thesaurus. (Places are few ....) - avp
  • one
    Latent-semantic analysis - Alex Kapustin

Take a look here . The solution described there is clearly better than through like. In general, I really do not recommend using like.

Look here better. Here in Russian in black and white.