public function testIndexRecord() { $mgr = new SolrSearch_Addon_Manager($this->db); $extable = $this->db->getTable('Exhibit'); foreach ($extable->findAll() as $ex) { $doc = $mgr->indexRecord($ex); $this->_testSolrDoc($ex, $doc, $ex->public); foreach ($ex->getPages() as $page) { $doc = $mgr->indexRecord($page); $this->_testSolrDoc($page, $doc, $ex->public); } } }
/** * This re-indexes everything in the Omeka DB. * * @return void * @author Eric Rochester **/ public static function indexAll($options = array()) { $solr = self::connect($options); $db = get_db(); $table = $db->getTable('Item'); $select = $table->getSelect(); // Removed in order to index both public and private items // $table->filterByPublic($select, true); $table->applySorting($select, 'id', 'ASC'); $excTable = $db->getTable('SolrSearchExclude'); $excludes = array(); foreach ($excTable->findAll() as $e) { $excludes[] = $e->collection_id; } if (!empty($excludes)) { $select->where('collection_id IS NULL OR collection_id NOT IN (?)', $excludes); } // First get the items. $pager = new SolrSearch_DbPager($db, $table, $select); while ($items = $pager->next()) { foreach ($items as $item) { $docs = array(); $doc = self::itemToDocument($item); $docs[] = $doc; $solr->addDocuments($docs); } $solr->commit(); } // Now the other addon stuff. $mgr = new SolrSearch_Addon_Manager($db); $docs = $mgr->reindexAddons(); $solr->addDocuments($docs); $solr->commit(); $solr->optimize(); }
/** * When a record is deleted, clear its Solr record. * * @param array $args With `record`. */ public function hookBeforeDeleteRecord($args) { $record = $args['record']; $mgr = new SolrSearch_Addon_Manager($this->_db); $id = $mgr->getId($record); if (!is_null($id)) { $solr = SolrSearch_Helpers_Index::connect(); try { $solr->deleteById($id); $solr->commit(); $solr->optimize(); } catch (Exception $e) { } } }
/** * Get the key used on Solr documents for a field on a given record. * * @param Omeka_Record_AbstractRecord $record The record. * @param string $field The field. * @return string */ protected function _getAddonKey($record, $field) { // Spin up a manager and indexer. $mgr = new SolrSearch_Addon_Manager($this->db); $idx = new SolrSearch_Addon_Indexer($this->db); $mgr->parseAll(); // Return the key used to store the field on the Solr document. return $idx->makeSolrName($mgr->findAddonForRecord($record), $field); }