本文整理汇总了C#中Lucene.Net.Index.IndexWriter.AddDocuments方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.AddDocuments方法的具体用法?C# IndexWriter.AddDocuments怎么用?C# IndexWriter.AddDocuments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.AddDocuments方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEmptyChildFilter
public void TestEmptyChildFilter()
{
Directory dir = NewDirectory();
IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
config.SetMergePolicy(NoMergePolicy.NO_COMPOUND_FILES);
// we don't want to merge - since we rely on certain segment setup
IndexWriter w = new IndexWriter(dir, config);
IList<Document> docs = new List<Document>();
docs.Add(MakeJob("java", 2007));
docs.Add(MakeJob("python", 2010));
docs.Add(MakeResume("Lisa", "United Kingdom"));
w.AddDocuments(docs);
docs.Clear();
docs.Add(MakeJob("ruby", 2005));
docs.Add(MakeJob("java", 2006));
docs.Add(MakeResume("Frank", "United States"));
w.AddDocuments(docs);
w.Commit();
int num = AtLeast(10); // produce a segment that doesn't have a value in the docType field
for (int i = 0; i < num; i++)
{
docs.Clear();
docs.Add(MakeJob("java", 2007));
w.AddDocuments(docs);
}
IndexReader r = DirectoryReader.Open(w, Random().NextBoolean());
w.Dispose();
assertTrue(r.Leaves.size() > 1);
IndexSearcher s = new IndexSearcher(r);
Filter parentsFilter = new FixedBitSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("docType", "resume"))));
BooleanQuery childQuery = new BooleanQuery();
childQuery.Add(new BooleanClause(new TermQuery(new Term("skill", "java")), BooleanClause.Occur.MUST));
childQuery.Add(new BooleanClause(NumericRangeQuery.NewIntRange("year", 2006, 2011, true, true), BooleanClause.Occur.MUST));
ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
BooleanQuery fullQuery = new BooleanQuery();
fullQuery.Add(new BooleanClause(childJoinQuery, BooleanClause.Occur.MUST));
fullQuery.Add(new BooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.MUST));
ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(Sort.RELEVANCE, 1, true, true);
s.Search(fullQuery, c);
TopGroups<int> results = c.GetTopGroups(childJoinQuery, null, 0, 10, 0, true);
assertFalse(float.IsNaN(results.MaxScore));
assertEquals(1, results.TotalGroupedHitCount);
assertEquals(1, results.Groups.Length);
IGroupDocs<int> group = results.Groups[0];
Document childDoc = s.Doc(group.ScoreDocs[0].Doc);
assertEquals("java", childDoc.Get("skill"));
assertNotNull(group.GroupValue);
Document parentDoc = s.Doc(group.GroupValue);
assertEquals("Lisa", parentDoc.Get("name"));
r.Dispose();
dir.Dispose();
}
示例2: SetUp
public override void SetUp()
{
Directory = NewDirectory();
IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter indexWriter = new IndexWriter(Directory, config);
for (int i = 0; i < AMOUNT_OF_SEGMENTS; i++)
{
IList<Document> segmentDocs = CreateDocsForSegment(i);
indexWriter.AddDocuments(segmentDocs);
indexWriter.Commit();
}
IndexReader = DirectoryReader.Open(indexWriter, Random().NextBoolean());
indexWriter.Dispose();
IndexSearcher = new IndexSearcher(IndexReader);
ParentsFilter = new FixedBitSetCachingWrapperFilter(new QueryWrapperFilter(new WildcardQuery(new Term("parent", "*"))));
}
示例3: IndexDocuments
internal static void IndexDocuments(string path, List<IndexOperation> batch)
{
var uniques = new Dictionary<string, Document>();
var deletes = new List<Term>();
var writes = new List<LDocument>();
for (var i = batch.Count - 1; i >= 0; i--)
{
var op = batch[i];
var doc = batch[i].Document;
var schema = doc.Schema;
var uniqueFields = doc.GetUniqueFields(schema);
bool indexDoc = op.Type == IndexOperationType.Save;
foreach (var field in uniqueFields)
{
var sig = field.GetSignature(schema);
if (uniques.ContainsKey(sig))
{
indexDoc = false;
break;
}
}
if (indexDoc)
{
foreach (var field in uniqueFields)
{
uniques.Add(field.GetSignature(schema), doc);
var t = new Term(field.Name, field.GetValue());
deletes.Add(t);
}
writes.Add(Convert(doc, schema));
}
}
var wrtr = new IndexWriter(path, new StandardAnalyzer());
wrtr.DeleteDocuments(deletes.ToArray());
wrtr.AddDocuments(writes.ToArray());
if (deletes.Count + writes.Count > 99)
{
wrtr.Optimize();
}
wrtr.Close();
}