Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow addons to get metadata, and create addon for collections. #141

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions addons/collections.json
Original file line number Diff line number Diff line change
@@ -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"]
}
]
}
}
2 changes: 2 additions & 0 deletions lib/SolrSearch/Addon/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion lib/SolrSearch/Addon/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
26 changes: 23 additions & 3 deletions lib/SolrSearch/Addon/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <erochest@virginia.edu>
**/
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.
Expand Down