Am working with drupal search api solr module am trying to get it to work with the OR Operator so if i do a search for "David Smith" it should show results for both "David" and "Smith" does anyone have ideas on how to achieve this
1 Answer
By default, the apachesolr Drupal module is set to do an AND search. However, you can change that in one of two ways:
Implement a custom module that alters the queries sent to apachesolr. All you'd need is to implement the apachesolr_query_alter hook.
<?php function HOOK_apachesolr_query_alter($query) { // Force an OR keyword search. $params['mm'] = '100%'; } ?>
More details can be found on this drupal.org documentation page: http://drupal.org/node/1159424
The second thing you can do is modify the deafaultOperator from "AND" to "OR" in apachesolr's schema.xml file. You should be able to find that in your modules/apachesolr/solr-conf folder. That setting should be towards the end of the file
<!-- SolrQueryParser configuration: defaultOperator="AND|OR" --> <solrQueryParser defaultOperator="AND"/> // change to OR here
With this second one, just be careful. You don't want to make this change to your schema file and then forget and have it replaced later when you update your module or something like that. Just by searching now, I can see there is this rather unstable module that exposes some of the configuration options of the schema file in the User Interface: http://drupal.org/project/apachesolr_confgen, but I'm not sure I'd choose to use that...
Hope one of these helps!
-
Thanks for the tips i have tried to use the hook in my template.php file but there is no change does this have to be in a custom module. also i am using the drupal.org/project/search_api_solr module not drupal.org/project/apachesolr so am guessing the hook may not work in this case? Commented Apr 26, 2013 at 20:14
-
Hey there, this should be your own separate module, but it can be quite minimal, since all you really would need is your .info file, and the hook above in your .module file (of course, with your module's name substituted in for the 'HOOK' part). This does indeed work with apachesolr, and I'm not sure if your module would call that hook... Commented Apr 29, 2013 at 17:04
-
Once again thanks for your help i have tried this on a custom module but it seems that hook is not available on the www.drupal.org/project/search_api_solr module. is there any other way to do this? thanks Commented Apr 30, 2013 at 14:00
-
@user1108509 The hook is named
hook_search_api_solr_query_alter()
for that module, there's a list of them in the search_api_solr.api.php file that comes with the module– Clive ♦Commented Jun 11, 2013 at 11:19