简体   繁体   English

MySQL全文搜索-搜索短词

[英]MySQL Full-text search - search for short words

I have a problem. 我有个问题。 I made a simple search engine which searches by brand and model of car. 我做了一个简单的搜索引擎,可以按汽车的品牌和型号进行搜索。 For reasons of query performance and a lot of data in database, I decided to use full-text search. 由于查询性能和数据库中数据很多的原因,我决定使用全文搜索。 It's ok, but now I come across the problem: 可以,但是现在我遇到了问题:

I would like to find all cars with brand "Audi" and with model "Q7". 我想找到所有品牌“ Audi”和型号“ Q7”的汽车。 For now, I have this SQL query, but it doesn't work right, because of word length "Q7": 现在,我有这个SQL查询,但是由于字长“ Q7”,它无法正常工作:

SELECT `a`.`id`, `a`.`title`, `a`.`askprice`, `a`.`description`, `a`.`picture`
FROM (`mm_ads` as a)
WHERE `a`.`category` =  '227'
AND `a`.`askprice` >= '0'
AND `a`.`askprice` <= '144000'
AND (MATCH(a.title) AGAINST ('+audi +q7' IN BOOLEAN MODE ))
GROUP BY `a`.`id`
ORDER BY `a`.`id` ASC
LIMIT 30

I don't have access to modify MySQL config file, to set ft_min_word_len to value 2. For now value is 3. Is there any other way to deal with that? 我无权修改MySQL配置文件,无法将ft_min_word_len设置为值2。现在,值是3。还有其他方法可以解决吗?


Here is another problem: 这是另一个问题:

I would like to get all cars brand "BMW" and model "116". 我想获得所有品牌的宝马汽车和型号116的汽车。 For example, I have a car named BMW, 1, 116i . 例如,我有一辆名为BMW, 1, 116i的汽车。 My SQL query is: 我的SQL查询是:

`SELECT `a`.`id`, `a`.`title`, `a`.`askprice`, `a`.`description`, `a`.`picture`
FROM (`mm_ads` as a)
WHERE `a`.`category` =  '227'
AND `a`.`askprice` >= '0'
AND `a`.`askprice` <= '144000'
AND (MATCH(a.title) AGAINST ('+bmw +116' IN BOOLEAN MODE))
GROUP BY `a`.`id`
ORDER BY `a`.`id` ASC
LIMIT 30`

Search return 0 rows. 搜索返回0行。 Why? 为什么? All input strings ("BMW", "116") are min length 3. What am I doing wrong? 所有输入字符串(“ BMW”,“ 116”)的最小长度为3。我在做什么错?

Regards, Mario 问候,马里奥

I had a similar issue when dealing with match against (regarding text length) and my answer was to strlen the string first and switch between like and match against for shorter words. 在处理与匹配时(关于文本长度),我遇到了类似的问题,我的答案是先将字符串加长,然后在喜欢和匹配之间切换以缩短单词。 Not what I would call graceful, but it was all I could do since I too had no access to the config. 不是我所说的优雅,但这是我所能做的,因为我也无法访问该配置。

As for the second question, are you sure the default isn't 4? 至于第二个问题,您确定默认值不是4吗? I recall I couldn't search on the term "art" in my case. 我记得我无法搜索“艺术”一词。 3 letters. 3个字母。 Had to go with like on everything below 4 chars. 必须与4个字符以下的所有内容一起使用。

Unless you have access to the config file and can change it I fear there is very little to do. 除非您有权访问配置文件并可以更改它,否则我几乎无事可做。

A change to ft_min_word_len requires a server restart and a full rebuild of the full text index. 更改ft_min_word_len要求重新启动服务器并完全重建全文本索引。

As found here 如在这里找到

Try this: 尝试这个:

for this search: "bmw 116i" 搜索结果:“ bmw 116i”

(MATCH(a.title) AGAINST ('+bmw +116i "bmw 116i"' IN BOOLEAN MODE )) (反对(MATCH(a.title)('+ bmw + 116i“ bmw 116i”'在布尔模式下))

not the best solution but might help... 不是最好的解决方案,但可能会有所帮助...

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

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