本文整理汇总了C#中Lucene.Net.Index.RandomIndexWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.RandomIndexWriter.Dispose方法的具体用法?C# Lucene.Net.Index.RandomIndexWriter.Dispose怎么用?C# Lucene.Net.Index.RandomIndexWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.RandomIndexWriter
的用法示例。
在下文中一共展示了Lucene.Net.Index.RandomIndexWriter.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetScores
public virtual void TestGetScores()
{
Directory directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), directory);
writer.Commit();
IndexReader ir = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
Weight fake = (new TermQuery(new Term("fake", "weight"))).CreateWeight(searcher);
Scorer s = new SimpleScorer(fake);
ScoreCachingCollector scc = new ScoreCachingCollector(Scores.Length);
scc.Scorer = s;
// We need to iterate on the scorer so that its doc() advances.
int doc;
while ((doc = s.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
{
scc.Collect(doc);
}
for (int i = 0; i < Scores.Length; i++)
{
Assert.AreEqual(Scores[i], scc.Mscores[i], 0f);
}
ir.Dispose();
directory.Dispose();
}
示例2: BeforeClass
public void BeforeClass()
{
Directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Directory, Similarity, TimeZone);
writer.Dispose();
Reader = DirectoryReader.Open(Directory);
}
示例3: BeforeClass
public static void BeforeClass()
{
Directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Directory);
writer.Dispose();
Reader = DirectoryReader.Open(Directory);
}
示例4: TestConstantScoreQueryAndFilter
public virtual void TestConstantScoreQueryAndFilter()
{
Directory d = NewDirectory();
RandomIndexWriter w = new RandomIndexWriter(Random(), d);
Document doc = new Document();
doc.Add(NewStringField("field", "a", Field.Store.NO));
w.AddDocument(doc);
doc = new Document();
doc.Add(NewStringField("field", "b", Field.Store.NO));
w.AddDocument(doc);
IndexReader r = w.Reader;
w.Dispose();
Filter filterB = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("field", "b"))));
Query query = new ConstantScoreQuery(filterB);
IndexSearcher s = NewSearcher(r);
Assert.AreEqual(1, s.Search(query, filterB, 1).TotalHits); // Query for field:b, Filter field:b
Filter filterA = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("field", "a"))));
query = new ConstantScoreQuery(filterA);
Assert.AreEqual(0, s.Search(query, filterB, 1).TotalHits); // Query field:b, Filter field:a
r.Dispose();
d.Dispose();
}
示例5: TestStartPositions
public virtual void TestStartPositions()
{
Directory dir = NewDirectory();
// mimic StopAnalyzer
CharacterRunAutomaton stopSet = new CharacterRunAutomaton((new RegExp("the|a|of")).ToAutomaton());
Analyzer analyzer = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true, stopSet);
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, analyzer);
Document doc = new Document();
doc.Add(NewTextField("field", "the quick brown fox", Field.Store.NO));
writer.AddDocument(doc);
Document doc2 = new Document();
doc2.Add(NewTextField("field", "quick brown fox", Field.Store.NO));
writer.AddDocument(doc2);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
// user queries on "starts-with quick"
SpanQuery sfq = new SpanFirstQuery(new SpanTermQuery(new Term("field", "quick")), 1);
Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);
// user queries on "starts-with the quick"
SpanQuery include = new SpanFirstQuery(new SpanTermQuery(new Term("field", "quick")), 2);
sfq = new SpanNotQuery(include, sfq);
Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);
writer.Dispose();
reader.Dispose();
dir.Dispose();
}
示例6: TestString
public virtual void TestString()
{
Directory dir = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
Document doc = new Document();
doc.Add(new SortedDocValuesField("value", new BytesRef("foo")));
doc.Add(NewStringField("value", "foo", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new SortedDocValuesField("value", new BytesRef("bar")));
doc.Add(NewStringField("value", "bar", Field.Store.YES));
writer.AddDocument(doc);
IndexReader ir = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
Sort sort = new Sort(new SortField("value", SortField.Type_e.STRING));
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
Assert.AreEqual(2, td.TotalHits);
// 'bar' comes before 'foo'
Assert.AreEqual("bar", searcher.Doc(td.ScoreDocs[0].Doc).Get("value"));
Assert.AreEqual("foo", searcher.Doc(td.ScoreDocs[1].Doc).Get("value"));
AssertNoFieldCaches();
ir.Dispose();
dir.Dispose();
}
示例7: BeforeClass
public static void BeforeClass()
{
Directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Directory);
Document doc = new Document();
Field field = NewStringField(FIELD, "meaninglessnames", Field.Store.NO);
doc.Add(field);
for (int i = 0; i < 5137; ++i)
{
writer.AddDocument(doc);
}
field.StringValue = "tangfulin";
writer.AddDocument(doc);
field.StringValue = "meaninglessnames";
for (int i = 5138; i < 11377; ++i)
{
writer.AddDocument(doc);
}
field.StringValue = "tangfulin";
writer.AddDocument(doc);
Reader = writer.Reader;
Searcher = NewSearcher(Reader);
writer.Dispose();
}
示例8: TestByte
public virtual void TestByte()
{
Directory dir = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
Document doc = new Document();
doc.Add(new NumericDocValuesField("value", 23));
doc.Add(NewStringField("value", "23", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new NumericDocValuesField("value", -1));
doc.Add(NewStringField("value", "-1", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new NumericDocValuesField("value", 4));
doc.Add(NewStringField("value", "4", Field.Store.YES));
writer.AddDocument(doc);
IndexReader ir = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
Sort sort = new Sort(new SortField("value", SortField.Type_e.BYTE));
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
Assert.AreEqual(3, td.TotalHits);
// numeric order
Assert.AreEqual("-1", searcher.Doc(td.ScoreDocs[0].Doc).Get("value"));
Assert.AreEqual("4", searcher.Doc(td.ScoreDocs[1].Doc).Get("value"));
Assert.AreEqual("23", searcher.Doc(td.ScoreDocs[2].Doc).Get("value"));
AssertNoFieldCaches();
ir.Dispose();
dir.Dispose();
}
示例9: Test2
public virtual void Test2()
{
Directory directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, new MockAnalyzer(Random(), MockTokenizer.KEYWORD, false));
AddDoc("LANGE", writer);
AddDoc("LUETH", writer);
AddDoc("PIRSING", writer);
AddDoc("RIEGEL", writer);
AddDoc("TRZECZIAK", writer);
AddDoc("WALKER", writer);
AddDoc("WBR", writer);
AddDoc("WE", writer);
AddDoc("WEB", writer);
AddDoc("WEBE", writer);
AddDoc("WEBER", writer);
AddDoc("WEBERE", writer);
AddDoc("WEBREE", writer);
AddDoc("WEBEREI", writer);
AddDoc("WBRE", writer);
AddDoc("WITTKOPF", writer);
AddDoc("WOJNAROWSKI", writer);
AddDoc("WRICKE", writer);
IndexReader reader = writer.Reader;
IndexSearcher searcher = NewSearcher(reader);
writer.Dispose();
FuzzyQuery query = new FuzzyQuery(new Term("field", "WEBER"), 2, 1);
//query.setRewriteMethod(FuzzyQuery.SCORING_BOOLEAN_QUERY_REWRITE);
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(8, hits.Length);
reader.Dispose();
directory.Dispose();
}
示例10: TestPrefixQuery_Mem
public virtual void TestPrefixQuery_Mem()
{
Directory directory = NewDirectory();
string[] categories = new string[] { "/Computers", "/Computers/Mac", "/Computers/Windows" };
RandomIndexWriter writer = new RandomIndexWriter(Random(), directory);
for (int i = 0; i < categories.Length; i++)
{
Document doc = new Document();
doc.Add(NewStringField("category", categories[i], Field.Store.YES));
writer.AddDocument(doc);
}
IndexReader reader = writer.Reader;
PrefixQuery query = new PrefixQuery(new Term("category", "/Computers"));
IndexSearcher searcher = NewSearcher(reader);
ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length, "All documents in /Computers category and below");
query = new PrefixQuery(new Term("category", "/Computers/Mac"));
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length, "One in /Computers/Mac");
query = new PrefixQuery(new Term("category", ""));
Terms terms = MultiFields.GetTerms(searcher.IndexReader, "category");
Assert.IsFalse(query.GetTermsEnum(terms) is PrefixTermsEnum);
hits = searcher.Search(query, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length, "everything");
writer.Dispose();
reader.Dispose();
directory.Dispose();
}
示例11: TestAfter
public virtual void TestAfter()
{
// create an index
Directory indexStore = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), indexStore);
long now = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
Document doc = new Document();
// add time that is in the future
doc.Add(NewStringField("datefield", DateTools.TimeToString(now + 888888, DateTools.Resolution.MILLISECOND), Field.Store.YES));
doc.Add(NewTextField("body", "Today is a very sunny day in New York City", Field.Store.YES));
writer.AddDocument(doc);
IndexReader reader = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(reader);
// filter that should preserve matches
// DateFilter df1 = DateFilter.After("datefield", now);
TermRangeFilter df1 = TermRangeFilter.NewStringRange("datefield", DateTools.TimeToString(now, DateTools.Resolution.MILLISECOND), DateTools.TimeToString(now + 999999, DateTools.Resolution.MILLISECOND), true, false);
// filter that should discard matches
// DateFilter df2 = DateFilter.After("datefield", now + 999999);
TermRangeFilter df2 = TermRangeFilter.NewStringRange("datefield", DateTools.TimeToString(now + 999999, DateTools.Resolution.MILLISECOND), DateTools.TimeToString(now + 999999999, DateTools.Resolution.MILLISECOND), false, true);
// search something that doesn't exist with DateFilter
Query query1 = new TermQuery(new Term("body", "NoMatchForthis"));
// search for something that does exists
Query query2 = new TermQuery(new Term("body", "sunny"));
ScoreDoc[] result;
// ensure that queries return expected results without DateFilter first
result = searcher.Search(query1, null, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query2, null, 1000).ScoreDocs;
Assert.AreEqual(1, result.Length);
// run queries with DateFilter
result = searcher.Search(query1, df1, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query1, df2, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
result = searcher.Search(query2, df1, 1000).ScoreDocs;
Assert.AreEqual(1, result.Length);
result = searcher.Search(query2, df2, 1000).ScoreDocs;
Assert.AreEqual(0, result.Length);
reader.Dispose();
indexStore.Dispose();
}
示例12: SetUp
public override void SetUp()
{
base.SetUp();
Directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), Directory);
Document doc = new Document();
doc.Add(NewTextField(FN, "the quick brown fox jumps over the lazy ??? dog 493432 49344", Field.Store.NO));
writer.AddDocument(doc);
Reader = writer.Reader;
writer.Dispose();
Searcher = NewSearcher(Reader);
}
示例13: TestBasic
public virtual void TestBasic()
{
Directory dir = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
Document doc = new Document();
doc.Add(NewTextField("field", "value", Field.Store.NO));
writer.AddDocument(doc);
IndexReader reader = writer.Reader;
writer.Dispose();
TermQuery termQuery = new TermQuery(new Term("field", "value"));
// should not throw exception with primitive query
QueryWrapperFilter qwf = new QueryWrapperFilter(termQuery);
IndexSearcher searcher = NewSearcher(reader);
TopDocs hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
Assert.AreEqual(1, hits.TotalHits);
hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
Assert.AreEqual(1, hits.TotalHits);
// should not throw exception with complex primitive query
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.Add(termQuery, Occur.MUST);
booleanQuery.Add(new TermQuery(new Term("field", "missing")), Occur.MUST_NOT);
qwf = new QueryWrapperFilter(termQuery);
hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
Assert.AreEqual(1, hits.TotalHits);
hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
Assert.AreEqual(1, hits.TotalHits);
// should not throw exception with non primitive Query (doesn't implement
// Query#createWeight)
qwf = new QueryWrapperFilter(new FuzzyQuery(new Term("field", "valu")));
hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
Assert.AreEqual(1, hits.TotalHits);
hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
Assert.AreEqual(1, hits.TotalHits);
// test a query with no hits
termQuery = new TermQuery(new Term("field", "not_exist"));
qwf = new QueryWrapperFilter(termQuery);
hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
Assert.AreEqual(0, hits.TotalHits);
hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
Assert.AreEqual(0, hits.TotalHits);
reader.Dispose();
dir.Dispose();
}
示例14: MakeIndex
internal virtual void MakeIndex()
{
// we use RAMDirectory here, because we dont want to stay on open files on Windows:
d = new RAMDirectory();
RandomIndexWriter w = new RandomIndexWriter(Random(), d);
Document doc = new Document();
doc.Add(newField("ints", "1", StringField.TYPE_NOT_STORED));
w.AddDocument(doc);
w.ForceMerge(1);
r = w.Reader;
w.Dispose();
SubR = (AtomicReader)(r.Leaves()[0]).Reader();
}
示例15: SetUp
public override void SetUp()
{
base.SetUp();
Analyzer = new MockAnalyzer(Random());
Dir = NewDirectory();
IndexWriterConfig config = NewIndexWriterConfig(TEST_VERSION_CURRENT, Analyzer);
config.SetMergePolicy(NewLogMergePolicy()); // we will use docids to validate
RandomIndexWriter writer = new RandomIndexWriter(Random(), Dir, config);
writer.AddDocument(Doc("lucene", "lucene is a very popular search engine library"));
writer.AddDocument(Doc("solr", "solr is a very popular search server and is using lucene"));
writer.AddDocument(Doc("nutch", "nutch is an internet search engine with web crawler and is using lucene and hadoop"));
Reader = writer.Reader;
writer.Dispose();
Searcher = NewSearcher(Reader);
}