本文整理汇总了C#中Lucene.Net.Index.IndexWriter.SetAllowMinus1Position方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.SetAllowMinus1Position方法的具体用法?C# Lucene.Net.Index.IndexWriter.SetAllowMinus1Position怎么用?C# Lucene.Net.Index.IndexWriter.SetAllowMinus1Position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了Lucene.Net.Index.IndexWriter.SetAllowMinus1Position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPayloadsPos0
public virtual void TestPayloadsPos0()
{
for (int x = 0; x < 2; x++)
{
Directory dir = new MockRAMDirectory();
IndexWriter writer = new IndexWriter(dir, new TestPayloadAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
if (x == 1)
{
writer.SetAllowMinus1Position();
}
Document doc = new Document();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.StreamWriter sw = new System.IO.StreamWriter(ms);
sw.Write("a a b c d e a f g h i j a b k k");
// flush to stream & reset it's position so it can be read
sw.Flush();
ms.Position = 0;
doc.Add(new Field("content", new System.IO.StreamReader(ms)));
writer.AddDocument(doc);
IndexReader r = writer.GetReader();
TermPositions tp = r.TermPositions(new Term("content", "a"));
int count = 0;
Assert.IsTrue(tp.Next());
// "a" occurs 4 times
Assert.AreEqual(4, tp.Freq());
int expected;
if (x == 1)
{
expected = System.Int32.MaxValue;
}
else
{
expected = 0;
}
Assert.AreEqual(expected, tp.NextPosition());
if (x == 1)
{
continue;
}
Assert.AreEqual(1, tp.NextPosition());
Assert.AreEqual(3, tp.NextPosition());
Assert.AreEqual(6, tp.NextPosition());
// only one doc has "a"
Assert.IsFalse(tp.Next());
IndexSearcher is_Renamed = new IndexSearcher(r);
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, 30, false);
count = 0;
bool sawZero = false;
//System.out.println("\ngetPayloadSpans test");
Lucene.Net.Search.Spans.Spans pspans = snq.GetSpans(is_Renamed.GetIndexReader());
while (pspans.Next())
{
//System.out.println(pspans.doc() + " - " + pspans.start() + " - "+ pspans.end());
System.Collections.Generic.ICollection<byte[]> payloads = pspans.GetPayload();
sawZero |= pspans.Start() == 0;
for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext(); )
{
count++;
System.Object generatedAux2 = it.Current;
//System.out.println(new String((byte[]) it.next()));
}
}
Assert.AreEqual(5, count);
Assert.IsTrue(sawZero);
//System.out.println("\ngetSpans test");
Lucene.Net.Search.Spans.Spans spans = snq.GetSpans(is_Renamed.GetIndexReader());
count = 0;
sawZero = false;
while (spans.Next())
{
count++;
sawZero |= spans.Start() == 0;
//System.out.println(spans.doc() + " - " + spans.start() + " - " + spans.end());
}
Assert.AreEqual(4, count);
Assert.IsTrue(sawZero);
//System.out.println("\nPayloadSpanUtil test");
sawZero = false;
PayloadSpanUtil psu = new PayloadSpanUtil(is_Renamed.GetIndexReader());
System.Collections.Generic.ICollection<byte[]> pls = psu.GetPayloadsForQuery(snq);
count = pls.Count;
for (System.Collections.IEnumerator it = pls.GetEnumerator(); it.MoveNext(); )
{
System.String s = new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[]) it.Current));
//System.out.println(s);
sawZero |= s.Equals("pos: 0");
}
Assert.AreEqual(5, count);
//.........这里部分代码省略.........