I am working on apachesolr search module.

I want to implement wildcard search I have used hook_apachesolr_query_prepare() function to modify apachesolr query but it is not working can any one give me solution.
I have implemented code like this.

I have taken reference from here : https://www.drupal.org/project/apachesolr/issues/1539284

function custommodule_apachesolr_query_prepare(DrupalSolrQueryInterface &$query, &$caller) {

  $search = '';
  $keywords = preg_split("/[\s,]+/", $query->getParam('q')); 

  foreach ($keywords as $keyword) {
    $search .= '*' . strtolower($keyword) . '* ';    

  $query->addParam('defType', 'edismax');  
  $query->replaceParam('q', $search);  


ENV: Drupal 7.60 | Solr 3.X

  • which drupal version you work with, and wich solr version please? – berramou Nov 10 '18 at 20:50
  • drupal 7.60, solr 3.x – muraliniceguy97 Nov 11 '18 at 12:53
  • if you just copied the solrconfig.xml from 3.X folder, add <requestHandler name="drupal" class="solr.SearchHandler" default="true"> mention in the issue page, because it's not added by default in the config example come with search_api_solr module. – berramou Nov 11 '18 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.