English 中文(简体)
使用 ravendb/lucene 的自然语言查询
原标题:natural language query using ravendb/lucene

在 ravenb 中取一个“ zoo” 文档列表, 每个文档中都有一年的字段和描述字段。 描述是一个字符串, 除其他信息外, 将包括在该动物园可以看到的许多动物。

(1) 如何使用“黑猩猩和红猩猩或“大猿”而非狐猴的用户搜索值,以及如何搜索动物园以查找描述。

(2) 除了1920年10年内建立的所有动物园之外,我怎么能做同样的搜索。

(3) 如何进行以下近距离搜索:“黑猩猩猩猩”~3和大象。

就本问题而言,不要担心动物名称的单体或多元形式,假设它们将是多元的。

我期待以下测试结果为零, 反之则返回二:

    public void LuceneANDQuery()
    {
        var zoosToCreate = new List<Zoo>
                               {
                                   new Zoo()
                                       {
                                           Description = "We have alligators, orangutans and chimpanzees",
                                           AbbreviatedState = "DC"
                                       },
                                   new Zoo()
                                       {Description = "We have orangutans and elephants", AbbreviatedState = "CA"}
                               };
        using (var session = documentStore.OpenSession())
        {
            zoosToCreate.ForEach(session.Store);
            session.SaveChanges();
            new DescriptionIndex().Execute(documentStore);
            string searchPhrase = @"lizards && orangutans";
            var matchingZoos = session.Advanced.LuceneQuery<Zoo>("DescriptionIndex").Search("Description", searchPhrase).
                WaitForNonStaleResultsAsOfNow().ToList();
            int matchingZoosCount = matchingZoos.Count;
            Assert.AreEqual(matchingZoosCount, 0);
        }
    }

    public class DescriptionIndex : AbstractIndexCreationTask<Zoo>
    {
        public DescriptionIndex()
        {
            Map = zoos => from zoo in zoos
                          select new {zoo.Description};
            Analyzers.Add(z => z.Description, "Lucene.Net.Analysis.Standard.StandardAnalyzer");
            Indexes.Add(z => z.Description, FieldIndexing.Analyzed);
        }
    }
最佳回答

Balazs, You can literally just run this query. RavenDB uses Lucene under the cover, and it expose its query outward. That means that you can just run queries like that. This is exposed in the API using Session.Advanced.LuceneQuery.

有一点需要注意的是,我们不支持默认字段,所以你需要具体说明你指的是什么字段,但这就是它。

问题回答

暂无回答




相关问题
Lucene.NET in medium trust

How do I make Lucene.NET 2.3.2 run in a medium trust environment? GoDaddy doesn t like it the way it is.

Grails searchable plugin

In my Grails app, I m using the Searchable plugin for searching/indexing. I want to write a Compass/Lucene query that involves multiple domain classes. Within that query when I want to refer to the id ...

Search subset of objects using Compass/Lucene

I m using the searchable plugin for Grails (which provides an API for Compass, which is itself an API over Lucene). I have an Order class that I would like to search but, I don t want to search all ...

Lucene seems to be caching search results - why?

In my project we use Lucene 2.4.1 for fulltext search. This is a J2EE project, IndexSearcher is created once. In the background, the index is refreshed every couple of minutes (when the content ...

热门标签