本文整理汇总了C#中IndexWriter.numDocs方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.numDocs方法的具体用法?C# IndexWriter.numDocs怎么用?C# IndexWriter.numDocs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.numDocs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
// default AzureDirectory stores cache in local temp folder
CloudStorageAccount cloudStorageAccount;
CloudStorageAccount.TryParse(CloudConfigurationManager.GetSetting("blobStorage"), out cloudStorageAccount);
//AzureDirectory azureDirectory = new AzureDirectory(cloudStorageAccount, "TestTest", new RAMDirectory());
//AzureDirectory azureDirectory = new AzureDirectory(cloudStorageAccount, "TestTest", FSDirectory.Open(@"c:\test"));
var azureDirectory = new AzureDirectory(cloudStorageAccount, "TestTest" /* default is FSDirectory.Open(@"%temp%/AzureDirectory/TestTest"); */ );
IndexWriter indexWriter = null;
while (indexWriter == null)
{
try
{
var config = new IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_CURRENT, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
indexWriter = new IndexWriter(azureDirectory, config);
}
catch (LockObtainFailedException)
{
Console.WriteLine("Lock is taken, waiting for timeout...");
Thread.Sleep(1000);
}
}
Console.WriteLine("IndexWriter lock obtained, this process has exclusive write access to index");
//indexWriter.setRAMBufferSizeMB(10.0);
//indexWriter.SetUseCompoundFile(false);
//indexWriter.SetMaxMergeDocs(10000);
//indexWriter.SetMergeFactor(100);
for (int iDoc = 0; iDoc < 10000; iDoc++)
{
if (iDoc % 10 == 0)
Console.WriteLine(iDoc);
var doc = new Document();
doc.add(new TextField("id", DateTime.Now.ToFileTimeUtc().ToString(CultureInfo.InvariantCulture), Field.Store.YES));
doc.add(new TextField("Title", GeneratePhrase(10), Field.Store.YES));
doc.add(new TextField("Body", GeneratePhrase(40), Field.Store.YES));
indexWriter.addDocument(doc);
}
Console.WriteLine("Total docs is {0}", indexWriter.numDocs());
Console.Write("Flushing and disposing writer...");
// Potentially Expensive: this ensures that all writes are commited to blob storage
indexWriter.commit();
indexWriter.close();
Console.WriteLine("done");
Console.WriteLine("Hit Key to search again");
Console.ReadKey();
IndexSearcher searcher;
using (new AutoStopWatch("Creating searcher"))
{
searcher = new IndexSearcher(DirectoryReader.open(azureDirectory));
}
SearchForPhrase(searcher, "dog");
SearchForPhrase(searcher, Random.Next(32768).ToString(CultureInfo.InvariantCulture));
SearchForPhrase(searcher, Random.Next(32768).ToString(CultureInfo.InvariantCulture));
Console.WriteLine("Hit a key to dispose and exit");
Console.ReadKey();
}