/** * Pull out all the fields that should be indexed for a particular object * * This mapping is done to make it easier to * * @param DataObject $dataObject * @return array */ protected function objectToFields($dataObject) { $ret = array(); $fields = Config::inst()->get($dataObject->ClassName, 'db'); $fields['Created'] = 'SS_Datetime'; $fields['LastEdited'] = 'SS_Datetime'; $ret['ClassName'] = array('Type' => 'Varchar', 'Value' => $dataObject->class); $ret['SS_ID'] = array('Type' => 'Int', 'Value' => $dataObject->ID); foreach ($fields as $name => $type) { if (preg_match('/^(\\w+)\\(/', $type, $match)) { $type = $match[1]; } // Just index everything; the query can figure out what to exclude... ! $value = $dataObject->{$name}; if ($type == 'MultiValueField' && $value instanceof MultiValueField) { $value = $value->getValues(); } $ret[$name] = array('Type' => $type, 'Value' => $value); } $rels = Config::inst()->get($dataObject->ClassName, 'has_one'); if ($rels) { foreach (array_keys($rels) as $rel) { $ret["{$rel}ID"] = array('Type' => 'ForeignKey', 'Value' => $dataObject->{$rel . "ID"}); } } if ($dataObject->hasMethod('additionalSolrValues')) { $extras = $dataObject->invokeWithExtensions('additionalSolrValues'); if ($extras && is_array($extras)) { foreach ($extras as $add) { foreach ($add as $k => $v) { $ret[$k] = array('Type' => $this->mapper->mapValueToType($k, $v), 'Value' => $v); } } } } return $ret; }