public function exhibitSearch($args, $view)
 {
     // Get exhibit ID from shortcode
     if (isset($args['exhibit'])) {
         $eid = $args['exhibit'];
     }
     // Get page IDs for the exhibit
     $db = get_db();
     $select = "\n                    SELECT id\n                    FROM omeka_exhibit_pages\n                    WHERE (exhibit_id=?)\n                    ORDER BY id\n                    ";
     $pages = $db->getTable("ExhibitPage")->fetchObjects($select, array($eid));
     $page_ids = array();
     foreach ($pages as $page) {
         array_push($page_ids, $page['id']);
     }
     $page_string = join(",", $page_ids);
     // Build the options and filters arrays used for searches.
     $options = array();
     // Set the default flag indicating whether to show the advanced form.
     if (!isset($options['show_advanced'])) {
         $options['show_advanced'] = true;
     }
     // Set the default submit value.
     if (!isset($options['submit_value'])) {
         $options['submit_value'] = __('Search');
     }
     // Set the default form attributes.
     $options['form_attributes'] = array();
     $url = apply_filters('search_form_default_action', url('search'));
     $options['form_attributes']['action'] = $url;
     $options['form_attributes']['id'] = 'search-form';
     $options['form_attributes']['method'] = 'get';
     $options['form_attributes']['style'] = 'text-align:left;width:75%';
     $this->_validQueryTypes = get_search_query_types();
     $this->_validRecordTypes = get_custom_search_record_types();
     $filters = array();
     if (isset($_GET['query'])) {
         $filters['query'] = $_GET['query'];
     } else {
         $filters['query'] = '';
     }
     if (isset($_GET['query_type']) && array_key_exists($_GET['query_type'], $this->_validQueryTypes)) {
         $filters['query_type'] = $_GET['query_type'];
     } else {
         $filters['query_type'] = 'keyword';
     }
     if (isset($_GET['record_types'])) {
         $filters['record_types'] = $_GET['record_types'];
     } else {
         $filters['record_types'] = array_keys($this->_validRecordTypes);
     }
     // Add a filter for exhibit_id
     if (isset($_GET['exhibit_id'])) {
         $filters['exhibit_id'] = $_GET['exhibit_id'];
     } else {
         $filters['exhibit_id'] = $page_ids;
     }
     $this->_filters = $filters;
     // Pass variables to a view; the view returns a search box.
     return $view->partial('search/search.php', array('options' => $options, 'filters' => $this->_filters, 'recordIDs' => $page_string, 'query_types' => array('keyword' => __('Keyword')), 'record_types' => array('ExhibitPage' => __('Exhibit Page')), 'exhibit_id' => array($eid => "Record Id: {$eid}")));
 }
Example #2
0
 public function editSearchAction()
 {
     // Customize search record types.
     $csrf = new Omeka_Form_SessionCsrf();
     $this->view->searchRecordTypes = get_search_record_types();
     $this->view->customSearchRecordTypes = get_custom_search_record_types();
     $this->view->csrf = $csrf;
     if ($this->getRequest()->isPost()) {
         if (!$csrf->isValid($_POST)) {
             $this->_helper->_flashMessenger(__('There was an error on the form. Please try again.'), 'error');
             return;
         }
         if (isset($_POST['submit_save_changes'])) {
             if (isset($_POST['search_record_types'])) {
                 $option = serialize($_POST['search_record_types']);
             } else {
                 $option = serialize(array());
             }
             set_option('search_record_types', $option);
             $this->_helper->flashMessenger(__('You have changed which records are searchable in Omeka. Please re-index the records using the form below.'), 'success');
         }
         // Index the records.
         if (isset($_POST['submit_index_records'])) {
             Zend_Registry::get('bootstrap')->getResource('jobs')->sendLongRunning('Job_SearchTextIndex');
             $this->_helper->flashMessenger(__('Indexing records. This may take a while. You may continue administering your site.'), 'success');
         }
         $this->_helper->redirector('edit-search');
     }
 }
