SQL Server ContainsTable not returning result with term “inn”

假如想象 提交于 2020-01-02 05:32:07

问题


I have a table called hotel with the following information:

  • Hotel_Id: 2950
  • Hotel_Name: Inn on the Park
  • Hotel_Number: 01234567
  • Hotel_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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!