- Get link
- X
- Other Apps
I've been working on a project where I needed to implement full time search on one table. My current solution was based on SQL Server db and Entity Framework 6. I had two choices implement the full text search in C# or use the functionality available in SQL server, since the data was stored in SQL Server the obvious solution was to use the built in full text search.
How this works:
1. You need to activate and configure the full text search: Activate on the sql server table by using SSMS, and specify which columns are going to be included.
2. To perform a full text search in a T-SQL query you have the choice between 2 Boolean functions: Contains and Freetext or two functions that returns 2 columns tables. In my case I need a function that could be used in a where clause (Boolean), and decided to use 'Contains'. For more details about the difference between Freetext and contains have a look at this article.
3. I need to instruct EF6 to generate a particular T-SQL statement when I want to make a full text search on a particular column. Luckily there is a way to perform this in EF6, by using a custom interceptor (A class that implements:IDbCommandInterceptor). You can find below a link that describes one implementation, in my case I just made a small alteration to the code in the RewriteFullQuery function, where I change the value of the parameter to split a sentence into multiple word: "news paper" ==> '"news" AND "paper"'
How this works:
1. You need to activate and configure the full text search: Activate on the sql server table by using SSMS, and specify which columns are going to be included.
2. To perform a full text search in a T-SQL query you have the choice between 2 Boolean functions: Contains and Freetext or two functions that returns 2 columns tables. In my case I need a function that could be used in a where clause (Boolean), and decided to use 'Contains'. For more details about the difference between Freetext and contains have a look at this article.
3. I need to instruct EF6 to generate a particular T-SQL statement when I want to make a full text search on a particular column. Luckily there is a way to perform this in EF6, by using a custom interceptor (A class that implements:IDbCommandInterceptor). You can find below a link that describes one implementation, in my case I just made a small alteration to the code in the RewriteFullQuery function, where I change the value of the parameter to split a sentence into multiple word: "news paper" ==> '"news" AND "paper"'
Comments
Post a Comment