如何正確的文件添加到搜索索引...Silverstripe Solr的搜索文件,網頁和數據對象
使用自定義索引我可以成功地搜索網頁和數據對象,但是當我試圖以包括文件這個索引,頁面從結果集中刪除,我只返回文件和數據對象。
這將按預期返回頁面和數據對象。
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'));
}
}
和一個基本的工作搜索功能
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();
}
進行以下小修改,以允許文件(僅變更爲簡潔起見所示)僅
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();
}
返回文件和數據對象。我在想$this->addAllFulltextFields();
現在只適用於文件嗎?