1

我正在尝试确定列中具有全文索引的单词旁边的所有可能单词。

我正在使用 sys.dm_fts_index_keywords 来获取所有可能的关键字,而忽略停止列表中的所有单词。

我试图弄清楚的一个例子:如果我有字符串:“我喜欢我办公室的咖啡馆”,我正在看“咖啡馆”这个词,我想知道它旁边的词是什么。

当我进行下一步搜索时,是否包含停止列表单词并不重要。我只是认为利用已经存在的全文索引会更容易。

4

1 回答 1

2

您可以使用 FT 索引来查找匹配项,但随后您必须解析短语并找到相邻的单词。不幸的是,FTS 没有给你比赛的位置 afaik,否则这可能会更容易。

这是一个示例设置:

declare @find varchar(100) = 'cafe';

declare @phrase varchar(100) = 'I like the cafe at my office';

;with 
x(x)
as (    select cast('<w>'+replace(@phrase, ' ', '</w><w>')+'</w>' as xml)
    ),
words(pos, word)    
as  (   select  dense_rank() over (order by n),
                p.n.value('.', 'varchar(100)')
        from x
        cross
        apply x.nodes('/w')p(n) 
    )
select  d.* 
from    words w
cross
apply   (   select  * 
            from    words 
            where   pos in (w.pos-1, w.pos+1)
        )d(pos, word)
where   w.word=@find
于 2012-06-04T07:44:58.580 回答