Pagination, sorting, crawling and storing data with Sitecore and Lucene
Please read full article from Pagination, sorting, crawling and storing data with Sitecore and Lucene
Sort simpleSort =
new
Sort(
new
SortField(
"__created"
, SortField.STRING));
Sort sortByAuthorThenByCreatedDateDesc =
new
Sort(
new
SortField[]
{
new
SortField(
"__created by"
, SortField.STRING),
new
SortField(
"__created"
, SortField.STRING,
true
)
}
);
ublic
List<Item> GetItems(Query query, Sort sort,
int
page,
int
itemsPerPage)
{
using
(IndexSearchContext sc =
SearchManager.GetIndex(
"Custom Index"
).CreateSearchContext())
{
TopDocs docs = sc.Searcher.Search(query,
null
, page * itemsPerPage, sort);
SearchHits searchHits =
new
SearchHits(docs, sc.Searcher.GetIndexReader());
return
searchHits
.FetchResults((page - 1) * itemsPerPage, itemsPerPage)
.Select(r => r.GetObject<Item>()).ToList();
}
}
List<Item> items = GetItems(query, sort, page, itemsPerPage);
Please read full article from Pagination, sorting, crawling and storing data with Sitecore and Lucene
No comments:
Post a Comment