本文整理汇总了C#中Lucene.Net.Search.DisjunctionMaxQuery.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DisjunctionMaxQuery.Add方法的具体用法?C# DisjunctionMaxQuery.Add怎么用?C# DisjunctionMaxQuery.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.DisjunctionMaxQuery
的用法示例。
在下文中一共展示了DisjunctionMaxQuery.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public Result Search (string term, int count, int start) {
try {
term = term.ToLower ();
Term htTerm = new Term ("hottext", term);
Query qq1 = new FuzzyQuery (htTerm);
Query qq2 = new TermQuery (htTerm);
qq2.Boost = 10f;
Query qq3 = new PrefixQuery (htTerm);
qq3.Boost = 10f;
DisjunctionMaxQuery q1 = new DisjunctionMaxQuery (0f);
q1.Add (qq1);
q1.Add (qq2);
q1.Add (qq3);
Query q2 = new TermQuery (new Term ("text", term));
q2.Boost = 3f;
Query q3 = new TermQuery (new Term ("examples", term));
q3.Boost = 3f;
DisjunctionMaxQuery q = new DisjunctionMaxQuery (0f);
q.Add (q1);
q.Add (q2);
q.Add (q3);
TopDocs top = SearchInternal (q, count, start);
Result r = new Result (term, searcher, top.ScoreDocs);
Results.Add (r);
return r;
} catch (IOException) {
Console.WriteLine ("No index in {0}", dir);
return null;
}
}
示例2: Test1
public virtual void Test1()
{
BooleanQuery q = new BooleanQuery();
PhraseQuery phraseQuery = new PhraseQuery();
phraseQuery.Slop = 1;
phraseQuery.Add(new Term(FIELD, "w1"));
phraseQuery.Add(new Term(FIELD, "w2"));
q.Add(phraseQuery, 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(new TermQuery(new Term(FIELD, "xx")), new ItemizedFilter(new int[] { 1, 3 }));
t.Boost = 1000;
q.Add(t, Occur.SHOULD);
t = new ConstantScoreQuery(new ItemizedFilter(new int[] { 0, 2 }));
t.Boost = 30;
q.Add(t, Occur.SHOULD);
DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
dm.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true));
dm.Add(new TermQuery(new Term(FIELD, "QQ")));
BooleanQuery xxYYZZ = new BooleanQuery();
xxYYZZ.Add(new TermQuery(new Term(FIELD, "xx")), Occur.SHOULD);
xxYYZZ.Add(new TermQuery(new Term(FIELD, "yy")), Occur.SHOULD);
xxYYZZ.Add(new TermQuery(new Term(FIELD, "zz")), Occur.MUST_NOT);
dm.Add(xxYYZZ);
BooleanQuery xxW1 = new BooleanQuery();
xxW1.Add(new TermQuery(new Term(FIELD, "xx")), Occur.MUST_NOT);
xxW1.Add(new TermQuery(new Term(FIELD, "w1")), Occur.MUST_NOT);
dm.Add(xxW1);
DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
dm2.Add(new TermQuery(new Term(FIELD, "w1")));
dm2.Add(new TermQuery(new Term(FIELD, "w2")));
dm2.Add(new TermQuery(new Term(FIELD, "w3")));
dm.Add(dm2);
q.Add(dm, Occur.SHOULD);
BooleanQuery b = new BooleanQuery();
b.MinimumNumberShouldMatch = 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 });
}
示例3: TestDisjunctionSumVersusDisjunctionMax
public virtual void TestDisjunctionSumVersusDisjunctionMax()
{
Term t1 = RandomTerm();
Term t2 = RandomTerm();
BooleanQuery q1 = new BooleanQuery();
q1.Add(new TermQuery(t1), Occur.SHOULD);
q1.Add(new TermQuery(t2), Occur.SHOULD);
DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.5f);
q2.Add(new TermQuery(t1));
q2.Add(new TermQuery(t2));
AssertSameSet(q1, q2);
}
示例4: 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});
}
示例5: GetQuery
/// <summary>
/// (non-Javadoc)
/// @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
/// </summary>
public virtual Query GetQuery(XmlElement e)
{
float tieBreaker = DOMUtils.GetAttribute(e, "tieBreaker", 0.0f);
DisjunctionMaxQuery dq = new DisjunctionMaxQuery(tieBreaker);
dq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
XmlNodeList nl = e.ChildNodes;
for (int i = 0; i < nl.Count; i++)
{
XmlNode node = nl.Item(i);
if (node is XmlElement)
{ // all elements are disjuncts.
XmlElement queryElem = (XmlElement)node;
Query q = factory.GetQuery(queryElem);
dq.Add(q);
}
}
return dq;
}
示例6: TestDMQ7
public virtual void TestDMQ7()
{
DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
q.Add(qp.Parse("-yy w3"));
q.Add(qp.Parse("w2"));
Qtest(q, new int[]{0, 1, 2, 3});
}
示例7: TestDMQ3
public virtual void TestDMQ3()
{
DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
q.Add(qp.Parse("QQ"));
q.Add(qp.Parse("w5"));
Qtest(q, new int[]{0});
}
示例8: TestNullOrSubScorer
public virtual void TestNullOrSubScorer()
{
Directory dir = new MockRAMDirectory();
IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
doc.Add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
w.AddDocument(doc);
IndexReader r = w.GetReader();
IndexSearcher s = new IndexSearcher(r);
BooleanQuery q = new BooleanQuery();
q.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
// PhraseQuery w/ no terms added returns a null scorer
PhraseQuery pq = new PhraseQuery();
q.Add(pq, BooleanClause.Occur.SHOULD);
Assert.AreEqual(1, s.Search(q, 10).TotalHits);
// A required clause which returns null scorer should return null scorer to
// IndexSearcher.
q = new BooleanQuery();
pq = new PhraseQuery();
q.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
q.Add(pq, BooleanClause.Occur.MUST);
Assert.AreEqual(0, s.Search(q, 10).TotalHits);
DisjunctionMaxQuery dmq = new DisjunctionMaxQuery(1.0f);
dmq.Add(new TermQuery(new Term("field", "a")));
dmq.Add(pq);
Assert.AreEqual(1, s.Search(dmq, 10).TotalHits);
r.Close();
w.Close();
dir.Close();
}
示例9: TestDMQ4
public virtual void TestDMQ4()
{
DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
q.Add(new TermQuery(new Term(FIELD, "QQ")));
q.Add(new TermQuery(new Term(FIELD, "xx")));
Qtest(q, new int[] { 2, 3 });
}
示例10: TestSkipToFirsttimeHit
public virtual void TestSkipToFirsttimeHit()
{
DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f);
dq.Add(Tq("dek", "albino"));
dq.Add(Tq("dek", "DOES_NOT_EXIST"));
QueryUtils.Check(dq, s);
Weight dw = dq.Weight(s);
Scorer ds = dw.Scorer(r);
Assert.IsTrue(ds.SkipTo(3), "firsttime skipTo found no match");
Assert.AreEqual("d4", r.Document(ds.Doc()).Get("id"), "found wrong docid");
}
示例11: TestSkipToFirsttimeMiss
public virtual void TestSkipToFirsttimeMiss()
{
DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f);
dq.Add(Tq("id", "d1"));
dq.Add(Tq("dek", "DOES_NOT_EXIST"));
QueryUtils.Check(dq, s);
Weight dw = dq.Weight(s);
Scorer ds = dw.Scorer(r);
bool skipOk = ds.SkipTo(3);
if (skipOk)
{
Assert.Fail("firsttime skipTo found a match? ... " + r.Document(ds.Doc()).Get("id"));
}
}
示例12: TestBooleanSpanQuery
public virtual void TestBooleanSpanQuery()
{
int hits = 0;
Directory directory = NewDirectory();
Analyzer indexerAnalyzer = new MockAnalyzer(Random());
IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, indexerAnalyzer);
IndexWriter writer = new IndexWriter(directory, config);
string FIELD = "content";
Document d = new Document();
d.Add(new TextField(FIELD, "clockwork orange", Field.Store.YES));
writer.AddDocument(d);
writer.Dispose();
IndexReader indexReader = DirectoryReader.Open(directory);
IndexSearcher searcher = NewSearcher(indexReader);
DisjunctionMaxQuery query = new DisjunctionMaxQuery(1.0f);
SpanQuery sq1 = new SpanTermQuery(new Term(FIELD, "clockwork"));
SpanQuery sq2 = new SpanTermQuery(new Term(FIELD, "clckwork"));
query.Add(sq1);
query.Add(sq2);
TopScoreDocCollector collector = TopScoreDocCollector.Create(1000, true);
searcher.Search(query, collector);
hits = collector.TopDocs().ScoreDocs.Length;
foreach (ScoreDoc scoreDoc in collector.TopDocs().ScoreDocs)
{
Console.WriteLine(scoreDoc.Doc);
}
indexReader.Dispose();
Assert.AreEqual(hits, 1);
directory.Dispose();
}
示例13: TestBooleanOptionalWithTiebreakerAndBoost
public virtual void TestBooleanOptionalWithTiebreakerAndBoost()
{
BooleanQuery q = new BooleanQuery();
{
DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
q1.Add(Tq("hed", "albino", 1.5f));
q1.Add(Tq("dek", "albino"));
q.Add(q1, BooleanClause.Occur.SHOULD); // false,false);
}
{
DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
q2.Add(Tq("hed", "elephant", 1.5f));
q2.Add(Tq("dek", "elephant"));
q.Add(q2, BooleanClause.Occur.SHOULD); // false,false);
}
QueryUtils.Check(Random(), q, s, Similarity);
ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
try
{
Assert.AreEqual(4, h.Length, "4 docs should match " + q.ToString());
float score0 = h[0].Score;
float score1 = h[1].Score;
float score2 = h[2].Score;
float score3 = h[3].Score;
string doc0 = s.Doc(h[0].Doc).Get("id");
string doc1 = s.Doc(h[1].Doc).Get("id");
string doc2 = s.Doc(h[2].Doc).Get("id");
string doc3 = s.Doc(h[3].Doc).Get("id");
Assert.AreEqual("d4", doc0, "doc0 should be d4: ");
Assert.AreEqual("d3", doc1, "doc1 should be d3: ");
Assert.AreEqual("d2", doc2, "doc2 should be d2: ");
Assert.AreEqual("d1", doc3, "doc3 should be d1: ");
Assert.IsTrue(score0 > score1, "d4 does not have a better score then d3: " + score0 + " >? " + score1);
Assert.IsTrue(score1 > score2, "d3 does not have a better score then d2: " + score1 + " >? " + score2);
Assert.IsTrue(score2 > score3, "d3 does not have a better score then d1: " + score2 + " >? " + score3);
}
catch (Exception e)
{
PrintHits("TestBooleanOptionalWithTiebreakerAndBoost", h, s);
throw e;
}
}
示例14: TestBooleanOptionalNoTiebreaker
public virtual void TestBooleanOptionalNoTiebreaker()
{
BooleanQuery q = new BooleanQuery();
{
DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
q1.Add(Tq("hed", "albino"));
q1.Add(Tq("dek", "albino"));
q.Add(q1, BooleanClause.Occur.SHOULD); // false,false);
}
{
DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
q2.Add(Tq("hed", "elephant"));
q2.Add(Tq("dek", "elephant"));
q.Add(q2, BooleanClause.Occur.SHOULD); // false,false);
}
QueryUtils.Check(Random(), q, s, Similarity);
ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
try
{
Assert.AreEqual(4, h.Length, "4 docs should match " + q.ToString());
float score = h[0].Score;
for (int i = 1; i < h.Length - 1; i++) // note: -1
{
Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same");
}
Assert.AreEqual("d1", s.Doc(h[h.Length - 1].Doc).Get("id"), "wrong last");
float score1 = h[h.Length - 1].Score;
Assert.IsTrue(score > score1, "d1 does not have worse score then others: " + score + " >? " + score1);
}
catch (Exception e)
{
PrintHits("testBooleanOptionalNoTiebreaker", h, s);
throw e;
}
}
示例15: TestBooleanRequiredEqualScores
public virtual void TestBooleanRequiredEqualScores()
{
BooleanQuery q = new BooleanQuery();
{
DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
q1.Add(Tq("hed", "albino"));
q1.Add(Tq("dek", "albino"));
q.Add(q1, BooleanClause.Occur.MUST); // true,false);
QueryUtils.Check(Random(), q1, s, Similarity);
}
{
DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
q2.Add(Tq("hed", "elephant"));
q2.Add(Tq("dek", "elephant"));
q.Add(q2, BooleanClause.Occur.MUST); // true,false);
QueryUtils.Check(Random(), q2, s, Similarity);
}
QueryUtils.Check(Random(), q, s, Similarity);
ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
try
{
Assert.AreEqual(3, h.Length, "3 docs should match " + q.ToString());
float score = h[0].Score;
for (int i = 1; i < h.Length; i++)
{
Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same");
}
}
catch (Exception e)
{
PrintHits("testBooleanRequiredEqualScores1", h, s);
throw e;
}
}