Example #3
0
 /**
  * Return a list of current search filters in use.
  * 
  * @param array $options Valid options are as follows:
  * - id (string): the ID of the filter wrapping div.
  * @return string
  */
 public function searchFilters(array $options = array())
 {
     $validQueryTypes = get_search_query_types();
     $validRecordTypes = get_custom_search_record_types();
     $query = '';
     $queryType = 'keyword';
     $recordTypes = $validRecordTypes;
     if (isset($_GET['query'])) {
         $query = $_GET['query'];
     }
     if (isset($_GET['query_type']) && array_key_exists($_GET['query_type'], $validQueryTypes)) {
         $queryType = $_GET['query_type'];
     }
     if (isset($_GET['record_types'])) {
         $recordTypes = array();
         foreach ($_GET['record_types'] as $recordType) {
             $recordTypes[] = $validRecordTypes[$recordType];
         }
     }
     // Set the default options.
     if (!isset($options['id'])) {
         $options['id'] = 'search-filters';
     }
     return $this->view->partial('search/search-filters.php', array('options' => $options, 'query' => $query, 'query_type' => $validQueryTypes[$queryType], 'record_types' => $recordTypes));
 }
Example #4
0
 public function applySearchFilters($select, $params, $retrieveInfos = false)
 {
     // For Url /search?query...
     // Set the query string if not passed.
     if (!isset($params['query'])) {
         $params['query'] = '';
     }
     // Set the query type if not passed.
     if (!isset($params['query_type'])) {
         $params['query_type'] = 'full_text';
     }
     // Set the base select statement.
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->columns(array('record_type', 'record_id', 'title'));
     // Set the where clause according to the query type.
     if ('exact_match' == $params['query_type']) {
         $where = '`search_texts`.`text` LIKE ?';
         $params['query'] = "%{$params['query']}%";
     } else {
         if ('boolean' == $params['query_type']) {
             $where = 'MATCH (`search_texts`.`text`) AGAINST (? IN BOOLEAN MODE)';
         } else {
             $where = 'MATCH (`search_texts`.`text`) AGAINST (?)';
         }
     }
     $select->where($where, $params['query']);
     // Must fire the "search_sql" hook here instead of relying on the native
     // "search_text_browse_sql" hook to ensure that the subsequent WHERE
     // clauses are not reset. This hook can be used when a custom search
     // strategy is added using the "search_query_types" filter.
     fire_plugin_hook('search_sql', array('select' => $select, 'params' => $params));
     // Search only those record types that are configured to be searched.
     $searchRecordTypes = get_custom_search_record_types();
     if ($searchRecordTypes) {
         $select->where('`search_texts`.`record_type` IN (?)', array_keys($searchRecordTypes));
     }
     // Search on an specific record type.
     if (isset($params['record_types'])) {
         $select->where('`search_texts`.`record_type` IN (?)', $params['record_types']);
     }
     // Restrict access to private records.
     $showNotPublic = Zend_Registry::get('bootstrap')->getResource('Acl')->isAllowed(current_user(), 'Search', 'showNotPublic');
     if (!$showNotPublic) {
         $select->where('`search_texts`.`public` = 1');
     }
     if ($retrieveInfos) {
         $select->joinLeft(array('hierarchies' => 'omeka_hierarchies'), 'search_texts.record_id = hierarchies.id', array('hierarchies.atom_top_parent_id', 'hierarchies.atom_id', 'search_texts.record_id as id'));
     }
 }
