如何在 SQL Server 中将单词表添加到停用词

问题描述 投票:0回答:1

我有一个单词表,想要添加到 SQL Server 中的停用词。我该怎么办?

我应该一一添加吗?

我尝试:

insert into sys.fulltext_stopwords (stopword) select stopword from Table_1

但出现此错误:

消息 259,第 16 级,状态 1,第 1 行

不允许对系统目录进行临时更新。

我使用 SQL Server 2022。

sql sql-server full-text-search stop-words
1个回答
0
投票

创建非索引字表:

CREATE FULLTEXT STOPLIST CustomStoplist;

将停用词添加到停用词列表中:

DECLARE @stopword NVARCHAR(64);

DECLARE stopword_cursor CURSOR FOR
SELECT stopword FROM Table_1;

OPEN stopword_cursor;

FETCH NEXT FROM stopword_cursor INTO @stopword;

WHILE @@FETCH_STATUS = 0
BEGIN
    EXEC sys.sp_addstopword @stopword = @stopword, @stoplist_name = 'CustomStoplist';
    FETCH NEXT FROM stopword_cursor INTO @stopword;
END

CLOSE stopword_cursor;
DEALLOCATE stopword_cursor;

将非索引字表与全文索引相关联:

CREATE FULLTEXT INDEX ON YourTableName
(
    YourColumnName
)
KEY INDEX YourPrimaryKeyIndex
WITH STOPLIST = CustomStoplist;
© www.soinside.com 2019 - 2024. All rights reserved.