对 id 1 进行全文搜索的奇怪 mysql 行为
Strange mysql behaviour with fulltext search on id 1
我有一个 table (INNODB db),其中有数千条记录,一些列是全文索引的。我在布尔模式下使用全文,它工作得很好,除了 id 为 1 的行。它总是告诉我相关性为 0,即使搜索 word/s 存在于索引列内,并且在其他行上经常找到该词.我已经检查了停用词,但这不是问题所在。这就像全文搜索在 id 为 1 的行上是盲目的。
有什么建议吗?
行为示例:
SELECT *, MATCH(full_name, short_name, long_description, summary, model) AGAINST("snom" IN BOOLEAN MODE) as relevance FROM product_sheets
结果:
id
full_name
short_name
model
long_description
summary
relevance
1
Snom phone black 12 lines
Snom phone
D385
Snom phone ..
Snom, phone
0
2
Snom phone blue 12 lines
Snom phone
D385
Snom phone ..
Snom, phone
38.311..
..
..
..
..
..
..
..
全文索引应用于片段中显示的列。
我无法重现您的问题,可能是您使用的版本问题,请尝试更新到可用的最新版本
CREATE TABLE product_sheets
(`id` int, `full_name` varchar(27), `short_name` varchar(12)
, `model` varchar(4), `long_description` varchar(15), `summary` varchar(13)
,FULLTEXT (full_name, short_name, long_description, summary, model))
;
INSERT INTO product_sheets
(`id`, `full_name`, `short_name`, `model`, `long_description`, `summary`)
VALUES
(1, '"Snom phone black 12 lines"', '"Snom phone"', 'D385', '"Snom phone .."', '"Snom, phone"'),
(2, '"Snom phone blue 12 lines"', '"Snom phone"', 'D385', '"Snom phone .."', '"Snom, phone"')
;
SELECT *, MATCH(full_name, short_name, long_description, summary, model) AGAINST("snom" IN BOOLEAN MODE) as relevance FROM product_sheets
id | full_name | short_name | model | long_description | summary | relevance
-: | :-------------------------- | :----------- | :---- | :--------------- | :------------ | -------------------------:
1 | "Snom phone black 12 lines" | "Snom phone" | D385 | "Snom phone .." | "Snom, phone" | 0.000000007543713209656744
2 | "Snom phone blue 12 lines" | "Snom phone" | D385 | "Snom phone .." | "Snom, phone" | 0.000000007543713209656744
db<>fiddle here
(这可能会或可能不会修复索引。请尝试。)
在 OPTIMIZE TABLE
上的 page 中:
After doing substantial insert, update, or delete operations on columns that are part of a FULLTEXT index in an InnoDB table. Set the configuration option innodb_optimize_fulltext_only=1 first. To keep the index maintenance period to a reasonable time, set the innodb_ft_num_word_optimize option to specify how many words to update in the search index, and run a sequence of OPTIMIZE TABLE statements until the search index is fully updated.
(请报告它是否解决了您的问题。)
我有一个 table (INNODB db),其中有数千条记录,一些列是全文索引的。我在布尔模式下使用全文,它工作得很好,除了 id 为 1 的行。它总是告诉我相关性为 0,即使搜索 word/s 存在于索引列内,并且在其他行上经常找到该词.我已经检查了停用词,但这不是问题所在。这就像全文搜索在 id 为 1 的行上是盲目的。 有什么建议吗?
行为示例:
SELECT *, MATCH(full_name, short_name, long_description, summary, model) AGAINST("snom" IN BOOLEAN MODE) as relevance FROM product_sheets
结果:
id | full_name | short_name | model | long_description | summary | relevance |
---|---|---|---|---|---|---|
1 | Snom phone black 12 lines | Snom phone | D385 | Snom phone .. | Snom, phone | 0 |
2 | Snom phone blue 12 lines | Snom phone | D385 | Snom phone .. | Snom, phone | 38.311.. |
.. | .. | .. | .. | .. | .. | .. |
全文索引应用于片段中显示的列。
我无法重现您的问题,可能是您使用的版本问题,请尝试更新到可用的最新版本
CREATE TABLE product_sheets (`id` int, `full_name` varchar(27), `short_name` varchar(12) , `model` varchar(4), `long_description` varchar(15), `summary` varchar(13) ,FULLTEXT (full_name, short_name, long_description, summary, model)) ; INSERT INTO product_sheets (`id`, `full_name`, `short_name`, `model`, `long_description`, `summary`) VALUES (1, '"Snom phone black 12 lines"', '"Snom phone"', 'D385', '"Snom phone .."', '"Snom, phone"'), (2, '"Snom phone blue 12 lines"', '"Snom phone"', 'D385', '"Snom phone .."', '"Snom, phone"') ;
SELECT *, MATCH(full_name, short_name, long_description, summary, model) AGAINST("snom" IN BOOLEAN MODE) as relevance FROM product_sheets
id | full_name | short_name | model | long_description | summary | relevance -: | :-------------------------- | :----------- | :---- | :--------------- | :------------ | -------------------------: 1 | "Snom phone black 12 lines" | "Snom phone" | D385 | "Snom phone .." | "Snom, phone" | 0.000000007543713209656744 2 | "Snom phone blue 12 lines" | "Snom phone" | D385 | "Snom phone .." | "Snom, phone" | 0.000000007543713209656744
db<>fiddle here
(这可能会或可能不会修复索引。请尝试。)
在 OPTIMIZE TABLE
上的 page 中:
After doing substantial insert, update, or delete operations on columns that are part of a FULLTEXT index in an InnoDB table. Set the configuration option innodb_optimize_fulltext_only=1 first. To keep the index maintenance period to a reasonable time, set the innodb_ft_num_word_optimize option to specify how many words to update in the search index, and run a sequence of OPTIMIZE TABLE statements until the search index is fully updated.
(请报告它是否解决了您的问题。)