シナリオ
名前 の列に各製品に関するいくつかのキーワードを保存しましTags
た。ユーザーがこの列に存在する単語を検索すると、関連する製品が表示される必要があります。ユーザーは検索クエリにいくつかの一般的な単語 (たとえば、an,or,some) を入力する可能性があるため、現在、一般性に基づいて各単語に重みを割り当てています。
タグ列を使用
する
と全文索引が作成され、Containstable
キーワードの検索に使用しています。
問題
数か月後、テーブル サイズが大幅に増加し、使用時に問題が発生していContainstable
ます。ユーザーが単語を検索すると (関連行のすべてのタグ列でのその単語の出現数が同じ)、結果行のランクは等しくなく、キーワード数が少ない (しきい値から小さい) 各行は、より高いランク。
これは問題ではなく、 https://technet.microsoft.com/en-us/library/ms142524%28v=sql.105%29.aspxに基づいており、ランキング にはとをContainsTable
使用してください。IndexedRowCount
KeyRowCount
タグ列に出現する単語の加重合計に基づいて各行をランク付けする方法はありますか?
更新機能と重量
のようなものが必要です。https://msdn.microsoft.com/en-us/library/ms187787.aspxに
基づいており、. Contains
weighted_term
Contains
以下のない私の新しいコードContainsTable
。このコードは非常に遅いです。
declare @q nvarchar(100)='word1#0.5,word2#0.4'
declare @wordsTable table(word nvarchar(30),weight decimal)
insert into @wordsTable
select substring(items,0,CHARINDEX('#',items)) as word,substring(items,CHARINDEX('#',items)+1,LEN(items)) as weight from split(@q,',')
declare @counter int
select @counter=COUNT(*) from @wordsTable
_____________________________________________
select Tags,SUM(rank) as ranks
from(
select (0.5) as rank, Tags from Product where contains(Tags,@word1)
union
select (0.4) as rank, Tags from Product where contains(Tags,@word2))
group by Tags