SQL 2005 Bug? Cannot create Full Text Index for varbinary column that's populated from converted nvarchar values

Last post 09-07-2008, 11:54 PM by ezabihi. 3 replies.
Sort Posts: Previous Next
  •  07-11-2007, 4:22 PM Post number 33404

    SQL 2005 Bug? Cannot create Full Text Index for varbinary column that's populated from converted nvarchar values

    Hi, I was wondering if any SQL Server gurus out there could help me...

    I have a table I'm trying to apply a full text catalog to, however no results are ever returned due to the text column being cataloged being of varbinary(max) that's being populated from a converted nvarchar(max) value.

    To re-create the problem quickly...

    If I populate the column via
    CONVERT(varbinary(max), 'test text')
    then there is no problem, I get results as expected.

    However if I populate the column via
    CONVERT(varbinary(max), CAST('test text' as nvarchar(max)))
    no results are ever returned.

    Is this a bug with SQL Server 2005 Full Text Indexing? I'm happily creating full text catalogs when an nvarchar is not getting converted into a varbinary.

    I'm setting the Document Type column to '.html' (I've tried changing this to '.txt' in case it was a fault with the html ifilter but the problem persists so I believe I can rule this out).

    The reason I need to convert an nvarchar to varbinary is that the table holds multi-lingual text and I'm adding a html meta tag <META NAME="MS.LOCALE" CONTENT="ES"> to the beginning in order for the full text indexing word breaker to select the correct language to catalog the text with. The aim being to provide more relevant searches in users native languages (I've read a few articles that describe this technique, but it's the first time I've tried to apply it).

    Any pointers / suggestions would be greatly appreciated. Cheers,
    Gavin.

    Below is a T-SQL script that will quickly re-create the problem I'm experiencing...

    -- Create test database
    CREATE DATABASE FullTextTest
    GO
    USE FullTextTest
    GO

    -- Create test data table
    CREATE TABLE TestTable
    (
    pk UNIQUEIDENTIFIER NOT NULL CONSTRAINT tablePK PRIMARY KEY,
    varbinarycol VARBINARY(MAX),
    documentExtension VARCHAR(5),
    )
    GO

    -- The below single entry WILL BE FOUND (the text source is being entered directly)
    INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX),'<META NAME="MS.LOCALE" CONTENT="EN">test entry 1'), '.html')

    -- The bellow two entries below WILL NOT BE FOUND (the text source is taken from an NVARCHAR(MAX) value)
    INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX), CAST('<META NAME="MS.LOCALE" CONTENT="EN">test entry 2' AS NVARCHAR(MAX))), '.html')
    INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX), CAST('<META NAME="MS.LOCALE" CONTENT="EN">test entry 3' AS NVARCHAR(MAX))), '.html')
    GO

    -- Create the full text catalog
    sp_fulltext_database 'enable'
    GO
    CREATE FULLTEXT CATALOG TEST AS DEFAULT
    GO
    CREATE FULLTEXT INDEX ON TestTable (varbinarycol TYPE COLUMN documentExtension LANGUAGE 1033)
    KEY INDEX tablePK
    GO

    -- NOTE: You might need to give the catalog a chance to build before running the script below.

    -- Now do a search that SHOULD RETURN 3 ROWS of data, but ONLY 1 ROW IS RETURNED
    SELECT CAST(varbinarycol AS NVARCHAR(MAX)) FROM TestTable WHERE CONTAINS(varbinarycol, 'test')

  •  07-15-2007, 3:00 PM Post number 33606 in reply to post number 33404

    Re: SQL 2005 Bug? Cannot create Full Text Index for varbinary column that's populated from converted nvarchar values

    I've also tried adding the following extra meta tag - <META http-equiv="Content-Type" content="text/html; charset=utf-16">

    But this seemed to break the Full Text Index even further. If applied to the example T-SQL I give above then even the non-nvarchar input is no longer returned:

    INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX),'<META http-equiv="Content-Type" content="text/html; charset=utf-16"><META NAME="MS.LOCALE" CONTENT="EN">test entry 1'), '.html')
  •  04-17-2008, 4:46 AM Post number 47699 in reply to post number 33606

    Re: SQL 2005 Bug? Cannot create Full Text Index for varbinary column that's populated from converted nvarchar values

    Hi.. If any body knows that how to query varbinary columns using full text indexing. Thanks.
  •  09-07-2008, 11:54 PM Post number 69439 in reply to post number 33404

    Re: SQL 2005 Bug? Cannot create Full Text Index for varbinary column that's populated from converted nvarchar values

    We had exactly the same problem. The solution is to add 0xFFFE to the beginning of the converted text. I did and it works:

    0xFFFE + CONVERT(varbinary(max), CAST('test text' as nvarchar(max)))

    I found the solution in the following weblog:
    http://milambda.blogspot.com/2006/03/snap-unicode-values-in-varbinarymax.html

    and then I found it in Microsoft website:
    http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124925

    Hope it works for you!
  • View as RSS news feed in XML