Example #5
0
 /**
  * Return the site-wide search form.
  * 
  * @param array $options Valid options are as follows:
  * - show_advanced: whether to show the advanced search; default is false.
  * - submit_value: the value of the submit button; default "Submit".
  * - form_attributes: an array containing form tag attributes.
  * @return string The search form markup.
  */
 public function searchForm(array $options = array())
 {
     $validQueryTypes = get_search_query_types();
     $validRecordTypes = get_custom_search_record_types();
     $filters = array('query' => apply_filters('search_form_default_query', ''), 'query_type' => apply_filters('search_form_default_query_type', 'keyword'), 'record_types' => apply_filters('search_form_default_record_types', array_keys($validRecordTypes)));
     if (isset($_GET['submit_search'])) {
         if (isset($_GET['query'])) {
             $filters['query'] = $_GET['query'];
         }
         if (isset($_GET['query_type'])) {
             $filters['query_type'] = $_GET['query_type'];
         }
         if (isset($_GET['record_types'])) {
             $filters['record_types'] = $_GET['record_types'];
         }
     }
     // Set the default flag indicating whether to show the advanced form.
     if (!isset($options['show_advanced'])) {
         $options['show_advanced'] = false;
     }
     // Set the default submit value.
     if (!isset($options['submit_value'])) {
         $options['submit_value'] = __('Search');
     }
     // Set the default form attributes.
     if (!isset($options['form_attributes'])) {
         $options['form_attributes'] = array();
     }
     if (!isset($options['form_attributes']['action'])) {
         $url = apply_filters('search_form_default_action', url('search'));
         $options['form_attributes']['action'] = $url;
     }
     if (!isset($options['form_attributes']['id'])) {
         $options['form_attributes']['id'] = 'search-form';
     }
     $options['form_attributes']['method'] = 'get';
     $formParams = array('options' => $options, 'filters' => $filters, 'query_types' => $validQueryTypes, 'record_types' => $validRecordTypes);
     $form = $this->view->partial('search/search-form.php', $formParams);
     return apply_filters('search_form', $form, $formParams);
 }
Example #6
0
 /**
  * Bulk index all valid records.
  */
 public function perform()
 {
     // Truncate the `search_texts` table before indexing to clean out
     // obsolete records.
     $sql = "TRUNCATE TABLE {$this->_db->SearchText}";
     $this->_db->query($sql);
     foreach (get_custom_search_record_types() as $key => $value) {
         $recordType = is_string($key) ? $key : $value;
         if (!class_exists($recordType)) {
             // The class does not exist or cannot be found.
             continue;
         }
         $record = new $recordType();
         if (!$record instanceof Omeka_Record_AbstractRecord) {
             // The class is not a valid record.
             continue;
         }
         if (!is_callable(array($record, 'addSearchText'))) {
             // The record does not implement the search mixin.
             continue;
         }
         $pageNumber = 1;
         $recordTable = $record->getTable();
         // Query a limited number of rows at a time to prevent memory issues.
         while ($recordObjects = $recordTable->fetchObjects($recordTable->getSelect()->limitPage($pageNumber, 100))) {
             foreach ($recordObjects as $recordObject) {
                 // Save the record object, which indexes its search text.
                 try {
                     $recordObject->save();
                 } catch (Omeka_Validate_Exception $e) {
                     _log($e, Zend_Log::ERR);
                     _log(sprintf('Failed to index %s #%s', get_class($recordObject), $recordObject->id), Zend_Log::ERR);
                 }
                 release_object($recordObject);
             }
             $pageNumber++;
         }
     }
 }
Example #7
0
 /**
  * Set the values needs for children of this class.
  */
 public function __construct()
 {
     // Set the valid query and record types.
     $this->_validQueryTypes = get_search_query_types();
     $this->_validRecordTypes = get_custom_search_record_types();
     // Set default form filters if not passed with the request.
     $filters = array();
     if (isset($_GET['query'])) {
         $filters['query'] = $_GET['query'];
     } else {
         $filters['query'] = '';
     }
     if (isset($_GET['query_type']) && array_key_exists($_GET['query_type'], $this->_validQueryTypes)) {
         $filters['query_type'] = $_GET['query_type'];
     } else {
         $filters['query_type'] = 'keyword';
     }
     if (isset($_GET['record_types'])) {
         $filters['record_types'] = $_GET['record_types'];
     } else {
         $filters['record_types'] = array_keys($this->_validRecordTypes);
     }
     $this->_filters = $filters;
 }