Reputation: 491
I have upgraded to Sitecore 7.1
in my dev environment and refactoring some areas in the application that were getting items, trying to use the new ContentSearchManager
. Through code or through LinqPad
I am getting no results but when debugging with Luke the index does have items.
Test code that doesn't return anything:
var index = ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = index.CreateSearchContext())
{
context.GetQueryable<SearchResultItem>().Where (item => item.Name == "Home");
}
Can someone tell me the best way to debug and get this wired up?
Upvotes: 0
Views: 1810
Reputation: 1262
Your code seems incomplete. I would expect to see something along the lines of the following:
public IEnumerable<Item> GetItems()
{
var index = ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = index.CreateSearchContext())
{
IQueryable<SearchResultItem> query = context.GetQueryable<SearchResultItem>().Where (item => item.Name == "Home");
SearchResults<SearchResultItem> results = query.GetResults();
return results.Hits.Select(hit => hit.Document.GetItem());
}
}
If that is unsuccessful, you should be able to see the raw Lucene query when debugging the query
object in Visual Studio. I would recommend validating that query matches the query you have been running in Luke. It's possible the API is applying additional filter expressions to your query.
Upvotes: 2