Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Full Text Search Leading Wildcard

After taking a look at this SO question and doing my own research, it appears that you cannot have a leading wildcard while using full text search.

So in the most simple example, if I have a Table with 1 column like below:

TABLE1

coin
coinage
undercoin

select COLUMN1 from TABLE1 where COLUMN1 LIKE '%coin%' Would get me the results I want.

How can I get the exact same results with FULL TEXT SEARCH enabled on the column?

The following two queries return the exact same data, which is not exactly what I want.

SELECT COLUMN1 FROM TABLE1 WHERE CONTAINS(COLUMN1, '"coin*"')

SELECT COLUMN1 FROM TABLE1 WHERE CONTAINS(COLUMN1, '"*coin*"')
like image 690
aherrick Avatar asked Apr 18 '10 23:04

aherrick


People also ask

What is leading wildcard in SQL?

SQL WildcardsA wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

Is * a wildcard in SQL?

To broaden the selections of a structured query language (SQL-SELECT) statement, two wildcard characters, the percent sign (%) and the underscore (_), can be used. The percent sign is analogous to the asterisk (*) wildcard character used with MS-DOS.


1 Answers

Full text search works on finding words or stems of words. Thus, it does not find the word "coin" anywhere in "undercoin". What you seek is the ability search suffixes using full text searches and it does not do this natively. There are some hacky workarounds like creating a reverse index and searching on "nioc".

like image 159
Thomas Avatar answered Sep 18 '22 04:09

Thomas