-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use COALESCE in FTS LINQ queries #515
Comments
@rwasef1830, you may interested in this one. |
@CodingGorilla your Where clause is not a boolean condition. It should look like this: .Where(p => EF.Functions.ToTsVector(
"english_nostop",
p.Name + " " + p.AddressLine1 + " " // ... all the fields in the same order as the index
).Matches(EF.Functions.PlainToTsQuery("Your search query"))
) This should generate the SQL you expect and utilize the index you created. |
So I tried this code:
Which generated this SQL (based on the console output):
(The additional This query returns 0 results, however the following query (based on my original):
returns 11 rows, which is what I expect. I would note that the grouping in the generated query seems a tad odd, although I'm not sure that has any effect, but also it is definitely missing any |
@CodingGorilla You can achieve coalesce effect in LINQ by using C# null coalesce operator, also make sure you use 'english_nostop' config also in your ToTsQuery call.
|
That did the trick! Thanks for the reminder about the 'english_nostop' in the |
FYI I opened dotnet/efcore#12673 to track the possibility of performing the null coalescing inside EF Core rather than requiring users to do it explicitly - this is a case where the C# behavior differs from the SQL behavior. |
I have a full text index as follows:
I'm trying to use the new FTS LINQ support to do these FTS queries, but I'm not entirely sure how to build the
Where()
clause. If I simply do something like:Wouldn't it stop considering the other fields after the first null field (which is most likely to be
p.AddressLine2
?The text was updated successfully, but these errors were encountered: