开发者

How to sort/filter using the new Sitecore.Search API

I couldn't find any way to do sort and filter us开发者_开发百科ing the new Sitecore.Search API. Lucene provides the following methods:

Search(Query query, Filter filter)
Search(Query query, Sort sort)
Search(Query query, Filter filter, Sort sort)

But I don't think Sitecore.Search API exposes these features. Am I missing something? Can someone please explain how to perform Filter and Sort with the new Sitecore.Search API? Or do I need to use the wrapped Searcher.Search(Query, Sort) to achieve this?

I am using Sitecore 6.5.

Thanks.


You can extend IndexSearchContext to have methods that accept a Lucene.Net.Search.Sort object. One of my team members figured this out and it's pretty clean.

public class SortableIndexSearchContext : IndexSearchContext 
{ 
public SortableIndexSearchContext(ILuceneIndex index) 
{ 
Initialize(index, true); 
} 
public SearchHits Search(Query query, Sort sort) 
{ 
return Search(query, SearchContext.Empty, sort); 
} 
public SearchHits Search(PreparedQuery query, Sort sort) 
{ 
return new SearchHits(Searcher.Search(query.Query, sort)); 
} 
public SearchHits Search(QueryBase query, Sort sort) 
{ 
return Search(query, SearchContext.Empty, sort); 
} 
public SearchHits Search(string query, Sort sort) 
{ 
return Search(query, SearchContext.Empty, sort); 
} 
public SearchHits Search(Query query, ISearchContext context, Sort sort) 
{ 
return Search(Prepare(query, context), sort); 
} 
public SearchHits Search(QueryBase query, ISearchContext context, Sort sort) 
{ 
return this.Search(Prepare(Translate(query), context), sort); 
} 
public SearchHits Search(string query, ISearchContext context, Sort sort) 
{ 
return this.Search(Parse(query, context), sort); 
} 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