MySQL全文搜索 - 搜索短字 [英] MySQL Full-text search - search for short words

查看:151
本文介绍了MySQL全文搜索 - 搜索短字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我做了一个简单的搜索引擎,搜索品牌和车型。由于查询性能和数据库中的大量数据的原因,我决定使用全文搜索。没关系,但现在我遇到了这个问题:



我想找到所有的汽车品牌奥迪和型号Q7。现在,我有这个SQL查询,但它不工作正确,因为字长度Q7:

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

我无法访问修改MySQL配置文件,将 ft_min_word_len 设置为值2.现在值为3.是否有其他方法处理?



这是另一个问题:



我想获得所有汽车品牌宝马和模型116 。例如,我有一辆名为 BMW,1,116i 的汽车。我的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`

搜索返回0行。为什么?



注意:Mario


<我有一个类似的问题,当处理匹配(关于文本长度)和我的答案是strlen字符串,并在之间切换和较短的词匹配。不是我所说的优雅,但这是我能做的,因为我也没有访问的配置。



至于第二个问题,你确定默认不是4?我记得我不能在我的案例中搜索艺术一词。 3个字母。必须在4个字符以下。


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". For now, I have this SQL query, but it doesn't work right, because of word length "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?


Here is another problem:

I would like to get all cars brand "BMW" and model "116". For example, I have a car named BMW, 1, 116i. My SQL query is:

`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. Why? All input strings ("BMW", "116") are min length 3. What am I doing wrong?

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? I recall I couldn't search on the term "art" in my case. 3 letters. Had to go with like on everything below 4 chars.

这篇关于MySQL全文搜索 - 搜索短字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