I was trying to do do a boolean search 'sname:'.$user->name.' OR sname:xxxxxx; , i am not getting any results where as sname:xxxxxx; works fine. i even added mm=1 with the query modify hook. can somebody guide me how i can accomplish this.

Here is my code.....

$keys = "";
$filters = 'sname:'.$user->name.' OR sname:xxxxxx;
//print($filters);
$solrsort = variable_get('apachesolr_search_taxonomy_sort', 'created desc');
$page = isset($_GET['page']) ? $_GET['page'] : 0;
$_GET['retain-filters'] = 1;

try {
//stolen from search.module (search_data)
$data = apachesolr_search_execute($keys, $filters, $solrsort, 'search/apachesolr_search', $page);
$results = theme('search_results', $data, $type);
} catch (Exception $e){
watchdog('apachesolr', t('Error running search'));
}

function reports_apachesolr_modify_query(&$query, &$params, $caller) {
// I only want to see articles by the admin!
$params['mm'] = 1;
}

Adv thanks.

Comments

pwolanin’s picture

You are trying to do a boolean filter query or a boolean OR keyword search?

If a filter query, look at the code in apachesolr_nodeaccess

for keywords, setting mm to 1 shoudl be enough alone.

this module does not support field:value type queries as keywords due to use of the dismax handler

robertDouglass’s picture

Status: Active » Fixed

There are two cases here, as Peter indicated. First, if you want to change the keyword behavior to be OR instead of AND you can use hook_apachesolr_modify_query(&$query, &$params, $caller) like this:

  // Based on a checkbox I've added to the form, xor will switch between 1 and 0.
  // "any" is the same as OR, so we set mm to 1.
  // "all" is the same as the current default behavior, be we enforce it by setting mm to 100%
  if (isset($values['xor'])) {
    $params['mm'] = ($values['xor'] == 'any') ? '1' : '100%';
  }

If you have a field that is a boolean field you can filter on it like this (same hook):

  if (isset($values['yes-no'])) {
    $query->add_filter('is_yes_no', 1);
  }

Status: Fixed » Closed (fixed)

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

nirmal_george’s picture

jpmckinney’s picture

Category: bug » support