Php 搜索类似twitter趋势主题的查询

Php 搜索类似twitter趋势主题的查询,php,mysql,twitter,trending,Php,Mysql,Twitter,Trending,我需要MYSQL搜索查询从我的表中获取趋势主题,下面是我需要的解释 +----+---------+-----------------------------+ | ID | ID_user | text | +----+---------+-----------------------------+ | 1 | bruno | michael jackson is dead | | 2 | thomasi | michael j.

我需要MYSQL搜索查询从我的表中获取趋势主题,下面是我需要的解释

+----+---------+-----------------------------+
| ID | ID_user | text                        | 
+----+---------+-----------------------------+
| 1  | bruno   | michael jackson is dead     |
| 2  | thomasi | michael j. moonwalk is dead |
| 3  | userts  | michael jackson lives       |
+----+---------+-----------------------------+
我想查询表中重复次数最多的单词,限制在前10位,结果可能是:

+-------+------------+
| count | word       |
+-------+------------+
| 3     | michael    |
| 2     | dead       |
| 2     | jackson    |
| 1     | j.         |
| 1     | lives      |
| 1     | moonwalk   |
+-------+------------+
但我只想搜索重复10次以上的单词,在这种情况下,没有一个单词出现,但如果重复单词的条件为2,它将只显示'michael'和'dead',但忽略'is',因为我不想要长度小于2个字符的单词,以及一个短语包含的单词,那么我需要:

+-------+-----------------+
| count | word            |
+-------+-----------------+
| 2     | michael jackson |
| 2     | dead            |
+-------+-----------------+
但这不是很有效,不应该这样做

编辑:

但这不是很有效,不应该这样做

编辑:


这里有一个基本的误解:RDBMS设计用于处理字段内容,而不是字段内容。虽然可以创建这样一个查询,但最有可能的是在数据库中处理这一问题的子解决方案。这涉及到一个基本的误解:RDBMS设计用于处理字段内容,而不是字段内容。虽然可以创建这样一个查询,但最有可能的是在DBgreat help中处理该查询,但无法得到结果。那么您希望得到什么结果?我不明白…和一个短语…我解释它的话。我有一个桌柱。现在有一个状态栏,我需要状态中最常用的词。但是我也应该排除诸如of、this、to等词。有什么对我有帮助吗?很大的帮助,但没有得到结果。那么你想要什么结果?我不明白…和一个短语…我解释它的话。我有一个桌柱。现在有一个状态栏,我需要状态中最常用的词。但我也应该排除诸如of、this、to等词。有什么对我有帮助的吗?
CREATE TEMPORARY TABLE counters (id INT);
-- insert into counters as much as you like (values here means "number of repeats"
INSERT INTO counters VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9),(10),
                           (11),(12),(13),(14),(15),(16),(17),(18),(19),(20),
                           (21),(22),(23),(24),(25),(26),(27),(28),(29),(30);

  SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(texts.text,' ',counters.id),' ',-1) AS word,
         COUNT(counters.id) AS counter
    FROM texts
         INNER JOIN counters ON (LENGTH(text)>0 AND SUBSTRING_INDEX(SUBSTRING_INDEX(text,' ',counters.id),' ',-1) <> SUBSTRING_INDEX(SUBSTRING_INDEX(text,' ',counters.id-1),' ', -1))
   WHERE length(SUBSTRING_INDEX(SUBSTRING_INDEX(texts.text,' ',counters.id),' ',-1)) > 2
GROUP BY word
  HAVING COUNT(counters.id) > 1
ORDER BY counter desc;
  SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(texts.text,' ',counters.id),' ',-1) AS word,
         COUNT(counters.id) AS counter
    FROM texts
         INNER JOIN counters ON (LENGTH(text)>0 AND SUBSTRING_INDEX(SUBSTRING_INDEX(text,' ',counters.id),' ',-1) <> SUBSTRING_INDEX(SUBSTRING_INDEX(text,' ',counters.id-1),' ', -1))
   -- exclude words list
   WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(texts.text,' ',counters.id),' ',-1) NOT IN ('is', 'of', 'this', 'to')
GROUP BY word
  HAVING COUNT(counters.id) > 1
ORDER BY counter desc;