本文整理汇总了C#中IndexSearcher.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IndexSearcher.Dispose方法的具体用法?C# IndexSearcher.Dispose怎么用?C# IndexSearcher.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexSearcher
的用法示例。
在下文中一共展示了IndexSearcher.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
/// <summary>
/// Searches the datasource using the specified criteria. Criteria is parsed by the query builder specified by
/// <typeparamref
/// name="QueryBuilderType" />
/// .
/// </summary>
/// <param name="scope">Name of the application.</param>
/// <param name="criteria">The criteria.</param>
/// <returns></returns>
/// <exception cref="VirtoCommerce.Search.Providers.Lucene.LuceneSearchException"></exception>
public virtual ISearchResults Search(string scope, ISearchCriteria criteria)
{
TopDocs docs = null;
var folderName = this.GetFolderName(scope, criteria.DocumentType);
var dir = FSDirectory.Open(new DirectoryInfo(this.GetDirectoryPath(folderName)));
var searcher = new IndexSearcher(dir);
var q = (Query)this.QueryBuilder.BuildQuery(criteria);
Debug.WriteLine("Search Lucene Query:{0}", (object)q.ToString());
try
{
var numDocs = criteria.StartingRecord + criteria.RecordsToRetrieve;
if (criteria.Sort != null)
{
var fields = criteria.Sort.GetSort();
docs = searcher.Search(
q,
null,
numDocs,
new Sort(
fields.Select(field => new SortField(field.FieldName, field.DataType, field.IsDescending))
.ToArray()));
}
else
{
docs = searcher.Search(q, numDocs);
}
}
catch (Exception ex)
{
throw new LuceneSearchException("Search exception", ex);
}
var results = new LuceneSearchResults(searcher, searcher.IndexReader, docs, criteria, q);
// Cleanup here
searcher.IndexReader.Dispose();
searcher.Dispose();
return results.Results;
}