Suresh
July 14, 2016
Recently I came across a situation where I needed to make Apache solr search from drupal programmatically. Basically, we have Apache solr module available in Drupal, which enables us to connect with solr for searching. There are loads of documentation for setting solr search with drupal, so instead of going into those details, let's head straight to the custom code required to make programmatic solr search from drupal:
$solr = apachesolr_get_solr();
$query = apachesolr_drupal_query("apachesolr");
$query->addParam('q', 'keyword'); // keyword to be searched
$query->addParam('hl', true); // enable highlighting
$query->addParam('rows', '200');
$response = $query->search();
$raw_results = apachesolr_search_process_response($response, $query);
if (isset($raw_results) && !empty($raw_results)) {
foreach ($raw_results as $raw_result) {
// theme individual results
$result .= theme('search_result', array('result' => $raw_result, 'module' => 'apachesolr_search'));
}
}
return $result;
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!