Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: LIKE and Contains — Different results

Tags:

sql

sql-server

I am using MS SQL Express SQL function Contains to select data. However when I selected data with LIKE operator, I realised that Contains function is missing a few rows.

Rebuilt indexes but it didn't help.

Sql: brs.SearchText like '%aprilis%' and CONTAINS(brs.SearchText, '*aprilis*')

The contains function missed rows like:

22-28.aprīlis
[1.aprīlis]
Sīraprīlis

PS. If I search directly CONTAINS(brs.SearchText, '*22-28.aprīlis*'), then it finds them

like image 541
Brivvirs Avatar asked Feb 13 '23 21:02

Brivvirs


1 Answers

contains is functionality based on the full text index. It supports words, phrases, and prefixed matches on words, but not suffixed matches. So you can match words that start with 'aprilis' but not words that end with it or that contain it arbitrarily in the middle. You might be able to take advantage of a thesaurus for these terms.

This is explained in more detail in the documentation.

like image 149
Gordon Linoff Avatar answered Feb 16 '23 09:02

Gordon Linoff