protected function myAddSearchText($item, $enrichedSearchTexts)
 {
     // http://omeka.org/forums/topic/adding-item-search-text-from-a-plugin
     //look up the existing search text
     $searchText = $this->_db->getTable('SearchText')->findByRecord('Item', $item->id);
     // searchText should already exist, but if something goes wrong, create it
     if (!$searchText) {
         $searchText = new SearchText();
         $searchText->record_type = 'Item';
         $searchText->record_id = $item->id;
         $searchText->public = $item->public;
         $searchText->title = metadata($item, array('Dublin Core', 'Title'));
     }
     $searchText->text .= ' ' . $enrichedSearchTexts;
     $searchText->save();
 }
Example #2
0
 /**
  * Save a search text row.
  * 
  * Call this statically only when necessary. Used primarily when in a record 
  * that does not implement Mixin_Search but contains text that is needed for 
  * another record's search text. For example, when saving a child record 
  * that contains search text that should be saved to its parent record.
  * 
  * @param string $recordType
  * @param int $recordId
  * @param string $text
  * @param string $title
  * @param int $public
  */
 public static function saveSearchText($recordType, $recordId, $text, $title, $public = 1)
 {
     // Index this record only if it's of a type that is registered in the
     // search_record_types filter.
     if (!array_key_exists($recordType, get_search_record_types())) {
         return;
     }
     $searchText = Zend_Registry::get('bootstrap')->getResource('Db')->getTable('SearchText')->findByRecord($recordType, $recordId);
     // Either don't save the search text or delete an existing search text
     // row if the record has no assigned text.
     if (!trim($text)) {
         if ($searchText) {
             $searchText->delete();
         }
         return;
     }
     if (!$searchText) {
         $searchText = new SearchText();
         $searchText->record_type = $recordType;
         $searchText->record_id = $recordId;
     }
     $searchText->public = $public ? 1 : 0;
     $searchText->title = $title;
     $searchText->text = $text;
     $searchText->save();
 }