简体   繁体   English

MysqL:对多列进行全文搜索,100%匹配

[英]MysqL: Perform fulltext search over multiple columns and 100 % match

I'd like to do a fulltext search over multiple columns in a MySQL database, only using 1 Input field to search for addresses. 我想对MySQL数据库中的多个列进行全文搜索,只使用1个输入字段来搜索地址。

So far my code works but I also get rows returned where not all search words are present. 到目前为止我的代码工作,但我也返回行,而不是所有搜索词都存在。

SELECT *, ((1.3 * (MATCH (city) AGAINST ('+$search*' IN BOOLEAN MODE)))
+ (0.6 * (MATCH (name, zip, str) AGAINST ('+$search*' IN BOOLEAN MODE)))) AS relevance
FROM service
WHERE (MATCH (name, city, zip, str) AGAINST ('+$search*' IN BOOLEAN MODE)) 
HAVING relevance > 0 ORDER BY relevance DESC LIMIT 10

This could return sth like: 这可能会像:

$search = "Anderson City ZIP"

1. Anderson, City, ZIP, street x
2. Anderson, City, ZIP, street y
3. Smith, City, ZIP, street x

So line 3 is wrong because it does not contain Anderson but Smith . 所以第3行是错误的,因为它不包含Anderson而是Smith

I already tried to add the + operator in the $search string ( Anderson City ZIP --> +Anderson +City +ZIP ) but then the result often does not show anything. 我已经尝试在$search字符串中添加+运算符( Anderson City ZIP --> +Anderson +City +ZIP ),但结果通常没有显示任何内容。

Is it possible to return only rows with 100 % match? 是否可以只返回100%匹配的行?

The plus sign is the good thing to do but you have to be sure that one of the strings you are searching for is not in more than 50% of the rows of your table. 加号是好事,但你必须确保你要搜索的其中一个字符串不超过表的50%。

Also consider using quotes to match the full expression: +"Anderson City ZIP" 还可以考虑使用引号来匹配完整的表达式:+“Anderson City ZIP”

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

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