简体   繁体   English

如何使用模糊查找在SQL中查找句子?

[英]how to use Fuzzy look up to find the sentence in SQL?

search term=['ISBN number on site'] the variable(column): sentence, in MySQL table. search term = ['站点上的ISBN号'] MySQL表中的变量(列):句子。 It consist many different sentence. 它由许多不同的句子组成。

the sentence I want to look for is "The AutoLink feature comes with Google's latest toolbar and provides links in a webpage to Amazon.com if it finds a book's ISBN number on the site." 我要查找的句子是“ Google的最新工具栏附带了自动链接功能,如果在网站上找到书的ISBN号,它会在网页上提供指向Amazon.com的链接。”

However, When I use the following statement: 但是,当我使用以下语句时:

SELECT * FROM testtable
where Sentence like "%ISBN number on site%" ;

I am not able to get the result. 我无法得到结果。 This is because the search term("ISBN number on site") is lack of one word("the") compare with the sentence. 这是因为搜索词(“站点上的ISBN号”)与句子相比缺少一个单词(“ the”)。

How to change my statement in order to get the sentence I want? 如何更改我的陈述以获得我想要的句子? thanks. 谢谢。 Assume that We do not change the search term=['ISBN number on site'] 假设我们不更改搜索词= ['站点上的ISBN号']

This is not a simple question. 这不是一个简单的问题。 Your best bet is to use some type of fulltext search . 最好的选择是使用某种全文搜索 Fulltext search can be configured to have stopwords (words that are omitted from search - like the word the ) and can have a minimum word length limit as well (words with less than certain characters long are also omitted from the search. 全文搜索可经配置以具有停止词(即从搜索词语省略-之类的词the ),并且可以具有最小字长度限制以及(字具有少于某些字符长也从搜索删去。

However, if you simply use 但是,如果您只是使用

SELECT * FROM testtable
WHERE MATCH (sentence)
AGAINST ('ISBN number on site');

Then MySQL will return not just the record with the value you were looking for, but the records that have some of the words only, and in different order. 然后,MySQL将不仅返回具有您要查找的值的记录,而且还返回仅包含某些单词并且以不同顺序排列的记录。 The one you showed will probably be one of the highest ranking one, but there is no guarantee that it will be highest ranked one. 您显示的那张可能是排名最高的那张之一,但不能保证它会是排名最高的那张。

You may want to use Boolean fulltext search and prepend + to every search word to force MySQL to return those records only that have all the search words present: 您可能想使用布尔全文搜索,并在每个搜索词前加上+ ,以强制MySQL仅返回所有存在搜索词的记录:

SELECT * FROM testtable
WHERE MATCH (sentence)
AGAINST ('+ISBN +number +on +site' IN BOOLEAN MODE);

But, on should either be a stopword (it is on the default stipword lists) or should be shorter that the minimum word length, so should be omitted from the search expression (you will not get back any results): 但是, on要么应该是一个停用词(它在默认的提示词列表中),要么应该比最小单词长度短,所以应从搜索表达式中将其省略(您将不会获得任何结果):

SELECT * FROM testtable
WHERE MATCH (sentence)
AGAINST ('+ISBN +number +site' IN BOOLEAN MODE);

I know that this requires alteration of the search expression, however this will get you the best results using MySQL's built-in functionality. 我知道这需要更改搜索表达式,但是使用MySQL的内置功能可以使您获得最佳结果。

The alternative is to use other fulltext search engines, such as sphinx to perform the search for you. 替代方法是使用其他全文搜索引擎(例如狮身人面像)为您执行搜索。

Try: 尝试:

SELECT * FROM testtable where Sentence like '%ISBN number on%site%' ;

The wildcard can go in the middle of a string too. 通配符也可以放在字符串中间。

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

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