I created a search block that was configured to search several content types. I used Dropdown list to show content types. When I did a search, the results page listed contents from all content types and the URL was `http://mysite.com/search/node/lorem?f%5B0%5D=bundle%3Anews` (`lorem` was the search term and `news` was the content type). By the way, I'm using apachesolr for the search. I looked the query passed to solr, the parameter `q=lorem` though `fq` (filter query) was empty.
It seems to that the `bundle` parameter was not passed to solr.

Any ideas? Thanks in advance.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jdanthinne’s picture

I think this has been fixed in Custom Search 7.x-1.17. Can you try this version?
See #2297015: Path generated for apache solr filters doesn't resolve.
In general, always try with the latest (or dev) version available before reporting a bug.

kuangshi.yan’s picture

Thanks for your response.
You're right the bug can be fixed by using `fq`, however in the last release (or dev) version (7.x-1.7 or 7.x-1.x-dev) it's always `f` being used. Can you check it ?
Thanks.

jdanthinne’s picture

Status: Active » Closed (duplicate)

Strange, the commit hasn't been taken. I've just re-pushed it to dev.
See http://cgit.drupalcode.org/custom_search/commit/?id=42188d0

ngocketit’s picture

Is it working now? It still doesn't seem to work for me. The query passed to Solr doesn't contain filter query for bundles. In the latest release version 7.x-1.18, fq is used instead of f. Here is the code:

function _custom_search_apachesolr_search($variables, &$keys, $fields) {
  // Use the search info for the apachesolr module to get the search path.
  $solr_info = apachesolr_search_search_info();
  $type = 'search/' . $solr_info['path'] . '/' . $variables['keywords'];
  $keys = array();

  if (count($variables['types']) && !in_array('all', $variables['types'])) {
    foreach ($variables['types'] as $t) {
      $keys['fq[' . count($keys) . ']'] = 'bundle:' . $t;
    }
  }

  if (module_exists('taxonomy') && count($variables['terms'])) {
    // Get all fields info to get correct filter names.
    $taxonomy_fields = array();
    foreach ($fields as $name => $settings) {
      if ($settings['type'] == 'taxonomy_term_reference') {
        $voc = taxonomy_vocabulary_machine_name_load($settings['settings']['allowed_values'][0]['vocabulary']);
        $taxonomy_fields[$voc->vid] = $name;
      }
    }
    // Build keys for taxonomy.
    foreach ($variables['terms'] as $t) {
      $vocid = taxonomy_term_load($t)->vid;
      $keys['fq[' . count($keys) . ']'] = 'im_' . $taxonomy_fields[$vocid] . ':' . $t;
    }
  }

  foreach (module_implements('custom_search_apachesolr_processing') as $module) {
    $function = $module . '_custom_search_apachesolr_processing';
    
    if (function_exists($function)) {
      call_user_func_array($function, array(&$keys, $fields, $variables['other']));
    }
  }
  return array('path' => $type, 'query' => $keys);
}
ngocketit’s picture

I just figured it out myself. It's not because of custom_search but a setting in Apachesolr module that prevents manual faceting passed thru the URL. Enabling it and the bundles are passed to Solr successfully. However, is there any way to use "OR" operator for the bundles? For example, I want to search nodes of either "page" or "event" content type. Currently, bundles seem to be "AND"ed.

jdanthinne’s picture

I'm not used to Solr so let me know (or provide a patch) how the query should be modified to have OR, and I'll do my best to implement that.

ngocketit’s picture

@jdanthinne: Currently, we're having something like this: fq[0]=bundle:event&fq[1]=bundle:page, which will result in "AND" to be used. For "OR", it would be like this instead: fq[0]=bundle:(event OR page).

jdanthinne’s picture

Can you try this patch and tell me if it's what you need?

krrishnajee’s picture

I waste my whole day to figure out this, but end of the day it's just a checkbox tic :) thanks @ngocketit