LinqToSql and full text search - can it be done?

前端 未结 2 668
不思量自难忘°
不思量自难忘° 2021-01-05 19:07

Has anyone come up with a good way of performing full text searches (FREETEXT() CONTAINS()) for any number of arbitrary keywords using standard LinqToSql query

相关标签:
2条回答
  • 2021-01-05 19:33

    I've manage to get around this by using a table valued function to encapsulate the full text search component, then referenced it within my LINQ expression maintaining the benefits of delayed execution:

    string q = query.Query;
    IQueryable<Story> stories = ActiveStories
                            .Join(tvf_SearchStories(q), o => o.StoryId, i => i.StoryId, (o,i) => o)
                            .Where (s => (query.CategoryIds.Contains(s.CategoryId)) &&
                                        /* time frame filter */
                                    (s.PostedOn >= (query.Start ?? SqlDateTime.MinValue.Value)) &&
                                    (s.PostedOn <= (query.End ?? SqlDateTime.MaxValue.Value)));
    

    Here 'tvf_SearchStories' is the table valued function that internally uses full text search

    0 讨论(0)
  • 2021-01-05 19:34

    Unfortunately LINQ to SQL does not support Full Text Search.

    There are a bunch of products out there that I think could: Lucene.NET, NHibernate Search comes to mind. LINQ for NHibernate combined with NHibernate Search would probably give that functionality, but both are still way deep in beta.

    0 讨论(0)
提交回复
热议问题