January 30, 2018 at 10:10 am
I'm creating a full text index using a type column and have run into an issue with varchar vs nvarchar. We want to use the filter to eliminate HTML tags, so below is what we're trying to implement. The data is currently in an nvarchar column. When I convert it to varbinary and run an FTI query, nothing shows, but if I convert to varchar first then to varbinary, it shows up in the query. I don't want to convert to varchar first, so wondering if anyone has run into this. The query below should return 2 rows but it only returns 1. Thanks in advance for any help. We're user SQL 2016 RTM
CREATE TABLE Posts
(
[Id] INT NOT NULL,
[Title] VARBINARY(MAX) NOT NULL,
[Content] VARBINARY(MAX) NOT NULL,
CONSTRAINT Pk_Posts PRIMARY KEY (Id)
)
go
ALTER TABLE Posts
Add FileExtension As '.html'
go
INSERT INTO Posts (ID, Title, Content)
VALUES (1, CONVERT(VARBINARY(MAX), 'Some title'), CONVERT(VARBINARY(MAX), '<p><strong>f</strong>oo</p>')),
(2, CONVERT(VARBINARY(MAX), N'Some title nvarchar'), CONVERT(VARBINARY(MAX), N'<p><strong>f</strong>oo nvarchar</p>'))
go
CREATE FULLTEXT CATALOG [posts_catalog]
go
CREATE FULLTEXT INDEX ON Posts
(
[Title] TYPE COLUMN FileExtension, [Content] TYPE COLUMN FileExtension
)
KEY INDEX Pk_Posts ON posts_catalog
go
SELECT
Id,
CONVERT(VARCHAR(MAX), [Title]) AS [Title],
CONVERT(VARCHAR(MAX), [Content]) AS [Content]
FROM Posts
where Contains(Content, 'foo')
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
February 8, 2018 at 12:09 pm
This seems to work:UPDATE Posts
SET content = 0xFFFE + content
Then:SELECT
Id,
CONVERT(nVARCHAR(MAX), [Title]) AS [Title],
CONVERT(nVARCHAR(MAX), [Content]) AS [Content]
FROM Posts
where Contains(Content, 'foo')
Apparently a byte marker is needed to clean this up.
February 8, 2018 at 3:28 pm
Steve Jones - SSC Editor - Thursday, February 8, 2018 12:09 PMThis seems to work:UPDATE Posts
SET content = 0xFFFE + contentThen:
SELECT
Id,
CONVERT(nVARCHAR(MAX), [Title]) AS [Title],
CONVERT(nVARCHAR(MAX), [Content]) AS [Content]
FROM Posts
where Contains(Content, 'foo')Apparently a byte marker is needed to clean this up.
Steve, thanks but that doesn't work. It should actually return both rows
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
February 8, 2018 at 7:55 pm
You have to be consistent. You can't mix nvarchar and varchar values in the column and have them work. I'm going to have to convert all data to nvarchar or varchar for this to work.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply