简体   繁体   English

如何使用SQL进行松散搜索

[英]how to search loosely with SQL

So i am trying to implement a search function using PHP and MySQL, i came across the LIKE SQL Operator, which works fine for basic string matching, but its looking for the exact match. 因此,我尝试使用PHP和MySQL实现搜索功能,我遇到了LIKE SQL Operator,该操作符对于基本的字符串匹配工作正常,但它在寻找完全匹配的对象。 i wondering how to be able to search loosely with MySQL. 我想知道如何能够使用MySQL进行松散搜索。

Right now if you search with my search function, for "blue jacket" , then it will not match it with "a very nice blue colored item | jacket" . 现在,如果使用我的搜索功能搜索“蓝色外套” ,那么它将与“一件非常漂亮的蓝色外套|外套”不匹配。 i want to be able to match that, any suggestions ? 我希望能够与之匹配,有什么建议吗?

My current MySQLi code for search, looks like this: 我当前用于搜索的MySQLi代码如下所示:

$stmt = $conn->prepare("SELECT * FROM `items` where title LIKE CONCAT('%', ?, '%')");

after @Gordon Linoff and @Sammitch suggested the full text search, i went into phpmyadmin and marked title colum as full text, and then modified the SQL query to : 在@Gordon Linoff和@Sammitch建议全文搜索之后,我进入phpmyadmin并将title colum标记为全文,然后将SQL查询修改为:

$stmt = $conn->prepare("SELECT * FROM `items` WHERE MATCH(title) AGAINST ( ? IN NATURAL LANGUAGE MODE)");

For more info: dev.mysql.com/doc/refman/5.7/en/fulltext-search.html 有关更多信息:dev.mysql.com/doc/refman/5.7/en/fulltext-search.html

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

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