How to correctly add files to the search index...
Using a custom index I can sucessfully search pages and dataobjects, however as soon as I attempt to include files in this index, pages drops off from the result set and I only get file and dataobjects returned.
This will return pages and dataobjects as expected.
class EntrySearchIndex extends SolrSearchIndex
{
public function init()
{
$this->addClass('SiteTree');
$this->addClass('EntryAccordionItem');
$this->addClass('EntryInformationBoxItem');
$this->addClass('EntryTabItem');
$this->addAllFulltextFields();
$this->addFilterField('ShowInSearch');
$this->excludeVariantState(array('SearchVariantVersioned' => 'Stage'));
}
}
and a basic working search function
public static function keywordSearch($keywords)
{
$keywords = Convert::raw2sql(trim($keywords));
$classes[] = array('class' => 'EntryPage', 'includeSubclasses' => true);
$classes[] = array('class' => 'EntryAccordionItem');
$classes[] = array('class' => 'EntryInformationBoxItem');
$classes[] = array('class' => 'EntryTabItem');
$index = singleton('EntrySearchIndex');
$engine = SearchQuery::create();
return $engine->search($keywords, $classes, $index, -1, 0)->getResults();
}
Making the following minor modifications to allow for files (only alterations shown for brevity)
public function init()
{
$this->addClass('SiteTree');
$this->addClass('EntryAccordionItem');
$this->addClass('EntryInformationBoxItem');
$this->addClass('EntryTabItem');
// File specific
$this->addClass('File');
$this->addFulltextField('FileContent');
$this->addAllFulltextFields();
$this->addFilterField('ShowInSearch');
$this->excludeVariantState(array('SearchVariantVersioned' => 'Stage'));
}
public static function keywordSearch($keywords)
{
[...]
// File specific
$classes[] = array('class' => 'File', 'includeSubclasses' => true);
[...]
return $engine->search($keywords, $classes, $index, -1, 0)->getResults();
}
Returns only files and dataobjects. Am I right in thinking $this->addAllFulltextFields();
is now only being applied to Files?