I have a table called hotel
with the following information:
Hotel_Id
: 2950Hotel_Name
: Inn on the ParkHotel_Number
: 01234567Hotel_TypeId
: 1
I need to be able to search for records where the name column contains certain terms.
The search is:
select *
from ContainsTable(hotel, Hotel_Name, '"Inn on Park"')
I get no results but if I search:
select *
from ContainsTable(hotel, Hotel_Name, '"In on Park"')
I get
Key: 2950
Rank: 176
I figured there was some issue with the term "inn" but if I search for:
select *
from ContainsTable(hotel, Hotel_Name, '"Inn"')
I get back the same key: 2950, Rank: 176 result.
Is "inn" a keyword that is causing this problem?
This is my theory..
Your hotel name, Inn on the Park
, would be index like this:
pos word
1 Inn
2 (noise)
3 (noise)
4 Park
on and the are stop/noise words, and not stored in the index (but notice that the position is still stored).
You're searching by a full string. Taking in to account the noise words this would mean:
Query 1: "Inn on Park" -> "Inn (noise) Park"
Query 2: "In on Park" -> "(noise) (noise) Park"
Your indexed string (hotel name) is Inn (noise) (noise) Park
, so this would be a partial match on the second query, but no match on the first.
This can be tested by for example searching for Inn 1 1 Park
. This will return a result. But Inn 1 Park
or 1 Inn 1 Park
will not (positions does not correspond).
To "fix" this you could use different operators, like AND, OR or NEAR:
"Inn" AND "Park"
"Inn*"
"Inn" NEAR "Park"
Here are two screenshots, showing the results of your main queries. Notice how the second will only search for "Park", or "noise noise Park" (any of those would return results):
来源:https://stackoverflow.com/questions/30134623/sql-server-containstable-not-returning-result-with-term-inn