/** * Method for adding an object from the database into the index. * * @param DataObject * @param string * @param array */ protected function _addAs($object, $base, $options) { $includeSubs = $options['include_children']; $doc = new Apache_Solr_Document(); // Always present fields $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); } // Add the user-specified fields foreach ($this->getFieldsIterator() as $name => $field) { if ($field['base'] == $base) { $this->_addField($doc, $object, $field); } } // CUSTOM Duplicate index combined fields ("Title" rather than // "SiteTree_Title"). // // This allows us to sort on these fields without deeper architectural // changes to the fulltextsearch module. Note: We can't use <copyField> // for this purpose because it only writes into multiValue=true // fields, and those can't be (reliably) sorted on. $this->_addField($doc, $object, $this->getCustomPropertyFieldData('Title', $object)); $this->_addField($doc, $object, $this->getCustomPropertyFieldData('LastEdited', $object, 'SSDatetime')); $this->getService()->addDocument($doc); return $doc; }
/** * Add all database-backed text fields as fulltext searchable fields. * * For every class included in the index, examines those classes and all subclasses looking for "Text" database * fields (Varchar, Text, HTMLText, etc) and adds them all as fulltext searchable fields. */ public function addAllFulltextFields($includeSubclasses = true) { foreach ($this->getClasses() as $class => $options) { foreach (SearchIntrospection::hierarchy($class, $includeSubclasses, true) as $dataclass) { $fields = DataObject::database_fields($dataclass); foreach ($fields as $field => $type) { if (preg_match('/^(\\w+)\\(/', $type, $match)) { $type = $match[1]; } if (is_subclass_of($type, 'StringField')) { $this->addFulltextField($field); } } } } }
protected function _addAs($object, $base, $options) { $includeSubs = $options['include_children']; $doc = new Apache_Solr_Document(); // Always present fields $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); } // Add the user-specified fields foreach ($this->getFieldsIterator() as $name => $field) { if ($field['base'] == $base) { $this->_addField($doc, $object, $field); } } try { $this->getService()->addDocument($doc); } catch (Exception $e) { SS_Log::log($e, SS_Log::WARN); return false; } return $doc; }