I would like to search for multiple node types; e.g. return all nodes with 'test' of type blog and page.

With solr, fq=[blog page] does work:
http://localhost:8983/solr/spawar/select/?q=test&version=2.2&start=0&row...

In function filter_extract() need to match this pattern, so that $filter is not broken up before the space only, and so that make_filter() does not convert [ to "

The following patch only takes into account if there were 2 types searched for, I haven't figured out how to write the regular expression for more.

CommentFileSizeAuthor
apachesolr_multipletypes.patch753 bytesaufumy

Comments

JacobSingh’s picture

Status: Needs review » Needs work

Unfortunately such as regex is impossible AFAIK.

It would need to be a 2 step process, match and then find :( perhaps we should use anonymous functions for pattern extraction instead of an array of regexes?

pwolanin’s picture

how about fq=type:(blog OR page)

This at least works from the Solr admin interface, and shoudl work from within the module - though I'm not sure whether the parser will handle that right in the URL.

aufumy’s picture

Testing out a different regex, and with more than 2 types, tested 3 and 4:

$patterns[] = '/(^| |-)'. $name .':([\[\(](\w+)(\s+OR\s+|\s+)(\w+)(.*)[\]\)])/';

While this regex does breakup both "type:(blog OR page OR story)" and "type:[blog page story]" the 'OR' version actually returns search results when using the module
* either manually typing in the url such as
/search/apachesolr_search/language?&filters=language%3A%28en%20OR%20ar%20OR%20de%20OR%20ru%29
* using a code snippet below (which depends on patch in http://drupal.org/node/449414)

$keys = 'language';
$query = apachesolr_drupal_query($keys, 'language:(en OR ar OR de OR ru)');
if (is_null($query)) {
  throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
}
$params = apachesolr_search_params($query);
apachesolr_modify_query($query, $params, 'apachesolr_search');
if (!$query) {
  return array();
}
$results = apachesolr_search_results($keys, $query, $params);
jpmckinney’s picture

Status: Needs work » Closed (won't fix)

In 6-2.x, you have OR facets to do this. I don't think this will be backported.

ebeyrent’s picture

Here's one way to implement filtering by multiple content types, as suggested in #5:


/**
 * Implementation of hook_apachesolr_modify_query()
 * 
 * @param object $query
 *   Reference to the Solr_Base_Query object
 * @param mixed $params
 *   Controlling params for the query object
 */
function MYMODULE_apachesolr_modify_query(&$query, &$params, $caller) {
  /**
   * Filters for multiple content types need to be applied to the Solr query object as an "or" condition instead of an "and" condition.
   * To do this, we need to utilize a Solr subquery.
   */
  $node_types = array(
    'blog',
    'page',
    'profile',
  );
  $subquery = apachesolr_drupal_query();
  foreach($node_types as $type) {
    $subquery->add_filter('type', $type);
    $query->add_subquery($subquery, 'OR');
  }
}

jpmckinney’s picture

Category: feature » support
Status: Closed (won't fix) » Fixed

Excellent. I'm switching to support request as the issue is now about how to do OR faceting in 6.x-1.x, not about backporting 6.x-2.x features.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.