ravendb の「zoo」ドキュメントのリストを取得します。各ドキュメントには、設立された年のフィールドと説明のフィールドがあります。説明は、他の情報とともに、その動物園で見られる動物の多くを含む文字列です。
(1) 「チンパンジー AND オランウータン OR 「類人猿」NOT キツネザル」というユーザー検索値を取得し、動物園で説明を検索するにはどうすればよいですか。
(2) 1920 年から 10 年以内に設立されたすべての動物園に対して、同じ検索を行うにはどうすればよいでしょうか。
(3) 次の近接検索を行うにはどうすればよいですか: "チンパンジー オランウータン"~3 AND ゾウ.
この質問の目的上、動物の名前の単数形または複数形について心配する必要はありません。それらが複数になると仮定します。
編集:次のテストでは結果が 0 になると予想されますが、代わりに 2 つが返されます。
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);
}
}