本文整理汇总了C#中Lucene.Net.Search.Spans.SpanNearQuery.GetSpans方法的典型用法代码示例。如果您正苦于以下问题:C# SpanNearQuery.GetSpans方法的具体用法?C# SpanNearQuery.GetSpans怎么用?C# SpanNearQuery.GetSpans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.Spans.SpanNearQuery
的用法示例。
在下文中一共展示了SpanNearQuery.GetSpans方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSpanNearOrderedOverlap
public virtual void TestSpanNearOrderedOverlap()
{
bool ordered = true;
int slop = 1;
SpanNearQuery snq = new SpanNearQuery(new SpanQuery[]{MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2"), MakeSpanTermQuery("t3")}, slop, ordered);
Spans spans = snq.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans.Next(), "first range");
Assert.AreEqual(11, spans.Doc(), "first doc");
Assert.AreEqual(0, spans.Start(), "first start");
Assert.AreEqual(4, spans.End(), "first end");
Assert.IsTrue(spans.Next(), "second range");
Assert.AreEqual(11, spans.Doc(), "second doc");
Assert.AreEqual(2, spans.Start(), "second start");
Assert.AreEqual(6, spans.End(), "second end");
Assert.IsFalse(spans.Next(), "third range");
}
示例2: TestSpanNearUnOrdered
public virtual void TestSpanNearUnOrdered()
{
//See http://www.gossamer-threads.com/lists/lucene/java-dev/52270 for discussion about this test
SpanNearQuery snq;
snq = new SpanNearQuery(new SpanQuery[]{MakeSpanTermQuery("u1"), MakeSpanTermQuery("u2")}, 0, false);
Spans spans = snq.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(4, spans.Doc(), "doc");
Assert.AreEqual(1, spans.Start(), "start");
Assert.AreEqual(3, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(5, spans.Doc(), "doc");
Assert.AreEqual(2, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(8, spans.Doc(), "doc");
Assert.AreEqual(2, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(9, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(2, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(10, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(2, spans.End(), "end");
Assert.IsTrue(spans.Next() == false, "Has next and it shouldn't: " + spans.Doc());
SpanNearQuery u1u2 = new SpanNearQuery(new SpanQuery[]{MakeSpanTermQuery("u1"), MakeSpanTermQuery("u2")}, 0, false);
snq = new SpanNearQuery(new SpanQuery[]{u1u2, MakeSpanTermQuery("u2")}, 1, false);
spans = snq.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(4, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(3, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
//unordered spans can be subsets
Assert.AreEqual(4, spans.Doc(), "doc");
Assert.AreEqual(1, spans.Start(), "start");
Assert.AreEqual(3, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(5, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(5, spans.Doc(), "doc");
Assert.AreEqual(2, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(8, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(8, spans.Doc(), "doc");
Assert.AreEqual(2, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(9, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(2, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(9, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(4, spans.End(), "end");
Assert.IsTrue(spans.Next(), "Does not have next and it should");
Assert.AreEqual(10, spans.Doc(), "doc");
Assert.AreEqual(0, spans.Start(), "start");
Assert.AreEqual(2, spans.End(), "end");
Assert.IsTrue(spans.Next() == false, "Has next and it shouldn't");
}
示例3: TestShrinkToAfterShortestMatch3
public virtual void TestShrinkToAfterShortestMatch3()
{
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();
doc.Add(new Field("content", new System.IO.StreamReader(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("j k a l f k k p a t a k l k t a")))));
writer.AddDocument(doc);
writer.Close();
IndexSearcher is_Renamed = new IndexSearcher(directory);
SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
SpanQuery[] sqs = new SpanQuery[]{stq1, stq2};
SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
Spans spans = snq.GetSpans(is_Renamed.GetIndexReader());
TopDocs topDocs = is_Renamed.Search(snq, 1);
System.Collections.Hashtable payloadSet = new System.Collections.Hashtable();
for (int i = 0; i < topDocs.ScoreDocs.Length; i++)
{
while (spans.Next())
{
System.Collections.Generic.ICollection<byte[]> payloads = spans.GetPayload();
for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext(); )
{
Support.CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[]) it.Current)));
}
}
}
Assert.AreEqual(2, payloadSet.Count);
if (DEBUG)
{
System.Collections.IEnumerator pit = payloadSet.GetEnumerator();
while (pit.MoveNext())
{
System.Console.Out.WriteLine("match:" + pit.Current);
}
}
Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
}
示例4: TestHeavilyNestedSpanQuery
public virtual void TestHeavilyNestedSpanQuery()
{
Spans spans;
IndexSearcher searcher = GetSearcher();
SpanQuery[] clauses = new SpanQuery[3];
clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "two"));
clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "three"));
SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 5, true);
clauses = new SpanQuery[3];
clauses[0] = spanNearQuery;
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "five"));
clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "six"));
SpanNearQuery spanNearQuery2 = new SpanNearQuery(clauses, 6, true);
SpanQuery[] clauses2 = new SpanQuery[2];
clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "eleven"));
clauses2[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "ten"));
SpanNearQuery spanNearQuery3 = new SpanNearQuery(clauses2, 2, false);
SpanQuery[] clauses3 = new SpanQuery[3];
clauses3[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "nine"));
clauses3[1] = spanNearQuery2;
clauses3[2] = spanNearQuery3;
SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
spans = nestedSpanNearQuery.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
CheckSpans(spans, 2, new int[]{8, 8});
}
示例5: TestFirstClauseWithoutPayload
public virtual void TestFirstClauseWithoutPayload()
{
Spans spans;
IndexSearcher searcher = GetSearcher();
SpanQuery[] clauses = new SpanQuery[3];
clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "nopayload"));
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "qq"));
clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "ss"));
SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 6, true);
SpanQuery[] clauses2 = new SpanQuery[2];
clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "pp"));
clauses2[1] = spanNearQuery;
SpanNearQuery snq = new SpanNearQuery(clauses2, 6, false);
SpanQuery[] clauses3 = new SpanQuery[2];
clauses3[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "np"));
clauses3[1] = snq;
SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
spans = nestedSpanNearQuery.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
CheckSpans(spans, 1, new int[]{3});
}
示例6: TestNestedSpans
public virtual void TestNestedSpans()
{
SpanTermQuery stq;
Spans spans;
IndexSearcher searcher = GetSearcher();
stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "mark"));
spans = stq.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
CheckSpans(spans, 0, null);
SpanQuery[] clauses = new SpanQuery[3];
clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "rr"));
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 12, false);
spans = spanNearQuery.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
CheckSpans(spans, 2, new int[]{3, 3});
clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "rr"));
clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
spanNearQuery = new SpanNearQuery(clauses, 6, true);
spans = spanNearQuery.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
CheckSpans(spans, 1, new int[]{3});
clauses = new SpanQuery[2];
clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "rr"));
spanNearQuery = new SpanNearQuery(clauses, 6, true);
// xx within 6 of rr
SpanQuery[] clauses2 = new SpanQuery[2];
clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
clauses2[1] = spanNearQuery;
SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses2, 6, false);
// yy within 6 of xx within 6 of rr
spans = nestedSpanNearQuery.GetSpans(searcher.GetIndexReader());
Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
CheckSpans(spans, 2, new int[]{3, 3});
}
示例7: TestSpans2
public virtual void TestSpans2()
{
SpanQuery qA1 = new SpanTermQuery(new Term("gender", "female"));
SpanQuery qA2 = new SpanTermQuery(new Term("first", "james"));
SpanQuery qA = new SpanOrQuery(new SpanQuery[]{qA1, new FieldMaskingSpanQuery(qA2, "gender")});
SpanQuery qB = new SpanTermQuery(new Term("last", "jones"));
SpanQuery q = new SpanNearQuery(new SpanQuery[]{new FieldMaskingSpanQuery(qA, "id"), new FieldMaskingSpanQuery(qB, "id")}, - 1, false);
Check(q, new int[]{0, 1, 2, 3});
Spans span = q.GetSpans(searcher.GetIndexReader());
Assert.AreEqual(true, span.Next());
Assert.AreEqual(S(0, 0, 1), S(span));
Assert.AreEqual(true, span.Next());
Assert.AreEqual(S(1, 1, 2), S(span));
Assert.AreEqual(true, span.Next());
Assert.AreEqual(S(2, 0, 1), S(span));
Assert.AreEqual(true, span.Next());
Assert.AreEqual(S(2, 2, 3), S(span));
Assert.AreEqual(true, span.Next());
Assert.AreEqual(S(3, 0, 1), S(span));
Assert.AreEqual(false, span.Next());
}