This is the stored procedure that we created based on GarethOwen's answer. It takes a comma-separated list of tables as parameters and waits until the full text indexes on all of them have been updated. It checks every tenth of a second to prevent disk chopping and downtime after 10 seconds, just in case everything works slowly / broken. Useful if your FT searches relate to multiple indexes.
Called as follows:
EXECUTE [dbo].[WaitForFullTextIndexing] 'MY_TABLE,ALTERNATE_NAMES,TAG_GROUP_VALUES,TAG_GROUPS,FIELD_OPTION';
Source:
CREATE PROCEDURE WaitForFullTextIndexing @TablesStr varchar(max) AS BEGIN DECLARE @Tables AS TABLE( [word] [varchar](8000) NULL) INSERT INTO @Tables (word) SELECT items from dbo.Split(@TablesStr, ','); DECLARE @NumberOfTables int; SELECT @NumberOfTables = COUNT(*) from @Tables; DECLARE @readyCount int; SET @readyCount = 0; DECLARE @waitLoops int; SET @waitLoops = 0; DECLARE @result bit; WHILE @readyCount <> @NumberOfTables AND @waitLoops < 100 BEGIN select @readyCount = COUNT(*) from @Tables tabs where OBJECTPROPERTY(object_id(tabs.word), 'TableFulltextPopulateStatus') = 0; IF @readyCount <> @NumberOfTables BEGIN -- prevent thrashing WAITFOR DELAY '00:00:00.1'; END set @waitLoops = @waitLoops + 1; END END GO
dbo.split is a table value function that everyone should have by now, which splits the row on the delimiter into a temporary table:
CREATE FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1)) returns @temptable TABLE (items varchar(8000)) as begin declare @idx int declare @slice varchar(8000) select @idx = 1 if len(@String)<1 or @String is null return while @idx!= 0 begin set @idx = charindex(@Delimiter,@String) if @idx!=0 set @slice = left(@String,@idx - 1) else set @slice = @String if(len(@slice)>0) insert into @temptable(Items) values(@slice) set @String = right(@String,len(@String) - @idx) if len(@String) = 0 break end return end GO
JohnB Oct 31 '11 at 12:11 2011-10-31 12:11
source share