I am running two queries that are supposed to do the same thing on our CV database table:
CONTAINS
(full-text indexed table - cv, fullname etc are all included in the index)SELECT COUNT(1) FROM [CVDatabase] WHERE CONTAINS ((CVText, fullname, city, CompanyName, jobTitle, targetJobTitle),'"cost accountant*"') AND (Country='South Africa')
Number of results: 300
CHARINDEX
(unindexed)SELECT COUNT(1) FROM [CVDatabase] WHERE (CHARINDEX ('cost accountant', cvtext) > 0 OR CHARINDEX ('cost accountant', fullname) > 0 OR CHARINDEX ('cost accountant', city) > 0 OR CHARINDEX ('cost accountant', companyname) > 0 OR CHARINDEX ('cost accountant', jobtitle) > 0 OR CHARINDEX ('cost accountant', targetjobtitle) > 0) AND (Country = 'South Africa')
Number of results: 339
This is over a 10% discrepancy. Naturally CHARINDEX
with capture 'cost accountant', 'cost accountants' (which CONTAINS
will also capture with the wildcard). The difference might come from characters before 'cost accountant' which CHARINDEX
will capture but not CONTAINS
- but I cannot think of any characters that would make sense before the word 'cost'.
Is it possible there is something wrong with the indexing, and it is not picking up all the results? It is set to track automatic changes so it should be indexing correctly.