本文整理汇总了C#中Lucene.Net.Store.Directory.ClearLock方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.ClearLock方法的具体用法?C# Directory.ClearLock怎么用?C# Directory.ClearLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.Directory
的用法示例。
在下文中一共展示了Directory.ClearLock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run()
{
Trace.WriteLine(DateTime.Now.ToString() + " [INIT]");
// Create azure account credentials
CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
{
configSetter(CloudSettingsResolver.GetConfigSetting(configName));
});
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.FromConfigurationSetting("BlobStorageEndpoint");
// Create reference to index queue
CloudQueueClient client = cloudStorageAccount.CreateCloudQueueClient();
CloudQueue queue = client.GetQueueReference("searchindexqueue");
queue.CreateIfNotExist();
queue.Clear();
// Create lucene index writer and optimize index (only on startup)
_Directory = new AzureDirectory(cloudStorageAccount, "LuceneStorage", new RAMDirectory());
while (true)
{
try
{
int queueItems = queue.RetrieveApproximateMessageCount();
Trace.WriteLine(DateTime.Now.ToString() + " [QUEUE_CHECK] " + queueItems + " items.");
if (queueItems > 0)
{
// Get index writer
if (IndexWriter.IsLocked(_Directory)) _Directory.ClearLock("write.lock");
IndexWriter indexWriter = new IndexWriter(_Directory, new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), false, new IndexWriter.MaxFieldLength(1000));
indexWriter.SetRAMBufferSizeMB(10.0);
indexWriter.SetUseCompoundFile(false);
indexWriter.SetMaxMergeDocs(10000);
indexWriter.SetMergeFactor(100);
try
{
// Get dictionary to skip duplicated queue items
Dictionary<long, DateTime> updatedSummaries = new Dictionary<long, DateTime>();
// Retrieve batch of messages to iterate
var msgs = queue.GetMessages(32);
while (msgs.Count() > 0)
{
foreach (var msg in msgs)
{
Trace.WriteLine(DateTime.Now.ToString() + " [MSG] " + msg.AsString);
long summaryId = long.Parse(msg.AsString);
// zero = re-index the search index
// positive number = add/update PointDataSummary to index
// negative number = delete PointDataSummary from index
if (summaryId == 0)
{
Trace.WriteLine(DateTime.Now.ToString() + " [REINDEX]");
indexWriter.Close();
indexWriter = new IndexWriter(_Directory, new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, new IndexWriter.MaxFieldLength(1000));
indexWriter.SetRAMBufferSizeMB(10.0);
indexWriter.SetUseCompoundFile(false);
indexWriter.SetMaxMergeDocs(10000);
indexWriter.SetMergeFactor(100);
List<PointDataSummary> summaries = PointDataSummary.All().ToList();
updatedSummaries = new Dictionary<long, DateTime>();
foreach (var summary in summaries)
{
Index(indexWriter, summary);
Trace.WriteLine(DateTime.Now.ToString() + " [INDEX] " + summary.Id);
updatedSummaries.Add(summaryId, DateTime.UtcNow);
}
}
else if (updatedSummaries.ContainsKey(summaryId) && ((DateTime)updatedSummaries[summaryId]) >= msg.InsertionTime)
{
Trace.WriteLine(DateTime.Now.ToString() + " [SKIPPED] " + msg.AsString);
}
else
{
if (summaryId < 0)
{
indexWriter.DeleteDocuments(new Lucene.Net.Index.Term("point_id", (-summaryId).ToString()));
}
else
{
var summary = PointDataSummary.SingleOrDefault(p => p.Id == summaryId);
if (summary != null)
{
Index(indexWriter, summary);
Trace.WriteLine(DateTime.Now.ToString() + " [INDEX] " + summary.Id);
}
}
updatedSummaries.Remove(summaryId);
updatedSummaries.Add(summaryId, DateTime.UtcNow);
}
// Delete message from queue
queue.DeleteMessage(msg);
}
// Retrieve batch of messages to iterate
msgs = queue.GetMessages(32);
}
}
//.........这里部分代码省略.........