Saturday, February 25, 2012

CONTAINS, phrases and keywords

I'm getting some results from a CONTAINS query that I find odd. Here
is MyTable:
ID TheText
1 two AND three
2 two three
and here is the query that I find odd:
SELECT * FROM MyTable WHERE CONTAINS(*, '"two OR three"')
that's a single quote followed by a double quote and then the reverse
at the end:
It returns row 1 but not row 2 in the results.
The only way I can explain why row 1 is being returned is if SQL is
throwing out both the AND in the data and the OR in the query. But if
that is the case why isn't row 2 being returned?
Anybody have any idea what's going on?
Hello ddaiker,
OR is an ignored word, what happens is that the ignored word gets replaced
by a token
so your search becomes "two ? three", similarly for the document and is an
ignored word, your search will only find a record where two and three appear
and are seperated by 1 ignored word.
Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons

> I'm getting some results from a CONTAINS query that I find odd. Here
> is MyTable:
> ID TheText
> --
> 1 two AND three
> 2 two three
> and here is the query that I find odd:
> SELECT * FROM MyTable WHERE CONTAINS(*, '"two OR three"')
> that's a single quote followed by a double quote and then the reverse
> at the end:
> It returns row 1 but not row 2 in the results.
> The only way I can explain why row 1 is being returned is if SQL is
> throwing out both the AND in the data and the OR in the query. But if
> that is the case why isn't row 2 being returned?
> Anybody have any idea what's going on?
>

No comments:

Post a Comment