Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Full Text Search (FTS) with LINQ?

I wonder if is possible to use FTS with LINQ using .NET Framework 3.5. I'm searching around the documentation that I didn't find anything useful yet.

Does anyone have any experience on this?

like image 803
Edwin Jarvis Avatar asked Oct 22 '08 04:10

Edwin Jarvis


People also ask

How do you implement full-text search?

To implement a full-text search in a SQL database, you must create a full-text index on each column you want to be indexed. In MySQL, this would be done with the FULLTEXT keyword. Then you will be able to query the database using MATCH and AGAINST.

How do I do a full-text search in SQL?

For a full-text index to be created on a table, the table must have a single, unique nonnull column. You can build a full-text index on columns of type char, varchar, nchar, nvarchar, text, ntext, image, xml, varbinary, and varbinary(max) can be indexed for full-text search.

Is full-text search fast?

A full text search query is much faster. Especially when working which lots of data in various columns. Additionally you will have language specific search support.

What is full-text search?

In a full-text search, a search engine examines all of the words in every stored document as it tries to match search criteria (for example, text specified by a user). Full-text-searching techniques became common in online bibliographic databases in the 1990s.


2 Answers

Yes. However you have to create SQL server function first and call that as by default LINQ will use a like.

This blog post which will explain the detail but this is the extract:

To get it working you need to create a table valued function that does nothing more than a CONTAINSTABLE query based on the keywords you pass in,

create function udf_sessionSearch       (@keywords nvarchar(4000)) returns table as   return (select [SessionId],[rank]             from containstable(Session,(description,title),@keywords)) 

You then add this function to your LINQ 2 SQL model and he presto you can now write queries like.

    var sessList = from s   in DB.Sessions                    join fts in DB.udf_sessionSearch(SearchText)                     on s.sessionId equals fts.SessionId                  select s; 
like image 136
John Avatar answered Oct 05 '22 22:10

John


No. Full text search is not supported by LINQ To SQL.

That said, you can use a stored procedure that utilizes FTS and have the LINQ To SQL query pull data from that.

like image 24
Gabriel Isenberg Avatar answered Oct 05 '22 21:10

Gabriel Isenberg