12

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 result in a splitting up that somehow doesn't work.....

3
  • could you add the code, which created the fulltext-index/catalog? maybe there are some freakin' options ...
    – user57508
    Apr 18, 2011 at 7:16
  • 2
    I think the - is just treated as a word breaking character and not used in the search at all. SELECT * FROM sys.dm_fts_parser('"VPN-000-362*"',1033,NULL,0) Apr 18, 2011 at 10:45
  • Though if you change the language parameter one of the - gets preserved. SELECT * FROM sys.dm_fts_parser('"VPN-000-362*"',0,NULL,0). Strange! Don't know what the rules are here. Apr 18, 2011 at 10:53

2 Answers 2

8

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

enter image description here

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

4
  • See my create scripts above - I didn't specify anything special at all; as far as I see, SQL Server used "English" for all my languages
    – marc_s
    Apr 18, 2011 at 7:33
  • which result do you get, if you change it to Neutral?
    – user57508
    Apr 18, 2011 at 7:37
  • Results stay the same - finds OK with 'VPN-000-362-%', doesn't find a thing with 'VPN-000-36%'
    – marc_s
    Apr 18, 2011 at 7:40
  • I tried WHERE CONTAINS(*, ' "VPN-000-36*" ') but the results are the same - no rows :-( even through they definitely ARE rows that match that critieria! Even if I specify the exact column name in the CONTAINS (which I wanted to avoid), I still get no results....
    – marc_s
    Apr 18, 2011 at 8:07
1

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.

2
  • 1
    I want to be able to search on dozens of fields - I don't like the idea of having to search for field 1, then field 2, then field 3 and so forth. Fulltext search can search in the whole fulltext index at once
    – marc_s
    Apr 18, 2011 at 15:46
  • 3
    and considering performance, a fulltext-index will surpass a like-search
    – user57508
    Apr 21, 2011 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.