本文整理汇总了C#中Index.CreateSearchContext方法的典型用法代码示例。如果您正苦于以下问题:C# Index.CreateSearchContext方法的具体用法?C# Index.CreateSearchContext怎么用?C# Index.CreateSearchContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Index
的用法示例。
在下文中一共展示了Index.CreateSearchContext方法的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();
}
}
}
}