0

Can anyone provide some info on how to properly execute a filtered apache sold search through the url? So far I've figured out that

?fq[]=bundle:type

will return a results filtered by that bundle type. I've also noticed that

?f[0]=machine_name:value

will return results if that particular facet has been configured. What I want to figure out, though, is how to use the url to send any filter request. For example, if I want to write a url that would return results based on a particular taxonomy term, how would I enter that? Furthermore, can any field be used to filter a search?

0

You should integrate Updated Apachesolr module. Write some custom menu hook to invoke your custom function.

 $query = apachesolr_current_query();
 $params_query = $query->getParams();

The above two statements will help us to check our solr queryString that we have triggered from our application.

/**
 * Implementation of hook_search_execute().
 */
function Custom_Function($keys = NULL, $conditions = NULL) {

  $filters = isset($conditions['fq']) ? $conditions['fq'] : array();
  $solrsort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';

  $response = NULL;
    $filt = array();
  // add custom filters if you want to add few custom filters in certain conditions.
   if($_GET['some key'] == 'some condition') {
        $filt[] = array('name' => 'entity_type', 'value' => 'trend_tips');
      }else{
        $filt[] = array('name' => 'im_16_field_category', 'value' => $_GET['category']);
      }
  $filters = $filt;
  $results = apachesolr_search_run('apachesolr', array('q' => $keys, 'fq' => $filters), $solrsort, 'search/' . arg(1), pager_find_page());

    // Set name for search results
    $query = apachesolr_current_query();

    $params_query = $query->getParams();

    if (module_hook($module, 'search_page')) {
      return module_invoke($module, 'search_page', $results); 
    }
 }
/**
 * Implementation of hook_apachesolr_query_prepare().
 */
function CustomeModule_apachesolr_query_prepare(&$current_query) {

  // add query filters for Style tips and trends
  $current_query->addParam('fl', 'tm_image,tm_url,content');
  $current_query->addParam('qf', 'tm_title');
  $current_query->addParam('qf', 'tm_short_content');
  $current_query->addParam('qf', 'tm_perex');
  $current_query->addParam('mm', '1<-90%'); // if you write more then 1 word to search, solr search as 'OR'
  $current_query->addParam('bf', 'recip(rord(created),4,5759,5759)^5.0'); // remove time dependency on search results


  // remove following content types (product and page) from search
    $current_query->addFilter('entity_type', 'product', true);
    $current_query->addFilter('bundle', 'page', true);
    $current_query->addFilter('tid', "63", true);
    $current_query->addFilter('tid', "64", true);


  $current_query->addParam('facet.field', 'bundle'); 
  // add a new facet type for filter trends and tips on search results

}

Please let me know if the above codebase helped to get some grip.

Thanks

0

It might help you using something like the Pretty Paths module https://www.drupal.org/project/facetapi_pretty_paths

It will be much easier to construct the urls you want.

screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.