Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GoodController.php #74

Merged
merged 1 commit into from Dec 5, 2020
Merged

Update GoodController.php #74

merged 1 commit into from Dec 5, 2020

Conversation

incasedo
Copy link
Contributor

@incasedo incasedo commented Dec 4, 2020

模糊搜索改为全文搜索

模糊搜索改为全文搜索
@dspurl
Copy link
Owner

dspurl commented Dec 5, 2020

image
image
image
模糊搜索的逻辑是什么样的,我测试下了,感觉结果和想要的完全不一样;如图,第二条应该不符合关键字要求,结果却查出来了,然后我试了下“女”或“鞋”,然后并没有查出结果,按理说应该帮我查询出来标题中包含“女”的所有商品才对

@incasedo
Copy link
Contributor Author

incasedo commented Dec 5, 2020

mysql.conf中需要添加:
ngram_token_size=1

取值范围是1到10,默认值是2。

通常ngram_token_size设置为要查询的单词的最小字数。如果需要搜索单字,就要把ngram_token_size设置为1。在默认值是2的情况下,搜索'女'字是得不到任何结果的。

@incasedo
Copy link
Contributor Author

incasedo commented Dec 5, 2020

可以试试使用BOOLEAN模式执行高级查询。

// 必须包含"腾讯"
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('+腾讯' IN BOOLEAN MODE);

我也是匆匆忙忙赶项目, 没时间详细测试, mysql 5.7这个特性以前没用过, 以前都是自己分词, 然后用全文索引.

@dspurl
Copy link
Owner

dspurl commented Dec 5, 2020

嗯,好的

@dspurl dspurl merged commit 172b637 into dspurl:master Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants