当前位置: 首页>>代码示例>>C#>>正文


C# Directory.ClearLock方法代码示例

本文整理汇总了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);
                            }
                        }
//.........这里部分代码省略.........
开发者ID:remiolivier,项目名称:Openturf,代码行数:101,代码来源:WorkerRole.cs


注:本文中的Lucene.Net.Store.Directory.ClearLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。