You are here

function apachesolr_search_conditions_default in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr_search.module \apachesolr_search_conditions_default()
  2. 6.3 apachesolr_search.module \apachesolr_search_conditions_default()
4 calls to apachesolr_search_conditions_default()
apachesolr_search_conditions in ./apachesolr_search.module
Implementation of a search_view() conditions callback.
apachesolr_search_custom_page in ./apachesolr_search.pages.inc
Returns search results on user defined search pages.
apachesolr_search_init in ./apachesolr_search.module
Implements hook_init().
apachesolr_search_search_results in ./apachesolr_search.module
Executes search depending on the conditions given. See apachesolr_search.pages.inc for another use of this function

File

./apachesolr_search.module, line 958
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_conditions_default($search_page) {
  $conditions = array();
  $search_type = isset($search_page['settings']['apachesolr_search_search_type']) ? $search_page['settings']['apachesolr_search_search_type'] : '';
  $allow_user_input = isset($search_page['settings']['apachesolr_search_allow_user_input']) ? $search_page['settings']['apachesolr_search_allow_user_input'] : FALSE;
  $path_replacer = isset($search_page['settings']['apachesolr_search_path_replacer']) ? $search_page['settings']['apachesolr_search_path_replacer'] : '';
  $set_custom_filter = isset($search_page['settings']['apachesolr_search_custom_enable']) ? $search_page['settings']['apachesolr_search_custom_enable'] : '';
  $search_page_fq = !empty($search_page['settings']['fq']) ? $search_page['settings']['fq'] : '';
  $conditions['fq'] = array();

  // We only allow this to happen if the search page explicitely allows it
  if ($allow_user_input) {

    // Get the filterQueries from the url
    if (!empty($_GET['fq']) && is_array($_GET['fq'])) {

      // Reset the array so that we have one level lower to go through
      $conditions['fq'] = $_GET['fq'];
    }
    foreach ($conditions['fq'] as $condition_id => $condition) {

      // If the user input does not pass our validation we do not allow
      // it to query solr
      $test_query = apachesolr_drupal_subquery('Test');
      if (!$test_query
        ->validFilterValue($condition)) {
        unset($conditions['fq'][$condition_id]);
      }
    }
  }

  // Custom filters added in search pages
  if (!empty($search_page_fq) && !empty($set_custom_filter)) {
    if (!empty($path_replacer)) {

      // If the manual filter has a % in it, replace it with $value
      $conditions['fq'][] = str_replace('%', $path_replacer, $search_page_fq);
    }
    else {

      // Put the complete filter in the filter query
      $conditions['fq'][] = $search_page_fq;
    }
  }

  // Search type filters (such as taxonomy)
  if (!empty($path_replacer) && !empty($search_type) && $search_type != 'custom') {
    $conditions['fq'][] = $search_type . ':' . $path_replacer;
  }

  // We may also have filters added by facet API module. The 'f'
  // is determined by variable FacetapiUrlProcessor::$filterKey. Hard
  // coded here to avoid extra class loading.
  if (!empty($_GET['f']) && is_array($_GET['f'])) {
    if (module_exists('facetapi')) {
      $conditions['f'] = $_GET['f'];
    }
  }

  // Add the sort from the page to our conditions
  $sort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';
  $conditions['apachesolr_search_sort'] = $sort;
  return $conditions;
}