MS SQL SERVER 2012
I have a full text index configured on a database which for the main part seems to be functioning correctly. I have a keyword field that contains the following text:
Veterinary Products Beaphar Fiprotec Spot On Small Dog 67mg x 1 235_ldzr_2 Beaphar 87112311437_ldzr_2
When trying to select the row I am getting unexpected results
select * from products where CONTAINS(keywords,'"235*"')
select * from products where CONTAINS(keywords,'"87112311437_ldzr_2*"')
Both return the expected result. This tells me that the index is setup and the underscore character is not an issue. However I get no results for:
select * from products where CONTAINS(keywords,'"235_*"')
select * from products where CONTAINS(keywords,'"235_ldzr_2*"')
I have automatic change tracking switched on, and have disabled it, rebuilt the index manually, re-enabled it, and still no luck. I have even gone to the point of evaluating the string character by character to get the ascii codes in case a special character had made it in via the import. The term does not appear in the stop list. I am now stuck as to why this item does not show.
I have created a copy in a seperate database and have not been able to reproduce the problem, so can't really post code here - as I cannot show the error.
Does anyone have any further checks I can perform or know of any other points that affect the full text search functionality?
@HoneyBadger I have narrowed it down. there seems to be a problem around digits followed by digits with an underscore. Try the following on your table structure.
DELETE FROM TestFullTextSearch
insert into TestFullTextSearch values (1, '235_ldzr_2 testing ')
insert into TestFullTextSearch values (2, 'test 235_ldzr_2 testing ')
insert into TestFullTextSearch values (3, 'A 235_ldzr_2 testing ')
insert into TestFullTextSearch values (4, '1 235_ldzr_2 testing ')
insert into TestFullTextSearch values (5, '12 235_ldzr_2 testing ')
insert into TestFullTextSearch values (6, '123 235_ldzr_2 testing ')
SELECT *
from TestFullTextSearch
where contains(AllText, '"235*"')
SELECT *
from TestFullTextSearch
where contains(AllText, '"235_*"')
Rows 1,2,3 all return as expected. 4,5,6 don't when the underscore is included.
select lcid from sys.syslanguages where langid=@@langid
to get the LCID for your db language 2) runselect * from sys.dm_fts_parser('"235_*"', your-lcid-here, 0, 0);
this will show you how the string is parsed (including the catalogs stop list) – Exile