Skip to content

Instantly share code, notes, and snippets.

@bfodeke
Last active November 27, 2017 12:02
Show Gist options
  • Save bfodeke/1ccf8c66d1d58aad630d0690b7028640 to your computer and use it in GitHub Desktop.
Save bfodeke/1ccf8c66d1d58aad630d0690b7028640 to your computer and use it in GitHub Desktop.
Search solr using custom code
<?php
/**
* Good resources.
*
* https://www.triquanta.nl/blog/what-fq-short-summary-solr-query-fields
* https://lucene.apache.org/solr/guide/6_6/common-query-parameters.html
* http://valuebound.com/resources/blog/how-to-create-custom-solr-search-autocomplete-drupal-7
*/
// Initializes solr, gets connection and cookie, etc.
$solr = apachesolr_get_solr();
// Create search object.
$s_query = apachesolr_drupal_query('custom', array('q' => 'something'));
// The bundle which you want to search.
$s_query->addFilter('bundle', 'course');
$s_query->setSolrsort('sort_label', 'asc');
$s_query->addParam('start', $offset);
$s_query->addParam('rows', $limit);
// Include debug information about returned info.
$s_query->addParam('debug', 'results');
// Only search in title.
$s_query->addParam('qf', 'label');
$response = $s_query->search();
$data = json_decode($response->data);
$found_courses = $data->response->docs;
dpm($found_courses);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment