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


C# Index.CreateDeleteContext方法代码示例

本文整理汇总了C#中Index.CreateDeleteContext方法的典型用法代码示例。如果您正苦于以下问题:C# Index.CreateDeleteContext方法的具体用法?C# Index.CreateDeleteContext怎么用?C# Index.CreateDeleteContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Index的用法示例。


在下文中一共展示了Index.CreateDeleteContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PruneResults

        private static void PruneResults(Index index, IDictionary<ItemUri, bool> crawledItems, bool fullCrawl)
        {
            IPruner pruner;
            if (fullCrawl)
            {
                pruner = new DictionaryPruner(crawledItems);
            }
            else
            {
                pruner = new SitecorePruner();
            }

            IndexSearchContext searchContext = index.CreateSearchContext();
            IndexReader reader = searchContext.Searcher.Reader;

            List<int> itemsToDelete = new List<int>();

            try
            {
                // first get how many documents are in the index
                int numberOfDocuments = reader.NumDocs();

                // interate over all of the documents
                for (int i = 0; i < numberOfDocuments; i++)
                {
                    // check to see if the document is deleted
                    if (reader.IsDeleted(i))
                    {
                        continue;
                    }

                    // get the actual document from the index
                    Document doc = reader.Document(i);

                    // get the url field from the index which contains item id, version, database, etc.
                    Field field = doc.GetField(BuiltinFields.Url);
                    string path = field.StringValue();

                    // parse out the values from the index
                    ItemUri uri = new ItemUri(path);

                    if (!pruner.StillExists(uri))
                    {
                        itemsToDelete.Add(i);
                    }
                }
            }
            finally
            {
                // clean up after ourselves
                reader.Close();
                searchContext.Searcher.Close();

                if (itemsToDelete.Any())
                {
                    using (IndexDeleteContext context = index.CreateDeleteContext())
                    {
                        context.DeleteDocuments(itemsToDelete);
                        context.Commit();
                    }
                }
            }
        }
开发者ID:Velir,项目名称:Sitecore-Lucene-Refresher,代码行数:63,代码来源:TreeRefresher.cs


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