I am using Sitecore 7.5 and SOLR 4.7 and I am noticing that the TotalSearchResults
property seems to ignore item security.
I perform a search, skip to the proper page and only take the amount needed for the page and the TotalSearchResults
value is 31
. However the Results
themselves are zero (which is correct).
In my Sitecore implementation there are 31 matches for the search, but all of them are restricted by security and should not be accessible by the anonymous user. Is this right? I feel like I am missing something.
public static SearchResults<myCustomSearchResultItem> SearchContent(string searchTerm, int currentPage, int pageSize, string indexName) {
using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext(SearchSecurityOptions.EnableSecurityCheck)) {
var query = context.GetQueryable<GeneralSearchResultItem>()
.Where(x.Language == Sitecore.Context.Language.Name);
query = query.Where(i => (i.Content.Contains(searchTerm) || i.Name.Contains(searchTerm)));
//Paging
if (currentPage > 1) {
query = query.Skip((currentPage - 1) * pageSize);
}
query = query.Take(pageSize);
return query.GetResults();
}
}
When I run the above code I get the following:
myResults.TotalSearchResults = 31
myResults.Count() = 0
The correct results should be zero items returned because all of the items are security restricted. So myResults.Count() = 0
is correct. However the TotalSearchResults = 31
is wrong.
Does TotalSearchResults
ignore Sitecore security?