diff --git a/addons/collections.json b/addons/collections.json new file mode 100644 index 00000000..5fe3a532 --- /dev/null +++ b/addons/collections.json @@ -0,0 +1,25 @@ +{ + "collections": { + "table" : "Collection", + "result_type" : "Collection", + "tagged" : false, + "flag" : "public", + + "fields": [ + { + "field" : "title", + "label" : "Title", + "facet" : false, + "is_title" : true, + "metadata" : ["Dublin Core", "Title"] + }, + { + "field" : "description", + "label" : "Description", + "facet" : false, + "is_title" : false, + "metadata" : ["Dublin Core", "Description"] + } + ] + } +} diff --git a/lib/SolrSearch/Addon/Config.php b/lib/SolrSearch/Addon/Config.php index 73f90c6d..3eabc0db 100644 --- a/lib/SolrSearch/Addon/Config.php +++ b/lib/SolrSearch/Addon/Config.php @@ -195,12 +195,14 @@ private function parseField($json) $field->is_facet = array_key_exists('facet', $json) ? $json['facet'] : false; $field->is_title = array_key_exists('is_title', $json) ? $json['is_title'] : false; $field->remote = array_key_exists('remote', $json) ? (object) $json['remote'] : null; + $field->metadata = array_key_exists('metadata', $json) ? (array) $json['metadata'] : null; } else { $field->name = $json; $field->label = $json; $field->is_facet = false; $field->is_title = false; $field->remote = null; + $field->metadata = null; } return $field; diff --git a/lib/SolrSearch/Addon/Field.php b/lib/SolrSearch/Addon/Field.php index d5dea5cc..b3d219c7 100644 --- a/lib/SolrSearch/Addon/Field.php +++ b/lib/SolrSearch/Addon/Field.php @@ -51,15 +51,25 @@ class SolrSearch_Addon_Field **/ var $remote; + /** + * This is an array containing the set and name to a metadata item for + * the data in this field. + * + * @var array|null + **/ + var $metadata; + function __construct( - $name=null, $label=null, $is_facet=null, $is_title=null, $remote=null + $name=null, $label=null, $is_facet=null, $is_title=null, $remote=null, + $metadata=null ) { $this->name = $name; $this->label = $label; $this->is_facet = $is_facet; $this->is_title = $is_title; $this->remote = $remote; + $this->metadata = $metadata; } diff --git a/lib/SolrSearch/Addon/Indexer.php b/lib/SolrSearch/Addon/Indexer.php index 67ad8015..e4c96b8a 100644 --- a/lib/SolrSearch/Addon/Indexer.php +++ b/lib/SolrSearch/Addon/Indexer.php @@ -142,10 +142,12 @@ public function indexRecord($record, $addon) foreach ($addon->fields as $field) { $solrName = $this->makeSolrName($addon, $field->name); - if (is_null($field->remote)) { - $value = $this->getLocalValue($record, $field); - } else { + if (!is_null($field->remote)) { $value = $this->getRemoteValue($record, $field); + } else if (!is_null($field->metadata)) { + $value = $this->getMetadataValue($record, $field); + } else { + $value = $this->getLocalValue($record, $field); } foreach ($value as $v) { @@ -219,6 +221,24 @@ protected function getRemoteValue($record, $field) } + /** + * This returns a value that is metadata to the record. + * + * @param Omeka_Record $record The record to get the value from. + * @param SolrSearch_Addon_Field $field The field that defines where to get + * the value. + * + * @return mixed $value The value of the field in the record. + * @author Eric Rochester + **/ + protected function getMetadataValue($record, $field) + { + $value = metadata($record, $field->metadata, 'all'); + + return $value; + } + + /** * This builds a query for returning all the records to index from the * database.