本文整理汇总了C#中Lucene.Net.Index.IndexWriter.GetReader方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.GetReader方法的具体用法?C# Lucene.Net.Index.IndexWriter.GetReader怎么用?C# Lucene.Net.Index.IndexWriter.GetReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了Lucene.Net.Index.IndexWriter.GetReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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")), Occur.SHOULD);
// LUCENE-2617: make sure that a term not in the index still contributes to the score via coord factor
float score = s.Search(q, 10).MaxScore;
Query subQuery = new TermQuery(new Term("field", "not_in_index"));
subQuery.Boost = 0;
q.Add(subQuery, Occur.SHOULD);
float score2 = s.Search(q, 10).MaxScore;
Assert.AreEqual(score * .5, score2, 1e-6);
// LUCENE-2617: make sure that a clause not in the index still contributes to the score via coord factor
BooleanQuery qq = (BooleanQuery)q.Clone();
PhraseQuery phrase = new PhraseQuery();
phrase.Add(new Term("field", "not_in_index"));
phrase.Add(new Term("field", "another_not_in_index"));
phrase.Boost = 0;
qq.Add(phrase, Occur.SHOULD);
score2 = s.Search(qq, 10).MaxScore;
Assert.AreEqual(score * (1.0 / 3), score2, 1e-6);
// now test BooleanScorer2
subQuery = new TermQuery(new Term("field", "b"));
subQuery.Boost = 0;
q.Add(subQuery, Occur.MUST);
score2 = s.Search(q, 10).MaxScore;
Assert.AreEqual(score * (2.0 / 3), score2, 1e-6);
// PhraseQuery w/ no terms added returns a null scorer
PhraseQuery pq = new PhraseQuery();
q.Add(pq, 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")), Occur.SHOULD);
q.Add(pq, 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();
}
示例3: TestBasic
public virtual void TestBasic()
{
HashSet<string> fileExtensions = new HashSet<string>();
fileExtensions.Add("fdt");
fileExtensions.Add("fdx");
Directory primaryDir = new MockRAMDirectory();
RAMDirectory secondaryDir = new MockRAMDirectory();
FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
IndexWriter writer = new IndexWriter(fsd, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
writer.UseCompoundFile = false;
TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
IndexReader reader = writer.GetReader();
Assert.AreEqual(100, reader.MaxDoc);
writer.Commit();
// we should see only fdx,fdt files here
System.String[] files = primaryDir.ListAll();
Assert.IsTrue(files.Length > 0);
for (int x = 0; x < files.Length; x++)
{
System.String ext = FileSwitchDirectory.GetExtension(files[x]);
Assert.IsTrue(fileExtensions.Contains(ext));
}
files = secondaryDir.ListAll();
Assert.IsTrue(files.Length > 0);
// we should not see fdx,fdt files here
for (int x = 0; x < files.Length; x++)
{
System.String ext = FileSwitchDirectory.GetExtension(files[x]);
Assert.IsFalse(fileExtensions.Contains(ext));
}
reader.Close();
writer.Close();
files = fsd.ListAll();
for (int i = 0; i < files.Length; i++)
{
Assert.IsNotNull(files[i]);
}
fsd.Close();
}
示例4: TestGiga
public virtual void TestGiga()
{
StandardAnalyzer analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT);
Directory index = new MockRAMDirectory();
IndexWriter w = new IndexWriter(index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
AddDoc("Lucene in Action", w);
AddDoc("Lucene for Dummies", w);
// addDoc("Giga", w);
AddDoc("Giga byte", w);
AddDoc("ManagingGigabytesManagingGigabyte", w);
AddDoc("ManagingGigabytesManagingGigabytes", w);
AddDoc("The Art of Computer Science", w);
AddDoc("J. K. Rowling", w);
AddDoc("JK Rowling", w);
AddDoc("Joanne K Roling", w);
AddDoc("Bruce Willis", w);
AddDoc("Willis bruce", w);
AddDoc("Brute willis", w);
AddDoc("B. willis", w);
IndexReader r = w.GetReader();
w.Close();
Query q = new QueryParser(Util.Version.LUCENE_CURRENT, "field", analyzer).Parse("giga~0.9");
// 3. search
IndexSearcher searcher = new IndexSearcher(r);
ScoreDoc[] hits = searcher.Search(q, 10).ScoreDocs;
Assert.AreEqual(1, hits.Length);
Assert.AreEqual(searcher.Doc(hits[0].Doc).Get("field"), "Giga byte");
r.Close();
}
示例5: TestPositionIncrements
public virtual void TestPositionIncrements()
{
Directory dir = new MockRAMDirectory();
Analyzer a = new StandardAnalyzer(Version.LUCENE_CURRENT);
IndexWriter w = new IndexWriter(dir, a, IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
doc.Add(new Field("f", "the wizard of ozzy", Field.Store.NO, Field.Index.ANALYZED));
w.AddDocument(doc);
IndexReader r = w.GetReader();
w.Close();
IndexSearcher s = new IndexSearcher(r);
QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "f", a);
Query q = qp.Parse("\"wizard of ozzy\"");
Assert.AreEqual(1, s.Search(q, 1).TotalHits);
r.Close();
dir.Close();
}
示例6: 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);
//.........这里部分代码省略.........
示例7: Test_SegmentTermVector_IndexOf
public void Test_SegmentTermVector_IndexOf()
{
Lucene.Net.Store.RAMDirectory directory = new Lucene.Net.Store.RAMDirectory();
Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.WhitespaceAnalyzer();
Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(directory, analyzer, Lucene.Net.Index.IndexWriter.MaxFieldLength.LIMITED);
Lucene.Net.Documents.Document document = new Lucene.Net.Documents.Document();
document.Add(new Lucene.Net.Documents.Field("contents", new System.IO.StreamReader(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("a_ a0"))), Lucene.Net.Documents.Field.TermVector.WITH_OFFSETS));
writer.AddDocument(document);
Lucene.Net.Index.IndexReader reader = writer.GetReader();
Lucene.Net.Index.TermPositionVector tpv = reader.GetTermFreqVector(0, "contents") as Lucene.Net.Index.TermPositionVector;
//Console.WriteLine("tpv: " + tpv);
int index = tpv.IndexOf("a_");
Assert.AreEqual(index, 1, "See the issue: LUCENENET-183");
}