按最相等的文本排序

Sort by most equal texts

我有一个 table,我需要根据单词出现的最频繁程度对行进行排序,是的。是的越多,就会在最前面加一行,并且限制行数为五行。

------------------------------------------------------------------------
id | logo       |  feature1    |   feature2     |   feature3    | feature4
------------------------------------------------------------------------
1  | img1.png   |   yes    |   yes          |   yes          |   info
------------------------------------------------------------------------
2  | img2.png   |   no     |   no           |   no          |   yes
------------------------------------------------------------------------
3  | img3.png   |   yes    |   info          |   yes         |   info
------------------------------------------------------------------------
4  | img4.png   |   yes    |   yes          |   info        |   yes

ID 为 1 或 4 的第一行 ID 为 1 或 4 的第二行 ID 为 3 的第三行 ID 为 2

的第四行

这样的东西应该能满足您的需求:

select id, logo, feature1, feature2, feature3, feature4
from your_table
order by ((feature1='yes') + (feature2='yes') + (feature3='yes') + (feature4='yes')) desc
limit 5

在所有特征列上放置一个 FULLTEXT 索引并进行简单的布尔搜索

ALTER TABLE t ADD FULLTEXT idx_name (feature1, feature2, feature3,feature4);

 SELECT * FROM T WHERE MATCH (feature1, feature2, feature3,feature4) AGAINST ('word');

关注stop word list and minimum word length.