/** * Builder method for returning a Zend_Search_Lucene_Field object based on * the DataObject field. * * If the SilverStripe database field is a Date or a descendant of Date, * stores the date as a Unix timestamp. Make sure your timezone is set * correctly! * * Keyword - Data that is searchable and stored in the index, but not * broken up into tokens for indexing. This is useful for being * able to search on non-textual data such as IDs or URLs. * * UnIndexed – Data that isn’t available for searching, but is stored * with our document (eg. article teaser, article URL and timestamp * of creation) * * UnStored – Data that is available for search, but isn’t stored in * the index in full (eg. the document content) * * Text – Data that is available for search and is stored in full * (eg. title and author) * * @access private * @param DataObject $object The DataObject from which to extract a * Zend field. * @param String $fieldName The name of the field to fetch a Zend field for. * @return Zend_Search_Lucene_Field */ private static function getZendField($object, $fieldName) { $encoding = ZendSearchLuceneSearchable::$encoding; $config = $object->getLuceneFieldConfig($fieldName); // Recurses through dot-notation. $value = self::getFieldValue($object, $fieldName); if ($config['content_filter']) { // Run through the content filter, if we have one. $value = call_user_func($config['content_filter'], $value); } if ($config['name']) { $fieldName = $config['name']; } if ($config['type'] == 'text') { return Zend_Search_Lucene_Field::Text($fieldName, $value, $encoding); } if ($config['type'] == 'unindexed') { return Zend_Search_Lucene_Field::UnIndexed($fieldName, $value, $encoding); } if ($config['type'] == 'keyword') { $keywordFieldName = $fieldName; if ($keywordFieldName == 'ID') { $keywordFieldName = 'ObjectID'; } // Don't use 'ID' as it's used by Zend Lucene return Zend_Search_Lucene_Field::Keyword($keywordFieldName, $value, $encoding); } // Default - index and store as unstored return Zend_Search_Lucene_Field::UnStored($fieldName, $value, $encoding); }