コード例 #1
0
 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);
         }
     }
 }
コード例 #2
0
 /**
  * When a record is saved, try to extract and index a Solr document.
  *
  * @param array $args With `record`.
  */
 public function hookAfterSaveRecord($args)
 {
     SolrSearch_Utils::ensureView();
     $record = $args['record'];
     $excludes = get_db()->getTable('SolrSearchExclude');
     $collection = get_collection_for_item($record);
     if (!is_null($collection) && $excludes->isExcluded($collection)) {
         return;
     }
     // Try to extract a document for the record.
     $mgr = new SolrSearch_Addon_Manager($this->_db);
     $doc = $mgr->indexRecord($record);
     // Does the record have an add-on profile?
     if ($addon = $mgr->findAddonForRecord($record)) {
         // Connect to Solr.
         $solr = SolrSearch_Helpers_Index::connect();
         // If the record yields a Solr document, index it.
         if (!is_null($doc)) {
             $solr->addDocuments(array($doc));
             $solr->commit();
             $solr->optimize();
         } else {
             try {
                 $solr->deleteById($mgr->getId($record));
                 $solr->commit();
                 $solr->optimize();
             } catch (Exception $e) {
             }
         }
     }
     // Reindex related records.
     $mgr->resaveRemoteParent($record);
     $mgr->resaveChildren($record);
 }