IndexSearchContextを拡張して、Lucene.Net.Search.Sortオブジェクトを受け入れるメソッドを持つことができます。私のチームのメンバーの一人がこれを考え出し、それはかなりきれいです。
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);
}
}
フィルターの仕組みを理解しましたか? –
@Lavinski - はい、techphoria414のように、IndexSearchContextクラスを拡張し、必要なメソッドを公開しました。以下の回答をご覧ください。 – Sudeep