本文整理汇总了C#中Lucene.Net.Search.BooleanQuery.SetMinimumNumberShouldMatch方法的典型用法代码示例。如果您正苦于以下问题:C# BooleanQuery.SetMinimumNumberShouldMatch方法的具体用法?C# BooleanQuery.SetMinimumNumberShouldMatch怎么用?C# BooleanQuery.SetMinimumNumberShouldMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.BooleanQuery
的用法示例。
在下文中一共展示了BooleanQuery.SetMinimumNumberShouldMatch方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostCreate
public virtual void PostCreate(BooleanQuery q)
{
BooleanClause[] c = q.GetClauses();
int opt = 0;
for (int i = 0; i < c.Length; i++)
{
if (c[i].GetOccur() == BooleanClause.Occur.SHOULD)
opt++;
}
q.SetMinimumNumberShouldMatch(rnd.Next(opt + 2));
}
示例2: TestOutOfOrderCollection
public virtual void TestOutOfOrderCollection()
{
Directory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, null, MaxFieldLength.UNLIMITED);
for (int i = 0; i < 10; i++)
{
writer.AddDocument(new Document());
}
writer.Commit();
writer.Close();
bool[] inOrder = new bool[]{false, true};
System.String[] actualTSDCClass = new System.String[]{"OutOfOrderTopScoreDocCollector", "InOrderTopScoreDocCollector"};
// Save the original value to set later.
bool origVal = BooleanQuery.GetAllowDocsOutOfOrder();
BooleanQuery.SetAllowDocsOutOfOrder(true);
BooleanQuery bq = new BooleanQuery();
// Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
// which delegates to BS if there are no mandatory clauses.
bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
// Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
// the clause instead of BQ.
bq.SetMinimumNumberShouldMatch(1);
try
{
IndexSearcher searcher = new IndexSearcher(dir);
for (int i = 0; i < inOrder.Length; i++)
{
TopDocsCollector tdc = TopScoreDocCollector.create(3, inOrder[i]);
Assert.AreEqual("Lucene.Net.Search.TopScoreDocCollector+" + actualTSDCClass[i], tdc.GetType().FullName);
searcher.Search(new MatchAllDocsQuery(), tdc);
ScoreDoc[] sd = tdc.TopDocs().scoreDocs;
Assert.AreEqual(3, sd.Length);
for (int j = 0; j < sd.Length; j++)
{
Assert.AreEqual(j, sd[j].doc, "expected doc Id " + j + " found " + sd[j].doc);
}
}
}
finally
{
// Whatever happens, reset BooleanQuery.allowDocsOutOfOrder to the
// original value. Don't set it to false in case the implementation in BQ
// will change some day.
BooleanQuery.SetAllowDocsOutOfOrder(origVal);
}
}
示例3: TestNoOptionalButMin2
public virtual void TestNoOptionalButMin2()
{
/* one required, no optional */
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); //true, false);
q.SetMinimumNumberShouldMatch(1); // 1 of 0 optional
VerifyNrHits(q, 0);
}
示例4: TestOneOptionalEqualToMin
public virtual void TestOneOptionalEqualToMin()
{
/* two required, one optional */
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.MUST); //true, false);
q.SetMinimumNumberShouldMatch(1); // 1 of 1 optional
VerifyNrHits(q, 1);
}
示例5: TestMinHigherThenNumOptional
public virtual void TestMinHigherThenNumOptional()
{
/* two required, two prohibited, some optional */
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "6")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "5")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.MUST_NOT); //false, true );
q.Add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "1")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "C")), BooleanClause.Occur.MUST_NOT); //false, true );
q.SetMinimumNumberShouldMatch(90); // 90 of 4 optional ?!?!?!
VerifyNrHits(q, 0);
}
示例6: TestSomeReqSomeProhibAndSomeOptional
public virtual void TestSomeReqSomeProhibAndSomeOptional()
{
/* two required, two prohibited, some optional */
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "6")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "5")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.MUST_NOT); //false, true );
q.Add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "1")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "C")), BooleanClause.Occur.MUST_NOT); //false, true );
q.SetMinimumNumberShouldMatch(3); // 3 of 4 optional
VerifyNrHits(q, 1);
}
示例7: TestOneProhibAndSomeOptional
public virtual void TestOneProhibAndSomeOptional()
{
/* one prohibited, some optional */
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("data", "1")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "2")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.MUST_NOT); //false, true );
q.Add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); //false, false);
q.SetMinimumNumberShouldMatch(2); // 2 of 3 optional
VerifyNrHits(q, 1);
}
示例8: TestSomeReqAndSomeOptional
public virtual void TestSomeReqAndSomeOptional()
{
/* two required, some optional */
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "6")), BooleanClause.Occur.MUST); //true, false);
q.Add(new TermQuery(new Term("data", "5")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "4")), BooleanClause.Occur.SHOULD); //false, false);
q.Add(new TermQuery(new Term("data", "3")), BooleanClause.Occur.SHOULD); //false, false);
q.SetMinimumNumberShouldMatch(2); // 2 of 3 optional
VerifyNrHits(q, 5);
}
示例9: TestAllOptional
public virtual void TestAllOptional()
{
BooleanQuery q = new BooleanQuery();
for (int i = 1; i <= 4; i++)
{
q.Add(new TermQuery(new Term("data", "" + i)), BooleanClause.Occur.SHOULD); //false, false);
}
q.SetMinimumNumberShouldMatch(2); // match at least two of 4
VerifyNrHits(q, 2);
}
示例10: TestOutOfOrderDocsScoringSort
public virtual void TestOutOfOrderDocsScoringSort()
{
// Two Sort criteria to instantiate the multi/single comparators.
Sort[] sort = new Sort[]{new Sort(SortField.FIELD_DOC), new Sort()};
bool[][] tfcOptions = new bool[][]{new bool[]{false, false, false}, new bool[]{false, false, true}, new bool[]{false, true, false}, new bool[]{false, true, true}, new bool[]{true, false, false}, new bool[]{true, false, true}, new bool[]{true, true, false}, new bool[]{true, true, true}};
System.String[] actualTFCClasses = new System.String[]{"OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector"};
// Save the original value to set later.
bool origVal = BooleanQuery.GetAllowDocsOutOfOrder();
BooleanQuery.SetAllowDocsOutOfOrder(true);
BooleanQuery bq = new BooleanQuery();
// Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
// which delegates to BS if there are no mandatory clauses.
bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
// Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
// the clause instead of BQ.
bq.SetMinimumNumberShouldMatch(1);
try
{
for (int i = 0; i < sort.Length; i++)
{
for (int j = 0; j < tfcOptions.Length; j++)
{
TopFieldCollector tdc = TopFieldCollector.Create(sort[i], 10, tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);
Assert.IsTrue(tdc.GetType().FullName.EndsWith("+" + actualTFCClasses[j]));
full.Search(bq, tdc);
TopDocs td = tdc.TopDocs();
ScoreDoc[] sd = td.ScoreDocs;
Assert.AreEqual(10, sd.Length);
}
}
}
finally
{
// Whatever happens, reset BooleanQuery.allowDocsOutOfOrder to the
// original value. Don't set it to false in case the implementation in BQ
// will change some day.
BooleanQuery.SetAllowDocsOutOfOrder(origVal);
}
}
示例11: TestBQ20
public virtual void TestBQ20()
{
BooleanQuery q = new BooleanQuery();
q.SetMinimumNumberShouldMatch(2);
q.Add(qp.Parse("QQQQQ"), BooleanClause.Occur.SHOULD);
q.Add(qp.Parse("yy"), BooleanClause.Occur.SHOULD);
q.Add(qp.Parse("zz"), BooleanClause.Occur.SHOULD);
q.Add(qp.Parse("w5"), BooleanClause.Occur.SHOULD);
q.Add(qp.Parse("w4"), BooleanClause.Occur.SHOULD);
Qtest(q, new int[]{0, 3});
}
示例12: Test1
public virtual void Test1()
{
BooleanQuery q = new BooleanQuery();
q.Add(qp.Parse("\"w1 w2\"~1"), Occur.MUST);
q.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true), Occur.SHOULD);
q.Add(Snear(Sf("w3", 2), St("w2"), St("w3"), 5, true), Occur.SHOULD);
Query t = new FilteredQuery(qp.Parse("xx"), new ItemizedFilter(new int[]{1, 3}));
t.SetBoost(1000);
q.Add(t, Occur.SHOULD);
t = new ConstantScoreQuery(new ItemizedFilter(new int[]{0, 2}));
t.SetBoost(30);
q.Add(t, Occur.SHOULD);
DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
dm.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true));
dm.Add(qp.Parse("QQ"));
dm.Add(qp.Parse("xx yy -zz"));
dm.Add(qp.Parse("-xx -w1"));
DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
dm2.Add(qp.Parse("w1"));
dm2.Add(qp.Parse("w2"));
dm2.Add(qp.Parse("w3"));
dm.Add(dm2);
q.Add(dm, Occur.SHOULD);
BooleanQuery b = new BooleanQuery();
b.SetMinimumNumberShouldMatch(2);
b.Add(Snear("w1", "w2", 1, true), Occur.SHOULD);
b.Add(Snear("w2", "w3", 1, true), Occur.SHOULD);
b.Add(Snear("w1", "w3", 3, true), Occur.SHOULD);
q.Add(b, Occur.SHOULD);
Qtest(q, new int[]{0, 1, 2});
}