本文整理汇总了C#中Lucene.Net.Search.MultiPhraseQuery类的典型用法代码示例。如果您正苦于以下问题:C# MultiPhraseQuery类的具体用法?C# MultiPhraseQuery怎么用?C# MultiPhraseQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiPhraseQuery类属于Lucene.Net.Search命名空间,在下文中一共展示了MultiPhraseQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestPhrasePrefix
public virtual void TestPhrasePrefix()
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Document doc1 = new Document();
Document doc2 = new Document();
Document doc3 = new Document();
Document doc4 = new Document();
Document doc5 = new Document();
doc1.Add(new Field("body", "blueberry pie", Field.Store.YES, Field.Index.ANALYZED));
doc2.Add(new Field("body", "blueberry strudel", Field.Store.YES, Field.Index.ANALYZED));
doc3.Add(new Field("body", "blueberry pizza", Field.Store.YES, Field.Index.ANALYZED));
doc4.Add(new Field("body", "blueberry chewing gum", Field.Store.YES, Field.Index.ANALYZED));
doc5.Add(new Field("body", "piccadilly circus", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc1);
writer.AddDocument(doc2);
writer.AddDocument(doc3);
writer.AddDocument(doc4);
writer.AddDocument(doc5);
writer.Optimize();
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore);
//PhrasePrefixQuery query1 = new PhrasePrefixQuery();
MultiPhraseQuery query1 = new MultiPhraseQuery();
//PhrasePrefixQuery query2 = new PhrasePrefixQuery();
MultiPhraseQuery query2 = new MultiPhraseQuery();
query1.Add(new Term("body", "blueberry"));
query2.Add(new Term("body", "strawberry"));
System.Collections.ArrayList termsWithPrefix = new System.Collections.ArrayList();
IndexReader ir = IndexReader.Open(indexStore);
// this TermEnum gives "piccadilly", "pie" and "pizza".
System.String prefix = "pi";
TermEnum te = ir.Terms(new Term("body", prefix + "*"));
do
{
if (te.Term().Text().StartsWith(prefix))
{
termsWithPrefix.Add(te.Term());
}
}
while (te.Next());
query1.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
query2.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
ScoreDoc[] result;
result = searcher.Search(query1, null, 1000).scoreDocs;
Assert.AreEqual(2, result.Length);
result = searcher.Search(query2, null, 1000).scoreDocs;
Assert.AreEqual(0, result.Length);
}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:56,代码来源:TestPhrasePrefixQuery.cs
示例2: Build
public virtual Query Build(IQueryNode queryNode)
{
MultiPhraseQueryNode phraseNode = (MultiPhraseQueryNode)queryNode;
MultiPhraseQuery phraseQuery = new MultiPhraseQuery();
IList<IQueryNode> children = phraseNode.GetChildren();
if (children != null)
{
IDictionary<int?, List<Term>> positionTermMap = new SortedDictionary<int?, List<Term>>();
foreach (IQueryNode child in children)
{
FieldQueryNode termNode = (FieldQueryNode)child;
TermQuery termQuery = (TermQuery)termNode
.GetTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
List<Term> termList;
if (!positionTermMap.TryGetValue(termNode.PositionIncrement, out termList) || termList == null)
{
termList = new List<Term>();
positionTermMap[termNode.PositionIncrement] = termList;
}
termList.Add(termQuery.Term);
}
foreach (int positionIncrement in positionTermMap.Keys)
{
List<Term> termList = positionTermMap[positionIncrement];
phraseQuery.Add(termList.ToArray(/*new Term[termList.size()]*/),
positionIncrement);
}
}
return phraseQuery;
}
开发者ID:apache,项目名称:lucenenet,代码行数:39,代码来源:MultiPhraseQueryNodeBuilder.cs
示例3: InitBlock
private void InitBlock(MultiPhraseQuery enclosingInstance)
{
this.enclosingInstance = enclosingInstance;
}
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:4,代码来源:MultiPhraseQuery.cs
示例4: TestBooleanQueryContainingSingleTermPrefixQuery
public virtual void TestBooleanQueryContainingSingleTermPrefixQuery()
{
// this tests against bug 33161 (now fixed)
// In order to cause the bug, the outer query must have more than one term
// and all terms required.
// The contained PhraseMultiQuery must contain exactly one term array.
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore, Similarity, TimeZone);
Add("blueberry pie", writer);
Add("blueberry chewing gum", writer);
Add("blue raspberry pie", writer);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
// this query will be equivalent to +body:pie +body:"blue*"
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("body", "pie")), BooleanClause.Occur.MUST);
MultiPhraseQuery trouble = new MultiPhraseQuery();
trouble.Add(new Term[] { new Term("body", "blueberry"), new Term("body", "blue") });
q.Add(trouble, BooleanClause.Occur.MUST);
// exception will be thrown here without fix
ScoreDoc[] hits = searcher.Search(q, null, 1000).ScoreDocs;
Assert.AreEqual(2, hits.Length, "Wrong number of hits");
// just make sure no exc:
searcher.Explain(q, 0);
writer.Dispose();
reader.Dispose();
indexStore.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:34,代码来源:TestMultiPhraseQuery.cs
示例5: MultiPhraseWeight
public MultiPhraseWeight(MultiPhraseQuery enclosingInstance, Searcher searcher)
{
InitBlock(enclosingInstance);
this.similarity = Enclosing_Instance.GetSimilarity(searcher);
// compute idf
System.Collections.IEnumerator i = Enclosing_Instance.termArrays.GetEnumerator();
while (i.MoveNext())
{
Term[] terms = (Term[]) i.Current;
for (int j = 0; j < terms.Length; j++)
{
idf += Enclosing_Instance.GetSimilarity(searcher).Idf(terms[j], searcher);
}
}
}
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:16,代码来源:MultiPhraseQuery.cs
示例6: TestPhrasePrefixWithBooleanQuery
public virtual void TestPhrasePrefixWithBooleanQuery()
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new StandardAnalyzer(new System.Collections.Hashtable(0)), true, IndexWriter.MaxFieldLength.LIMITED);
Add("This is a test", "object", writer);
Add("a note", "note", writer);
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore);
// This query will be equivalent to +type:note +body:"a t*"
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("type", "note")), BooleanClause.Occur.MUST);
MultiPhraseQuery trouble = new MultiPhraseQuery();
trouble.Add(new Term("body", "a"));
trouble.Add(new Term[]{new Term("body", "test"), new Term("body", "this")});
q.Add(trouble, BooleanClause.Occur.MUST);
// exception will be thrown here without fix for #35626:
ScoreDoc[] hits = searcher.Search(q, null, 1000).scoreDocs;
Assert.AreEqual(0, hits.Length, "Wrong number of hits");
searcher.Close();
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:24,代码来源:TestMultiPhraseQuery.cs
示例7: TestPhrasePrefix
public virtual void TestPhrasePrefix()
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Add("blueberry pie", writer);
Add("blueberry strudel", writer);
Add("blueberry pizza", writer);
Add("blueberry chewing gum", writer);
Add("bluebird pizza", writer);
Add("bluebird foobar pizza", writer);
Add("piccadilly circus", writer);
writer.Optimize();
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore);
// search for "blueberry pi*":
MultiPhraseQuery query1 = new MultiPhraseQuery();
// search for "strawberry pi*":
MultiPhraseQuery query2 = new MultiPhraseQuery();
query1.Add(new Term("body", "blueberry"));
query2.Add(new Term("body", "strawberry"));
System.Collections.ArrayList termsWithPrefix = new System.Collections.ArrayList();
IndexReader ir = IndexReader.Open(indexStore);
// this TermEnum gives "piccadilly", "pie" and "pizza".
System.String prefix = "pi";
TermEnum te = ir.Terms(new Term("body", prefix));
do
{
if (te.Term().Text().StartsWith(prefix))
{
termsWithPrefix.Add(te.Term());
}
}
while (te.Next());
query1.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
Assert.AreEqual("body:\"blueberry (piccadilly pie pizza)\"", query1.ToString());
query2.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
Assert.AreEqual("body:\"strawberry (piccadilly pie pizza)\"", query2.ToString());
ScoreDoc[] result;
result = searcher.Search(query1, null, 1000).scoreDocs;
Assert.AreEqual(2, result.Length);
result = searcher.Search(query2, null, 1000).scoreDocs;
Assert.AreEqual(0, result.Length);
// search for "blue* pizza":
MultiPhraseQuery query3 = new MultiPhraseQuery();
termsWithPrefix.Clear();
prefix = "blue";
te = ir.Terms(new Term("body", prefix));
do
{
if (te.Term().Text().StartsWith(prefix))
{
termsWithPrefix.Add(te.Term());
}
}
while (te.Next());
query3.Add((Term[]) termsWithPrefix.ToArray(typeof(Term)));
query3.Add(new Term("body", "pizza"));
result = searcher.Search(query3, null, 1000).scoreDocs;
Assert.AreEqual(2, result.Length); // blueberry pizza, bluebird pizza
Assert.AreEqual("body:\"(blueberry bluebird) pizza\"", query3.ToString());
// test slop:
query3.SetSlop(1);
result = searcher.Search(query3, null, 1000).scoreDocs;
Assert.AreEqual(3, result.Length); // blueberry pizza, bluebird pizza, bluebird foobar pizza
MultiPhraseQuery query4 = new MultiPhraseQuery();
try
{
query4.Add(new Term("field1", "foo"));
query4.Add(new Term("field2", "foobar"));
Assert.Fail();
}
catch (System.ArgumentException e)
{
// okay, all terms must belong to the same field
}
searcher.Close();
indexStore.Close();
}
开发者ID:Rationalle,项目名称:ravendb,代码行数:89,代码来源:TestMultiPhraseQuery.cs
示例8: TestNoDocs
public virtual void TestNoDocs()
{
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore, Similarity, TimeZone);
Add("a note", "note", writer);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
MultiPhraseQuery q = new MultiPhraseQuery();
q.Add(new Term("body", "a"));
q.Add(new Term[] { new Term("body", "nope"), new Term("body", "nope") });
Assert.AreEqual(0, searcher.Search(q, null, 1).TotalHits, "Wrong number of hits");
// just make sure no exc:
searcher.Explain(q, 0);
writer.Dispose();
reader.Dispose();
indexStore.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:21,代码来源:TestMultiPhraseQuery.cs
示例9: TestMPQ6
public virtual void TestMPQ6()
{
MultiPhraseQuery q = new MultiPhraseQuery();
q.Add(Ta(new System.String[]{"w1", "w3"}));
q.Add(Ta(new System.String[]{"w2"}));
q.Slop = 1;
Qtest(q, new int[]{0, 1, 2, 3});
}
开发者ID:Nangal,项目名称:lucene.net,代码行数:8,代码来源:TestSimpleExplanations.cs
示例10: TestZeroPosIncrSloppyMpqAndOrNoMatch
public virtual void TestZeroPosIncrSloppyMpqAndOrNoMatch()
{
MultiPhraseQuery mpq = new MultiPhraseQuery();
foreach (Token[] tap in INCR_0_QUERY_TOKENS_AND_OR_NO_MATCHN)
{
Term[] terms = TapTerms(tap);
int pos = tap[0].PositionIncrement - 1;
mpq.Add(terms, pos); //AND logic in pos, OR across lines
}
DoTestZeroPosIncrSloppy(mpq, 0);
mpq.Slop = 2;
DoTestZeroPosIncrSloppy(mpq, 0);
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:13,代码来源:TestMultiPhraseQuery.cs
示例11: TestMPQ3
public virtual void TestMPQ3()
{
MultiPhraseQuery q = new MultiPhraseQuery();
q.Add(Ta(new string[] { "w1", "xx" }));
q.Add(Ta(new string[] { "w2", "w3" }));
Qtest(q, new int[] { 0, 1, 2, 3 });
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:TestSimpleExplanations.cs
示例12: TestPhrasePrefix
public virtual void TestPhrasePrefix()
{
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore, Similarity, TimeZone);
Add("blueberry pie", writer);
Add("blueberry strudel", writer);
Add("blueberry pizza", writer);
Add("blueberry chewing gum", writer);
Add("bluebird pizza", writer);
Add("bluebird foobar pizza", writer);
Add("piccadilly circus", writer);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
// search for "blueberry pi*":
MultiPhraseQuery query1 = new MultiPhraseQuery();
// search for "strawberry pi*":
MultiPhraseQuery query2 = new MultiPhraseQuery();
query1.Add(new Term("body", "blueberry"));
query2.Add(new Term("body", "strawberry"));
LinkedList<Term> termsWithPrefix = new LinkedList<Term>();
// this TermEnum gives "piccadilly", "pie" and "pizza".
string prefix = "pi";
TermsEnum te = MultiFields.GetFields(reader).Terms("body").Iterator(null);
te.SeekCeil(new BytesRef(prefix));
do
{
string s = te.Term().Utf8ToString();
if (s.StartsWith(prefix))
{
termsWithPrefix.AddLast(new Term("body", s));
}
else
{
break;
}
} while (te.Next() != null);
query1.Add(termsWithPrefix.ToArray(/*new Term[0]*/));
Assert.AreEqual("body:\"blueberry (piccadilly pie pizza)\"", query1.ToString());
query2.Add(termsWithPrefix.ToArray(/*new Term[0]*/));
Assert.AreEqual("body:\"strawberry (piccadilly pie pizza)\"", query2.ToString());
ScoreDoc[] result;
result = searcher.Search(query1, null, 1000).ScoreDocs;
Assert.AreEqual(2, result.Length);
result = searcher.Search(query2, null, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
// search for "blue* pizza":
MultiPhraseQuery query3 = new MultiPhraseQuery();
termsWithPrefix.Clear();
prefix = "blue";
te.SeekCeil(new BytesRef(prefix));
do
{
if (te.Term().Utf8ToString().StartsWith(prefix))
{
termsWithPrefix.AddLast(new Term("body", te.Term().Utf8ToString()));
}
} while (te.Next() != null);
query3.Add(termsWithPrefix.ToArray(/*new Term[0]*/));
query3.Add(new Term("body", "pizza"));
result = searcher.Search(query3, null, 1000).ScoreDocs;
Assert.AreEqual(2, result.Length); // blueberry pizza, bluebird pizza
Assert.AreEqual("body:\"(blueberry bluebird) pizza\"", query3.ToString());
// test slop:
query3.Slop = 1;
result = searcher.Search(query3, null, 1000).ScoreDocs;
// just make sure no exc:
searcher.Explain(query3, 0);
Assert.AreEqual(3, result.Length); // blueberry pizza, bluebird pizza, bluebird
// foobar pizza
MultiPhraseQuery query4 = new MultiPhraseQuery();
try
{
query4.Add(new Term("field1", "foo"));
query4.Add(new Term("field2", "foobar"));
Assert.Fail();
}
catch (System.ArgumentException e)
{
// okay, all terms must belong to the same field
}
writer.Dispose();
reader.Dispose();
indexStore.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:99,代码来源:TestMultiPhraseQuery.cs
示例13: TestZeroPosIncrSloppyMpqAnd
public virtual void TestZeroPosIncrSloppyMpqAnd()
{
MultiPhraseQuery mpq = new MultiPhraseQuery();
int pos = -1;
foreach (Token tap in INCR_0_QUERY_TOKENS_AND)
{
pos += tap.PositionIncrement;
mpq.Add(new Term[] { new Term("field", tap.ToString()) }, pos); //AND logic
}
DoTestZeroPosIncrSloppy(mpq, 0);
mpq.Slop = 1;
DoTestZeroPosIncrSloppy(mpq, 0);
mpq.Slop = 2;
DoTestZeroPosIncrSloppy(mpq, 1);
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:15,代码来源:TestMultiPhraseQuery.cs
示例14: TestZeroPosIncrSloppyParsedAnd
public virtual void TestZeroPosIncrSloppyParsedAnd()
{
MultiPhraseQuery q = new MultiPhraseQuery();
q.Add(new Term[] { new Term("field", "a"), new Term("field", "1") }, -1);
q.Add(new Term[] { new Term("field", "b"), new Term("field", "1") }, 0);
q.Add(new Term[] { new Term("field", "c") }, 1);
DoTestZeroPosIncrSloppy(q, 0);
q.Slop = 1;
DoTestZeroPosIncrSloppy(q, 0);
q.Slop = 2;
DoTestZeroPosIncrSloppy(q, 1);
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:12,代码来源:TestMultiPhraseQuery.cs
示例15: TestZeroPosIncr
public virtual void TestZeroPosIncr()
{
Directory dir = new RAMDirectory();
Token[] tokens = new Token[3];
tokens[0] = new Token();
tokens[0].Append("a");
tokens[0].PositionIncrement = 1;
tokens[1] = new Token();
tokens[1].Append("b");
tokens[1].PositionIncrement = 0;
tokens[2] = new Token();
tokens[2].Append("c");
tokens[2].PositionIncrement = 0;
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);
Document doc = new Document();
doc.Add(new TextField("field", new CannedTokenStream(tokens)));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new TextField("field", new CannedTokenStream(tokens)));
writer.AddDocument(doc);
IndexReader r = writer.Reader;
writer.Dispose();
IndexSearcher s = NewSearcher(r);
MultiPhraseQuery mpq = new MultiPhraseQuery();
//mpq.setSlop(1);
// NOTE: not great that if we do the else clause here we
// get different scores! MultiPhraseQuery counts that
// phrase as occurring twice per doc (it should be 1, I
// think?). this is because MultipleTermPositions is able to
// return the same position more than once (0, in this
// case):
if (true)
{
mpq.Add(new Term[] { new Term("field", "b"), new Term("field", "c") }, 0);
mpq.Add(new Term[] { new Term("field", "a") }, 0);
}
else
{
mpq.Add(new Term[] { new Term("field", "a") }, 0);
mpq.Add(new Term[] { new Term("field", "b"), new Term("field", "c") }, 0);
}
TopDocs hits = s.Search(mpq, 2);
Assert.AreEqual(2, hits.TotalHits);
Assert.AreEqual(hits.ScoreDocs[0].Score, hits.ScoreDocs[1].Score, 1e-5);
/*
for(int hit=0;hit<hits.TotalHits;hit++) {
ScoreDoc sd = hits.ScoreDocs[hit];
System.out.println(" hit doc=" + sd.Doc + " score=" + sd.Score);
}
*/
r.Dispose();
dir.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:55,代码来源:TestMultiPhraseQuery.cs
示例16: TestCustomIDF
public virtual void TestCustomIDF()
{
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore, Similarity, TimeZone);
Add("this is a test", "object", writer);
Add("a note", "note", writer);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
searcher.Similarity = new DefaultSimilarityAnonymousInnerClassHelper(this);
MultiPhraseQuery query = new MultiPhraseQuery();
query.Add(new Term[] { new Term("body", "this"), new Term("body", "that") });
query.Add(new Term("body", "is"));
Weight weight = query.CreateWeight(searcher);
Assert.AreEqual(10f * 10f, weight.ValueForNormalization, 0.001f);
writer.Dispose();
reader.Dispose();
indexStore.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:21,代码来源:TestMultiPhraseQuery.cs
示例17: RandomPhraseQuery
private MultiPhraseQuery RandomPhraseQuery(int seed)
{
Random random = new Random(seed);
int length = TestUtil.NextInt(random, 2, 5);
MultiPhraseQuery pq = new MultiPhraseQuery();
int position = 0;
for (int i = 0; i < length; i++)
{
int depth = TestUtil.NextInt(random, 1, 3);
Term[] terms = new Term[depth];
for (int j = 0; j < depth; j++)
{
terms[j] = new Term("field", "" + (char)TestUtil.NextInt(random, 'a', 'z'));
}
pq.Add(terms, position);
position += TestUtil.NextInt(random, 1, 3);
}
return pq;
}
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:19,代码来源:TestSloppyPhraseQuery2.cs
示例18: TestPhrasePrefixWithBooleanQuery
public virtual void TestPhrasePrefixWithBooleanQuery()
{
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new StandardAnalyzer(Util.Version.LUCENE_CURRENT, Support.Compatibility.SetFactory.CreateHashSet<string>()), true, IndexWriter.MaxFieldLength.LIMITED);
Add("This is a test", "object", writer);
Add("a note", "note", writer);
writer.Close();
IndexSearcher searcher = new IndexSearcher(indexStore, true);
// This query will be equivalent to +type:note +body:"a t*"
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("type", "note")), Occur.MUST);
MultiPhraseQuery trouble = new MultiPhraseQuery();
trouble.Add(new Term("body", "a"));
trouble.Add(new Term[]{new Term("body", "test"), new Term("body", "this")});
q.Add(trouble, Occur.MUST);
// exception will be thrown here without fix for #35626:
ScoreDoc[] hits = searcher.Search(q, null, 1000).ScoreDocs;
Assert.AreEqual(0, hits.Length, "Wrong number of hits");
searcher.Close();
}
开发者ID:raol,项目名称:lucene.net,代码行数:24,代码来源:TestMultiPhraseQuery.cs
示例19: TestNegativeSlop
public virtual void TestNegativeSlop()
{
MultiPhraseQuery query = new MultiPhraseQuery();
query.Add(new Term("field", "two"));
query.Add(new Term("field", "one"));
try
{
query.Slop = -2;
Assert.Fail("didn't get expected exception");
}
catch (System.ArgumentException expected)
{
// expected exception
}
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:15,代码来源:TestMultiPhraseQuery.cs
示例20: TestPhrasePrefixWithBooleanQuery
public virtual void TestPhrasePrefixWithBooleanQuery()
{
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore, Similarity, TimeZone);
Add("this is a test", "object", writer);
Add("a note", "note", writer);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
// this query will be equivalent to +type:note +body:"a t*"
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("type", "note")), BooleanClause.Occur.MUST);
MultiPhraseQuery trouble = new MultiPhraseQuery();
trouble.Add(new Term("body", "a"));
trouble.Add(new Term[] { new Term("body", "test"), new Term("body", "this") });
q.Add(trouble, BooleanClause.Occur.MUST);
// exception will be thrown here without fix for #35626:
ScoreDoc[] hits = searcher.Search(q, null, 1000).ScoreDocs;
Assert.AreEqual(0, hits.Length, "Wrong number of hits");
writer.Dispose();
reader.Dispose();
indexStore.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:26,代码来源:TestMultiPhraseQuery.cs
注:本文中的Lucene.Net.Search.MultiPhraseQuery类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论