在sql server中全文搜索

时间:2022-09-13 07:56:58

I am using SQL Server 2008. I have indexed the ProductName column in the Product table as full text search index. Some ProductName values as examples:

我正在使用SQL Server 2008.我已将Product表中的ProductName列编入索引作为全文搜索索引。一些ProductName值作为示例:

ProductName
-------------
Iphone 3GS
Iphone 4S
Iphone 5S
Iphone 5

Now I am using the following code to search for Product:

现在我使用以下代码搜索产品:

WHERE CONTAINS (Product.ProductName, '"Iphone 4S"')

It's OK! But if I edit and use this:

没关系!但是如果我编辑并使用它:

WHERE CONTAINS (Product.ProductName, '"4S Iphone"')

No results!

没有结果!

Could you help me to solve this problem? Thanks.

你能帮我解决这个问题吗?谢谢。

5 个解决方案

#1


5  

you want find out results which contain Iphone,4S.So you can use OR condition to get the result.

你想找到包含Iphone,4S的结果。所以你可以使用OR条件得到结果。

WHERE CONTAINS (Product.ProductName, '4S  OR Iphone')

Following link will be more useful for better understanding. http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/

以下链接将更有助于更好地理解。 http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/

#2


2  

Sounds like you'll want to use the NEAR operator between 4S and Iphone. It searches for words with those, and the order can be independent.

听起来你想要在4S和Iphone之间使用NEAR算子。它搜索带有那些的单词,顺序可以是独立的。

WHERE CONTAINS (Product.ProductName, '"4S" NEAR "Iphone"')

You can also use a tilde(~) in place of the NEAR statement

您也可以使用波浪号(〜)代替NEAR语句

WHERE CONTAINS (Product.ProductName, '"4S" ~ "Iphone"')

#3


1  

Individual search-phrases should be encased in quotations.

个别搜索短语应该用引号括起来。

If you were to compare the results of there 2 lines you would probably find the results you desire:

如果您要比较那两行的结果,您可能会找到您想要的结果:

WHERE CONTAINS (Product.ProductName, '"Iphone" and "4S"')

WHERE CONTAINS (Product.ProductName, '"4S" and "Iphone"')

This is because you might want to search on combinations which involve spaces:

这是因为您可能想要搜索涉及空格的组合:

WHERE CONTAINS (Product.ProductName, '"Sweet apple" or "Sour orange" or "Sour apple"')

In this case you would not be able to find a sweet orange for example.

在这种情况下,你将无法找到甜橙。

The point is to not limit your search to individual words but actually allow you to require different combinations of words if you so choose.

关键是不要将搜索限制为单个单词,但实际上允许您根据需要选择不同的单词组合。

#4


0  

Bit late to the party, nevertheless, wondering if

尽管如此,对党来说还是迟到了

FreeText

FreeText的

will address the issue of the OP, instead of using CONTAINS with AND/OR, as FreeText takes multiple keywords to search.

将解决OP的问题,而不是使用CONTAINS与AND / OR,因为FreeText需要多个关键字进行搜索。

#5


-4  

why dont you go with:

为什么不跟你一起去:

 product.ProductName like '%3GS%'
 product.ProductName like '%4S%'

if you want to be even more accurate then:

如果你想更准确那么:

 where product.ProductName like '%4S%'
       and product.ProductName like '%Iphone%'

#1


5  

you want find out results which contain Iphone,4S.So you can use OR condition to get the result.

你想找到包含Iphone,4S的结果。所以你可以使用OR条件得到结果。

WHERE CONTAINS (Product.ProductName, '4S  OR Iphone')

Following link will be more useful for better understanding. http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/

以下链接将更有助于更好地理解。 http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/

#2


2  

Sounds like you'll want to use the NEAR operator between 4S and Iphone. It searches for words with those, and the order can be independent.

听起来你想要在4S和Iphone之间使用NEAR算子。它搜索带有那些的单词,顺序可以是独立的。

WHERE CONTAINS (Product.ProductName, '"4S" NEAR "Iphone"')

You can also use a tilde(~) in place of the NEAR statement

您也可以使用波浪号(〜)代替NEAR语句

WHERE CONTAINS (Product.ProductName, '"4S" ~ "Iphone"')

#3


1  

Individual search-phrases should be encased in quotations.

个别搜索短语应该用引号括起来。

If you were to compare the results of there 2 lines you would probably find the results you desire:

如果您要比较那两行的结果,您可能会找到您想要的结果:

WHERE CONTAINS (Product.ProductName, '"Iphone" and "4S"')

WHERE CONTAINS (Product.ProductName, '"4S" and "Iphone"')

This is because you might want to search on combinations which involve spaces:

这是因为您可能想要搜索涉及空格的组合:

WHERE CONTAINS (Product.ProductName, '"Sweet apple" or "Sour orange" or "Sour apple"')

In this case you would not be able to find a sweet orange for example.

在这种情况下,你将无法找到甜橙。

The point is to not limit your search to individual words but actually allow you to require different combinations of words if you so choose.

关键是不要将搜索限制为单个单词,但实际上允许您根据需要选择不同的单词组合。

#4


0  

Bit late to the party, nevertheless, wondering if

尽管如此,对党来说还是迟到了

FreeText

FreeText的

will address the issue of the OP, instead of using CONTAINS with AND/OR, as FreeText takes multiple keywords to search.

将解决OP的问题,而不是使用CONTAINS与AND / OR,因为FreeText需要多个关键字进行搜索。

#5


-4  

why dont you go with:

为什么不跟你一起去:

 product.ProductName like '%3GS%'
 product.ProductName like '%4S%'

if you want to be even more accurate then:

如果你想更准确那么:

 where product.ProductName like '%4S%'
       and product.ProductName like '%Iphone%'