立即更新全文搜索索引 - SQL SERVER 2012
Posted
技术标签:
【中文标题】立即更新全文搜索索引 - SQL SERVER 2012【英文标题】:Updating Fulltextsearch index immediately - SQL SERVER 2012 【发布时间】:2016-03-31 09:38:24 【问题描述】:我在 SQL Server 2012 上创建了全文搜索索引。它工作正常,直到我不得不从 Table 中删除包含在 FullTextSearch 中的列。
然后我尝试删除现有的全文索引和目录,然后重新创建它。但不知何故,在重新创建后,它没有显示任何搜索查询结果(之前的结果即将到来)。
我运行了以下查询以了解全文搜索的状态:
declare @id int
select @id = id FROM sys.sysobjects where [Name] = 'TableName'
select 'TableFullTextBackgroundUpdateIndexOn' as 'Property', objectpropertyex(@id, 'TableFullTextBackgroundUpdateIndexOn') as 'Value'
union select 'TableFullTextChangeTrackingOn', objectpropertyex(@id, 'TableFullTextChangeTrackingOn')
union select 'TableFulltextDocsProcessed', objectpropertyex(@id, 'TableFulltextDocsProcessed')
union select 'TableFulltextFailCount', objectpropertyex(@id, 'TableFulltextFailCount')
union select 'TableFulltextItemCount', objectpropertyex(@id, 'TableFulltextItemCount')
union select 'TableFulltextKeyColumn', objectpropertyex(@id, 'TableFulltextKeyColumn')
union select 'TableFulltextPendingChanges', objectpropertyex(@id, 'TableFulltextPendingChanges')
union select 'TableHasActiveFulltextIndex', objectpropertyex(@id, 'TableHasActiveFulltextIndex')
union select 'TableFulltextPopulateStatus', objectpropertyex(@id, 'TableFulltextPopulateStatus')
它返回以下结果:
我运行以下查询以删除和重新创建全文搜索目录和索引:
GO
EXEC sp_fulltext_database 'enable'
GO
DROP FULLTEXT INDEX ON [AT].[TableName]
GO
DROP FULLTEXT CATALOG [table_search_catalog];
GO
CREATE FULLTEXT CATALOG [table_search_catalog] WITH ACCENT_SENSITIVITY = ON;
GO
DECLARE @Const Varchar(150)
DECLARE @Query1 Varchar(MAX)
SELECT @Const=TC.CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC
INNER JOIN
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KU
ON TC.CONSTRAINT_TYPE = 'PRIMARY KEY' AND
TC.CONSTRAINT_NAME = KU.CONSTRAINT_NAME
and ku.table_name='TableName'
ORDER BY KU.TABLE_NAME, KU.ORDINAL_POSITION;
SET @Query1 ='CREATE FULLTEXT INDEX ON [AT].[TableName]
(
UserName
Language 1033,
ResumeTitle
Language 1033,
Address1
Language 1033,
OtherSNSURL
Language 1033,
LinkedInURL
Language 1033,
FacebookURL
Language 1033,
TwitterURL
Language 1033,
SkypeID
Language 1033,
comments
Language 1033,
CurrentCompany
Language 1033,
PreviousCompany
Language 1033
)
KEY INDEX '+@Const +'
ON table_search_catalog
WITH STOPLIST = SYSTEM, CHANGE_TRACKING AUTO'
EXEC (@query1)
GO
Update [AT].[TableName] SET UserName=UserName;
GO
ALTER INDEX ALL ON AT.TableName
REORGANIZE;
GO
ALTER FULLTEXT INDEX ON [AT].[TableName]
SET CHANGE_TRACKING MANUAL;
GO
ALTER FULLTEXT INDEX ON [AT].[TableName]
START FULL POPULATION;
GO
ALTER FULLTEXT INDEX ON [AT].[TableName]
START update POPULATION;
GO
ALTER FULLTEXT INDEX ON [AT].[TableName]
SET CHANGE_TRACKING AUTO;
显然,全文搜索索引包含要处理的记录,但一段时间后它保持不变。
请告诉我处理记录通常需要多长时间? 另外应该怎么做才能立即处理待处理的记录(这个查询会很棒)?
谢谢
【问题讨论】:
【参考方案1】:实际上 20 分钟后,我运行查询以查看更改并发现所有待处理的记录都已处理。但是仍然需要很长时间才能反映这些变化。
谢谢
【讨论】:
以上是关于立即更新全文搜索索引 - SQL SERVER 2012的主要内容,如果未能解决你的问题,请参考以下文章