RavenDB full-text search

前端 未结 3 1133
攒了一身酷
攒了一身酷 2021-02-04 13:11

Can you please tell how to perform simple full-text search in RavenDb. The database is stored document: Movie {Name = \"Pirates of the Carribean\"}. I

3条回答
  •  半阙折子戏
    2021-02-04 13:32

    Here's how I acheived an "ANDing" term search.

    First, make sure that your field is indexed and analyzed:

    public class MyIndex: AbstractIndexCreationTask
    {
        public MyIndex()
        {
            Map = docs => from d in docs
                          select new { d.MyTextField  };
    
            Index(x => x.MyTextField, FieldIndexing.Analyzed);
        }
    }
    

    Then query from the client:

       var query = session.Query();
    
        query = theSearchText
                    .Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries)
                    .Aggregate(query, (q, term) =>
                         q.Search(x => x.MyTextField, term, options: SearchOptions.And));
    

提交回复
热议问题