简体   繁体   English

PHP MYSQL FULLTEXT如何进行精确搜索?

[英]PHP MYSQL FULLTEXT how to make a Precise search?

I make a PHP MYSQL FULLTEXT search, but how to make a Precise search? 我做了一个PHP MYSQL FULLTEXT搜索,但是如何进行精确搜索? As I use some following code, I need return the data which must contain word 'new' and 'york', em... in fact the code will return some data only contain 'new' but never has 'york'. 当我使用以下代码时,我需要返回必须包含单词'new'和'york'的数据,em ...实际上代码将返回一些仅包含'new'但从未有'york'的数据。 So how? 又怎样?

SELECT * FROM text WHERE MATCH (title,body) AGAINST('new+york' IN BOOLEAN MODE)

You've stumbled upon an edge case -- the problem isn't what you think it is. 你偶然发现了一个边缘案例 - 问题不是你想象的那样。

MySQL fulltext indexing by default will not index words under four characters in length, like "new" . 默认情况下,MySQL全文索引不会将长度超过四个字符的单词编入索引,例如"new" If you want to search for "new" , then you'll need to adjust the minimum word length and rebuild your indexes. 如果要搜索"new" ,则需要调整最小字长并重建索引。

Although Charles is correct regarding the length of the word 'new', there is another issue here - even reindexing with a shorter minimum word length (not entirely advisable), you will get content that contains the word 'new' and 'york' and many words in between them, but not necessarily just the string 'new york'. 虽然查尔斯关于“新”这个词的长度是正确的,但这里还有另一个问题 - 即使用较短的最小词长重新索引(不完全可取),你会得到包含“新”和“约克”这个词的内容。他们之间有很多单词,但不一定只是字符串'new york'。

Also, there's a good chance that the word 'new' is in more then 50% of your records, so no records will return for that. 此外,“新”这个词很可能超过你记录的50%,所以没有任何记录可以返回。

I came up with a way of incorporating exact string matching with fulltext indexes a couple of years ago - though I never got around to including boolean mode searches as well. 几年前,我提出了一种将精确字符串匹配与全文索引相结合的方法 - 尽管我从来没有考虑过包含布尔模式搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM