SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


FullText Index using type column


FullText Index using type column

Author
Message
Mike01
Mike01
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5144 Visits: 1563
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/
Steve Jones
Steve Jones
SSC Guru
SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)

Group: Administrators
Points: 352696 Visits: 20207
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.


Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Mike01
Mike01
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5144 Visits: 1563
Steve Jones - SSC Editor - Thursday, February 8, 2018 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.

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/
Steve Jones
Steve Jones
SSC Guru
SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)SSC Guru (352K reputation)

Group: Administrators
Points: 352696 Visits: 20207
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.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search