Sitecore 8 lucene indexing pdf content

Hi, recently I had to create a page that needed to search pdf files on Sitecore.

The scenario was on Sitecore 8 using Lucene search

I found a good explanation that enabled me to almost achieve my goal on the link below

Ryan Bailey Development

The only missing piece was a function that would perform the search . The trick was showed on Ryan Bailey, is the field item["_content"]


public List SearchFile(string contentText)
{
Item rootSitecoreItem = GetRootItem();
ISearchIndex index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(rootSitecoreItem));


string folderName = Sitecore.Context.Database.GetItem("{2418AF15-F0A1-4C0E-B103-5C1C67AC82C7}", Sitecore.Context.Language).Name
using (IProviderSearchContext context = index.CreateSearchContext())
{
var results =
context.GetQueryable(
new CultureExecutionContext(Sitecore.Context.Language.CultureInfo)).
Where(item => item["_content"] == contentText
&& item.Path.Contains(folderName)
&& item.Language == Sitecore.Context.Language.Name)
.GetResults()
.ToList()
.Select(i => i.Document.GetItem()).ToList().Where(f => f != null && f.TemplateID.ToString() != FolderTemplate).ToList();


return results.ToList();
}
}