Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top