public function addResource($resource) { if (!is_array($resource)) { return false; } $fields = array('id' => $resource['Resource']['id'], 'sha' => $resource['Resource']['sha'], 'user' => $resource['User']['name'], 'filetype' => $resource['Resource']['mime_type'], 'filename' => $resource['Resource']['file_name'], 'type' => $resource['Resource']['type'], 'title' => $resource['Resource']['title'], 'public' => $resource['Resource']['public'], 'modified' => $this->_formatDate($resource['Resource']['modified']), 'created' => $this->_formatDate($resource['Resource']['created']), 'comment' => \_\pluck($resource['Comment'], 'content'), 'annotation' => \_\pluck($resource['Annotation'], 'caption'), 'keyword' => \_\pluck($resource['Keyword'], 'keyword'), 'collection' => $resource['Collection'] ?: array()); $document = new \Apache_Solr_Document(); foreach ($fields as $key => $val) { if (is_array($val)) { foreach ($val as $subval) { $document->addField($key, $subval); } } else { $document->{$key} = $val; } } foreach ($resource['Metadatum'] as $m) { $document->addField($m['attribute'] . '_t', $m['value']); } $this->solr->addDocument($document); $this->solr->commit(); $this->solr->optimize(); }
/** * Run the query and return a completion array for a category. * * @return array completion values */ public function complete($category, $query = null, $options = array()) { if (is_array($query)) { $this->addFacets($query); } $map = $this->mappings[$category]; $sql = $this->buildCompleteStatement($category, $options); $rows = $this->execute($sql, $this->values); return array_unique(array_values(array_filter(\_\pluck($rows, $map['field'])))); }