RavenDB full-text search

前端 未结 3 1132
攒了一身酷
攒了一身酷 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:30

    What you are worrying about isn't anything to do with full text - by default Lucene works on an OR basis and what you want is an AND

    If I were you I'd do

     String[] terms = searchTerm.Split(" "); // Or whatever the string.split method is
    

    and

      .Where("Name:(" + String.Join(" AND ", terms) + ")");
    

    Your index should look something like

     public class Movie_ByName : AbstractIndexCreationTask
     {
        public override IndexDefinition CreateIndexDefinition()
        {
            return new IndexDefinitionBuilder
                       {
                           Map = movies => from movie in movies
                                            select new { movie.Name, market.Id },
    
                           Indexes =
                               {
                                   {x => x.Name, FieldIndexing.Analyzed}
                               }
                       }
                .ToIndexDefinition(DocumentStore.Conventions);
        }
    

    You don't need storage, you're not requesting the data from lucene directly at any time. You might not even want an index (You might actually want FieldIndexing.Analyzed, and might get away with just using dynamic queries here)

    Up to you though.

提交回复
热议问题