Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_fulltext_thesaurus_update

  No additional text.


Syntax
CREATE PROCEDURE sys.sp_fulltext_thesaurus_update
          @lcid int
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @phraseid int,
            @parentstateid int,
            @root int,
            @wordStart int,
            @wordLength int,
            @tmpphraseid int,
            @word varbinary(132),
            @wbterms varbinary(1024),
            @phraseLength int,
            @createNewState bit,
            @newStateCreated bit,
            @stateid int,
            @duplicateThesaurusRule bit

    -- delete existing entries from state table for this lcid, but dont delete the root node for this lcid as an optimization, if it exists
    -- (root for an lcid is identified by parentid=0)
    
    DELETE tempdb.sys.fulltext_thesaurus_state_table
    WHERE lcid=@lcid AND parentid != 0

    SELECT @stateid = 2

    -- Add root node if it doesnt exist already and get its stateid
    
    EXEC @root = sys.sp_fulltext_thesaurus_add_root
                @lcid = @lcid

    -- Iterate through all the phrases for this lcid, word break them and create states for each term in the state table
    
    DECLARE phrase_cursor CURSOR LOCAL
        FOR SELECT phraseid, terms
            FROM tempdb.sys.fulltext_thesaurus_phrase_table
            WHERE lcid = @lcid AND
                  ((isExpansion=1) OR (isLHSOfReplacement = 1))

    OPEN phrase_cursor

    FETCH NEXT FROM phrase_cursor
        INTO @phraseid, @wbterms

    WHILE ( @@FETCH_STATUS = 0 )
    BEGIN
        SELECT @parentstateid = @root, @phraseLength=len(@wbterms), @wordStart=1, @wordLength=0, @tmpphraseid=NULL, @createNewState=0, @duplicateThesaurusRule=0

        IF (@phraseLength != 0)
        BEGIN

            WHILE (@wordStart < @phraseLength)
            BEGIN
                SELECT @wordLength = CONVERT(int, SUBSTRING(@wbterms, @wordStart, 1))
                IF ((@wordLength > 128) OR (@wordLength = 0) OR (@wordStart + @wordLength > @phraseLength))
                BEGIN
                    -- Unable to complete the requested operation because of either a catastrophic media failure or a data structure corruption on the disk.
                    -- ERROR_INTERNAL_DB_CORRUPTION
                   RAISERROR(30049, 16, 1, 0x8007054E)
                END

                SELECT @word=SUBSTRING(@wbterms, @wordStart+1, @wordLength)

                IF (@wordStart + @wordLength = @phraseLength)
                BEGIN
                    SET @tmpphraseid = @phraseid
                END

                EXEC @parentstateid = sys.sp_fulltext_thesaurus_add_term
                            @createNewState = @createNewState,
                            @newstateid = @stateid,
                            @parentid = @parentstateid,
                            @phraseIdOrNull = @tmpphraseid,
                            @term = @word,
                            @lcid = @lcid,
                            @newStateCreated = @newStateCreated output,
                            @duplicateThesaurusRule = @duplicateThesaurusRule output
                IF (@newStateCreated = 1)
                BEGIN
                    SET @stateid = @stateid + 1
                END

                SET @createNewState = @newStateCreated
                SET @wordStart = @wordStart + @wordLength + 1
            END

        END

        -- If we encountered a duplicate thesaurus LHS rule, then we have an ambiguity. In such cases we choose
        -- the first one and ignore the latter ones, instead of failing the thesaurus load.
        -- Print an informational message to the client for each duplicate term encountered
        
        IF (@duplicateThesaurusRule=1)
        BEGIN
            DECLARE @originalTerm nvarchar(512)

            SELECT @wordStart=1
            WHILE (@wordStart < @phraseLength)
            BEGIN
                SELECT @wordLength = CONVERT(int, SUBSTRING(@wbterms, @wordStart, 1))
                SELECT @word=SUBSTRING(@wbterms, @wordStart+1, @wordLength)
                if (@wordStart = 1)
                BEGIN
                    SELECT @originalTerm = fulltext_display_term(@word)
                END
                ELSE
                BEGIN
                    SELECT @originalTerm = @originalTerm + N' ' + fulltext_display_term(@word)
                END

                SELECT @wordStart = @wordStart + @wordLength + 1
            END

            -- duplicate thesaurus phrase informational message
            
            RAISERROR(30048, -1, -1, @originalTerm, @lcid)
        END

        FETCH NEXT FROM phrase_cursor
            INTO @phraseid, @wbterms
    END

    -- This is a local cursor hence if there is an error thrown from above the cursor will be closed
    -- and deallocated implicitly
    
    CLOSE phrase_cursor
    DEALLOCATE phrase_cursor
END

 
Last revision 2008RTM
See also

  sp_fulltext_load_thesaurus_file (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash