简体   繁体   English

如何为SQL Server 2008构建全文搜索谓词

[英]How to construct a full-text search predicate for SQL Server 2008

I want to search a full-text column for the following two terms: 我想搜索以下两个术语的全文列:

2011
J Vineyards

where I construct the predicate as 我在哪里构造谓词

"2011*" and "j vineyards*"

no rows are returned. 没有返回任何行。

A record which should match is 应该匹配的记录是

2011 j vineyards viognier alexander valley united states

After experimentation, it seems to be related to the single "j" character. 经过实验,它似乎与单个“j”字符有关。

EDIT: 编辑:

Here is the select statement for the full-text column BeverageSearchData. 以下是全文列BeverageSearchData的select语句。

Declare @test nvarchar(100);
Set @test='""2011*" and "j vineyards*"';
Select * from bv_beverage WHERE CONTAINS (BeverageSearchData,@test)

There are a couple of possibilities going on here. 这里有几种可能性。 The full query and not just the predicate would help you get a better answer. 完整查询而不仅仅是谓词可以帮助您获得更好的答案。

One thing that is probably going on is that SQL Full-text search eliminates single characters (As in J) when building its index. 可能会发生的一件事是,SQL全文搜索在构建索引时会消除单个字符(如J中所示)。

If using CONTAINS , you may need to change your noise file and restart the SQL Server FullText Search service. 如果使用CONTAINS ,您可能需要更改噪声文件并重新启动SQL Server FullText Search服务。

If using LIKE , you may be able try adding an additional single character wildcard. 如果使用LIKE ,您可以尝试添加额外的单个字符通配符。 Play with it and see if it works without the 2011 and then add it back in. 玩它,看看它是否有效,没有2011年,然后重新加入。

WHERE myColumn like 'j_vineyards%'
WHERE myColumn like 'j%vineyards%'

An additional thing to note is that CONTAINS does not supports leading wildcards. 另外需要注意的是CONTAINS不支持前导通配符。

You're looking for % , not * . 你在寻找% ,而不是*

Try this instead: 试试这个:

"%2011%" and "%j vineyards%"

What language did you choose when creating the index? 您在创建索引时选择了哪种语言? SQL Server associates the system full-text stoplist by default when creating an index which is probably what is happening in your case. 默认情况下,SQL Server在创建索引时会关联系统全文停止列表,这可能是您的情况。

Try building the index with STOPLIST OFF like so - 尝试使用STOPLIST OFF构建索引,如下所示 -

CREATE FULLTEXT INDEX on [table]([column]) ON [catalog] WITH STOPLIST OFF;

Alternatively, you can modify the stoplists to exclude certain words such as 'j' in the example shown above. 或者,您可以修改停止列表以排除上面示例中的某些单词,例如“j”。

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

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