I want to conclude similar articles. There is a table of articles, well, let's say with the name, articles with the fields id, text, title, etc. Doing a query like every time you view the article is too resource-intensive. Therefore, you need to somehow write the id-schniki of similar articles to the database. And from there pull out their JOIN request. And add these id at each creation or editing of the article.

As I understand it in mysql there is no split function for a string. Therefore, the conclusion suggests itself that adding a varchar-column of type likes to this table will not solve it. There is an idea to make a separate table with the news_id and news_likes_id . And already there to write down id'shniki of all similar articles. Those. for each article, for example, there will be several lines:

 news_id news_likes_id 1 5 1 6 1 4 4 5 ... 

I hope everything is clear outlined. Maybe you have other ideas?

  • one
    Such things are usually done through tags. And in terms of content, similarity can be detected only if an indexing system of the type [sphinx] [1] is used. [1]: en.wikipedia.org/wiki/… - KiTE
  • Well, you can do the same thing yourself :) But is it really necessary?) - Alex Kapustin

1 answer 1

If “The easiest way,” then make two more tables:

 tags id | tag tag_article id | tag_id | article_id 

and in each article you need to put down these tags.

But similar ones are to select articles in which there are data tags, excluding the current one.

let's say curId is the current id of the article.

 select article_id from tag_article where tag_id in (select tag_id from tag_article where article_id = curId) and article_id <> curId 

So we got a list of "similar" articles.

  • Thank. As for the tags, I somehow did not think. Now it's clear ... I'll rummage in popular cms, maybe I'll find a good one there) - Dobby007
  • Can I ask you for advice? It is probably better to make the tag field (in the tags table) as primary, no? Well, that the same tags are not written in this table ... - Dobby007
  • No, primary is id and the tag field is better to make unique - Alex Kapustin
  • Here's a pancake))) Forgot about the existence of Unique at all)) Thank you, namesake)) - Dobby007