本文整理汇总了C#中Lucene.Net.Search.DisjunctionMaxQuery类的典型用法代码示例。如果您正苦于以下问题:C# DisjunctionMaxQuery类的具体用法?C# DisjunctionMaxQuery怎么用?C# DisjunctionMaxQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DisjunctionMaxQuery类属于Lucene.Net.Search命名空间,在下文中一共展示了DisjunctionMaxQuery类的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: 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;
}
示例5: 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});
}
示例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: 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); //false,false);
QueryUtils.Check(q1, s);
}
{
DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
q2.Add(Tq("hed", "elephant"));
q2.Add(Tq("dek", "elephant"));
q.Add(q2, BooleanClause.Occur.MUST); //false,false);
QueryUtils.Check(q2, s);
}
QueryUtils.Check(q, s);
Hits h = s.Search(q);
try
{
Assert.AreEqual(3, h.Length(), "3 docs should match " + q.ToString());
float score = h.Score(0);
for (int i = 1; i < h.Length(); i++)
{
Assert.AreEqual(score, h.Score(i), SCORE_COMP_THRESH, "score #" + i + " is not the same");
}
}
catch (System.ApplicationException e)
{
PrintHits("testBooleanRequiredEqualScores1", h);
throw e;
}
}
示例11: TestSimpleTiebreaker
public virtual void TestSimpleTiebreaker()
{
DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.01f);
q.Add(Tq("dek", "albino"));
q.Add(Tq("dek", "elephant"));
QueryUtils.Check(q, s);
Hits h = s.Search(q);
try
{
Assert.AreEqual(3, h.Length(), "3 docs should match " + q.ToString());
Assert.AreEqual("d2", h.Doc(0).Get("id"), "wrong first");
float score0 = h.Score(0);
float score1 = h.Score(1);
float score2 = h.Score(2);
Assert.IsTrue(score0 > score1, "d2 does not have better score then others: " + score0 + " >? " + score1);
Assert.AreEqual(score1, score2, SCORE_COMP_THRESH, "d4 and d1 don't have equal scores");
}
catch (System.ApplicationException e)
{
PrintHits("testSimpleTiebreaker", h);
throw e;
}
}
示例12: TestSimpleEqualScores3
public virtual void TestSimpleEqualScores3()
{
DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.0f);
q.Add(Tq("hed", "albino"));
q.Add(Tq("hed", "elephant"));
q.Add(Tq("dek", "albino"));
q.Add(Tq("dek", "elephant"));
QueryUtils.Check(q, s);
Hits h = s.Search(q);
try
{
Assert.AreEqual(4, h.Length(), "all docs should match " + q.ToString());
float score = h.Score(0);
for (int i = 1; i < h.Length(); i++)
{
Assert.AreEqual(score, h.Score(i), SCORE_COMP_THRESH, "score #" + i + " is not the same");
}
}
catch (System.ApplicationException e)
{
PrintHits("testSimpleEqualScores3", h);
throw e;
}
}
示例13: 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");
}
示例14: 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"));
}
}
示例15: 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();
}