strider
strider

Reputation: 2227

Sql Server Full-Text Search with wild card suffix using Entity Framework 6 Interceptor

http://www.entityframework.info/Home/FullTextSearch

This example works fine for full word searches but does not talk about how to implement wild card suffix.

For example, I can do the following in SQL and get results for "bill" or "billy" using '*' in the end. How do I add that to my Interceptor?

select * from dbo.messagethread a where contains(Text, '"bil*"')

If you look at that example code in that link above, I was thinking if something like this (below) is possible, but obviously that does not work as it is getting added to the parameter name not the value.

string.Format(@"contains([$1].[$2], @{0} *)", parameter.ParameterName));

There are questions like this one which talk about wildcards in full-text in SQL.

Upvotes: 0

Views: 411

Answers (1)

strider
strider

Reputation: 2227

Look for this line in the example link provided in the question.

parameter.Value = value;

Then, to do prefix match, just add this line below that.

value = $"\"{value}*\""; // prefix match

We're basically changing the value of the parameter to have the * in it inside double quotes. Now if you search for "bil", you get results for "bill"/"billy" and so on.

Upvotes: 1

Related Questions