Reputation: 79
I've got an index that's being generated completely fine (can browse through Luke through all the items created). Did a query in Luke, and even managed to return results back - implemented in the below code in C# but not returns back. Is there anything glaring obvious that I'm missing.
totalResults = 0;
using (var context = ContentSearchManager.GetIndex("custom_search_index").CreateSearchContext())
{
var filterPredicate = PredicateBuilder.True<SearchItem>();
var termPredicate = PredicateBuilder.False<SearchItem>();
termPredicate = termPredicate
.Or(p => p.Name.Like(keyword, 0.75f)).Boost(2.0f)
.Or(p => p.Excerpt.Like(keyword))
.Or(p => p.SearchTags.Like(keyword))
.Or(p => p.HtmlContent.Like(keyword));
var predicate = filterPredicate.And(termPredicate);
var query = context.GetQueryable<SearchItem>().Where(predicate);
var results = query.Page(page, itemsPerPage).GetResults();
totalResults = results.TotalSearchResults;
var result = results.Hits.Select(h => GetPage(h.Document)).ToArray();
return result;
}
in Search.Log i'm getting the following hit
ExecuteQueryAgainstLucene (custom_search_index): _name:1980s~0.75 excerpt:1980s searchtags:1980s htmlcontent:1980s - Filter :
If i run '_name:1980s~0.75 excerpt:1980s searchtags:1980s htmlcontent:1980s' in Luke I do get a result back!
Upvotes: 1
Views: 872
Reputation: 1170
From the other comments it seems like you are using page = 1
to get the first page of results.
But the page
parameter is zero-based, meaning if you want the first page you have to use 0.
// This will return the first 5 results (page 1)
query.Page(0, 5).GetResults();
// This will return the next 5 results (page 2)
query.Page(1, 5).GetResults();
This can be verified by looking at the code for the Page(..)
extension method:
return Queryable.Take<TSource>(Queryable.Skip<TSource>(source, page * pageSize), pageSize);
Upvotes: 1
Reputation: 79
So if i use the following code:
var results = query.Page(page, itemsPerPage).GetResults();
where page is 1 and itemsPerPage is 5, but my filtered results returns only one value (or less then itemsPerPage) GetResults() returns no results!
Upvotes: 0
Reputation: 422
Most of the time, this indicates that the index is out-of-date. For instance, the items the results point to have been deleted or haven't been published yet. Rebuilding the index should result in having Luke and Sitecore return the same.
Also, check if your paging doesn't exclude results. Maybe try it first without paging.
Upvotes: 1