views:

52

answers:

0

Making a search with Apachesolr, i want to add a couple of filters in hook_apachesolr_prepare_query(&$query). This works fine, except I want the filters to widen the search ('OR'), rather than narrow it ('AND').

For example, if I have 4 nodes of type:A and 3 of type:B that match a search, to filter by type:A and type:B should return 7 nodes (of type:A AND nodes of type:B), rather than 0 those of type:A which are also of type:B.

I saw a suggestion to do this using the model of nodeaccess

foreach ($filters as $filter) {
  $subquery = apachesolr_drupal_query();
  if (!empty($subquery)) {
    $subquery->add_filter('type', $filter);
    $query->add_subquery($subquery);
  }
}

but this doesn't seem to work. (It doesn't return any results).

I then tried (as I have a limited number of node types) excluding the types that I don't want:

$excludes = array('A', 'B', 'C');
$excludes = array_diff($excludes, $filters);
$exclude = implode('&', $excludes);
$query->add_filter('type', $exclude, TRUE);

This method of stitching them together doesn't work (the '&' gets escaped) but neither does adding them as subqueries, similar to the manner above.

Any suggestions on how to do this?

related questions