RavenDB 全文搜索

发布于 2024-10-05 08:27:41 字数 141 浏览 5 评论 0原文

您能告诉我如何在RavenDb中执行简单的全文搜索吗?数据库存储文档:Movie {Name = "Pirates of the Carribean"}。我希望在搜索短语“加勒比海盗”或任何其他单词组合中找到该文档。

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 wish that this document was found on the search phrase "Pirates Carribean" or any other combination of words.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜光 2024-10-12 08:27:41

鲍里斯,
Rob的答案有正确的索引,但查询起来有点尴尬。您可以使用以下方法来做到这一点

 session.Query<Movie, Movie_ByName>()
         .Search(x=>x.Name, searchTerms)
         .ToList()

Boris,
Rob's answer has the right index, but it is a bit awkward for querying. You can do that using:

 session.Query<Movie, Movie_ByName>()
         .Search(x=>x.Name, searchTerms)
         .ToList()

That will

又怨 2024-10-12 08:27:41

你担心的与全文无关 - 默认情况下 Lucene 在 OR 基础上工作,你想要的是 AND

如果我是你,我会这样做

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

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

你的索引应该看起来像

 public class Movie_ByName : AbstractIndexCreationTask
 {
    public override IndexDefinition CreateIndexDefinition()
    {
        return new IndexDefinitionBuilder<Movie>
                   {
                       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存储,您在任何时候都不会直接从 lucene 请求数据。您甚至可能不需要索引(您实际上可能需要 FieldIndexing.Analyzed,并且可能只需要在此处使用动态查询)

即可。不过,这取决于您。

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<Movie>
                   {
                       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.

素染倾城色 2024-10-12 08:27:41

以下是我如何实现“ANDing”术语搜索。

首先,确保您的字段已被索引和分析:

public class MyIndex: AbstractIndexCreationTask<MyDocument>
{
    public MyIndex()
    {
        Map = docs => from d in docs
                      select new { d.MyTextField  };

        Index(x => x.MyTextField, FieldIndexing.Analyzed);
    }
}

然后从客户端查询:

   var query = session.Query<MyDocument, MyIndex>();

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

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

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

public class MyIndex: AbstractIndexCreationTask<MyDocument>
{
    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<MyDocument, MyIndex>();

    query = theSearchText
                .Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries)
                .Aggregate(query, (q, term) =>
                     q.Search(x => x.MyTextField, term, options: SearchOptions.And));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文