开发者

SQL Server Fulltext search not finding my rows

开发者 https://www.devze.com 2023-02-25 07:47 出处:网络
I have a SQL Server table and I\'m trying to make sense of fulltext searching :-) I have set up a fulltext catalog and a fulltext index on a table Entry, which contains among other columns a VARCHAR(

I have a SQL Server table and I'm trying to make sense of fulltext searching :-)

I have set up a fulltext catalog and a fulltext index on a table Entry, which contains among other columns a VARCHAR(20) column called VPN-ID.

There are about 200'000 rows in that table, and the VPN-ID column has values such as:

VPN-000-359-90
VPN-000-363-85
VPN-000-362-07
VPN-000-362-91
VPN-000-355-55
VPN-000-368-36
VPN-000-356-90

Now I'm trying to find rows in that table with a fulltext enabled search.

When I do

SELECT (list of columns)
FROM dbo.Entry
WHERE CONTAINS(*, 'VPN-000-362-07')

everything's fine and dandy and my rows are returned.

When I start searching with a wildcard like this:

SELECT (list of columns)
FROM dbo.Entry
WHERE CONTAINS(*, 'VPN-000-362-%')

I am getting results and everything seems fine.

HOWEVER: when I searching like this:

SELECT (list of columns)
FROM dbo.Entry
WHERE CONTAINS(*, 'VPN-000-36%')

suddenly I get no results back at all..... even though there are clearly rows that match that search criteria...

Any ideas why?? What other "surprises" might fulltext search have in store for me? :-)

Update: to create my fulltext catalog I used:

CREATE FULLTEXT CATALOG MyCatalog WITH ACCENT_SENSITIVITY = OFF

and to create the fulltext index on my table, I used

CREATE FULLTEXT INDEX 
ON dbo.Entry(list of columns)
KEY INDEX PK_Entry

I tried to avoid any "oddball" options as much a I could.

Update #2: after a bit more investigation, it appears as if SQL Server Fulltext search somehow interprets my dashes inside the strings as separators....

While this query returns nothing:

SELECT (list of columns)
FROM dbo.Entry
WHERE CONTAINS(*, '"VPN-000-362*"')

this one does (splitting up the search term on the dashes):

SELECT (list of columns)
FROM dbo.Entry
WHERE CONTAINS(*, ' "VPN" AND "000" AND "362*"')

OK - seems a bit odd that a dash appears to r开发者_StackOverflow中文版esult in a splitting up that somehow doesn't work.....


which Language for Word Breaker do you use? Have you tried Neutral?

SQL Server Fulltext search not finding my rows

EDIT:
in adition you should use WHERE CONTAINS([Column], '"text*"'). See MSDN for more information on Prefix Searches:

C. Using CONTAINS with

The following example returns all product names with at least one word starting with the prefix chain in the Name column.

USE AdventureWorks2008R2;
GO
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, ' "Chain*" ');
GO

btw ... similar question here and here


Just wondering, but why don't you just do this:

SELECT (list of columns)
FROM dbo.Entry
WHERE [VPN-ID] LIKE 'VPN-000-36%'

It seems to me that fulltext search is not the right tool for the job. Just use a normal index on that column.

0

精彩评论

暂无评论...
验证码 换一张
取 消