Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class SearchIndexWithTags extends SolrSearchIndex
{
public function init()
{
$this->addFilterField('SiteTree_TagID');
parent::init();
}
public function getFieldDefinitions()
{
$xml = parent::getFieldDefinitions();
$xml .= "\n\t\t<field name='SiteTree_TagID' type='tint' indexed='true' stored='false' multiValued='true' />";
return $xml;
}
protected function _addAs($object, $base, $options)
{
$includeSubs = $options['include_children'];
$doc = new Apache_Solr_Document();
$doc->setField('_documentid', $this->getDocumentID($object, $base, $includeSubs));
$doc->setField('ID', $object->ID);
$doc->setField('ClassName', $object->ClassName);
foreach (SearchIntrospection::hierarchy(get_class($object), false) as $class) {
$doc->addField('ClassHierarchy', $class);
}
foreach ($this->getFieldsIterator() as $name => $field) {
if ($field['base'] == $base) {
$this->_addField($doc, $object, $field);
}
}
// add each of the tags on the page on
foreach($object->Tags() as $tag) {
$doc->addField('SiteTree_TagID', $tag->ID);
}
try {
$this->getService()->addDocument($doc);
} catch (Exception $e) {
SS_Log::log($e, SS_Log::WARN);
return false;
}
return $doc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.