bricelam / bricelam.github.io

Highlighting some of my more technical adventures
bricelam.net
3 stars 2 forks source link

SQL Server Full-Text Search and EF Core #32

Closed utterances-bot closed 1 year ago

utterances-bot commented 3 years ago

SQL Server Full-Text Search and EF Core | Brice’s Blog

Full-Text Search is a feature of Microsoft SQL Server that lets you perform search engine like queries against the string properties of your entities.

https://www.bricelam.net/2020/08/08/mssql-freetext-and-efcore.html

SoftCircuits commented 3 years ago

Too bad they don't have support for CONTAINSTABLE, as that has always been my preferred approach to full-text search.

bricelam commented 3 years ago

@SoftCircuits You might be able to use it via FromSql. First-class support is tracked by https://github.com/dotnet/efcore/issues/11487.

mahesh-anjani commented 3 years ago

How to do full-text search on byte[] (varbinary(max) in SQL)? Can you please share sample or link with sample?

bricelam commented 3 years ago

@mahesh-anjani Tracked by https://github.com/dotnet/efcore/issues/11482. You might be able to work around it by defining your own function mapping.

mahesh-anjani commented 3 years ago

Thank you for reply @bricelam. It seems like "FromExpression" is specific to EF Core 5.x. Is there any alternative for "FromExpression" in EF Core 3.1.15?

public IQueryable PostsWithPopularComments(int likeThreshold) => FromExpression(() => PostsWithPopularComments(likeThreshold));

bricelam commented 3 years ago

I don't think we supported TVFs in 3.1. @pmiddleton might remember.

pmiddleton commented 3 years ago

TVFs were not added until 5.0.

jrpharis commented 3 years ago

We are using .NET Core 3.1, is it possible to do fuzzy matching via EF.Functions.Contains? I looked at the Full-Text Search documentation and it says that CONTAINS can do fuzzy/less-precise searching and even return weighted results. But looking at the EF.Functions.Contains method, it doesn't appear to have a way to specify the preciseness of a match.

steinbachio commented 2 years ago

Is there any way that entities.Where(x => x.Name.Contains("test")) Will result in SELECT * FROM Entities WHERE CONTAINS(Name, 'test') instead of SELECT * FROM Entities WHERE Name LIKE '%test%'? Of course it should only do that on Properties that are full-text indexed.