This is just a simple post, showing how to do a search against an index using the new Sitecore.ContentSearch API. This is so simple that I just wanted to write a little blog on it. In the old days, we really had some challenges getting stuff from the index, but this is so simple!

using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext())
            {
                // get all items in medialibrary
                var query = context.GetQueryable<SearchResultItem>().Where(i => i.Path.StartsWith("/sitecore/media library"));
                return query.ToList();
            }

The above code will return all items in the media library, as SearchResultItem. SearchResultItem contains some default properties like ID, path, name and parent, but you can always get the actual item by calling GetItem(). It doesn´t get more simple than that. LINQ to Sitecore(Provider) does the magic. In a future blog post, I will try to do a little deep dive in the searching API