5

I am using full-text search in SQL Server 2008. The following query

select * From MyTable where contains( *, 'FLOW AND VALVE')

returns two rows:

1. FLOW CONTROL VALVE
2. FLOW VALVE

but the following query

select * From MyTable where contains( *, '"FLOW AND VALVE"'))

returns only one row:

1. FLOW CONTROL VALVE

Why doesn't the second query return the second row?

1 Answer 1

5

If you are on SQL Server 2008 you can get some clues from running

SELECT * 
FROM sys.dm_fts_parser('FLOW AND VALVE',1033,0,0)

SELECT * 
FROM sys.dm_fts_parser('"FLOW AND VALVE"',1033,0,0)

CONTAINS( *, 'FLOW AND VALVE') is interpreted as two <simple_term> searches joined together with a boolean condition. i.e. CONTAINS( *, 'FLOW') AND CONTAINS( *, 'VALVE')

CONTAINS( *, '"FLOW AND VALVE"')) is interpreted as a phrase search with the "And" ignored as a noise word.

As to why the second one matches "FLOW CONTROL VALVE" but not "FLOW VALVE" From this article

Although it ignores the inclusion of stopwords, the full-text index does take into account their position.

so essentially the presence of the stop word acts as a wildcard word match.

2
  • It does seem that noise words are matching any "single" word. e.g. The second query matches this: "FLOW CONTROL VALVE" But does not match these: "FLOW VALVE" "FLOW METER ADJUSTING VALVE" "VALVE FLOW" I cannot find anything in the docs that explain this though.
    – unubar
    Dec 25, 2011 at 12:56
  • 1
    @unubar - The phrase search has "Flow" position 1, "And" position 2, "Valve" position 3. As "And" is ignored presumably it just looks for instances of "Flow" in the index which have "Valve" 2 positions later. Dec 25, 2011 at 12:59

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.