Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save algotrader-dotcom/41d484070d06fbcb08d91f93c7449aee to your computer and use it in GitHub Desktop.

Select an option

Save algotrader-dotcom/41d484070d06fbcb08d91f93c7449aee to your computer and use it in GitHub Desktop.
Drupal Search Api Custom Search Example
<?php
# http://drupal.stackexchange.com/questions/135918/return-other-indexed-fields-using-searchapiqueryindex
# http://www.phponwebsites.com/2015/12/drupal-7-add-custom-fields-to-search-api-solr-index.html
# https://gist.github.com/acquialibrary/572acdbc4004fbfca02b
# http://drupal.stackexchange.com/questions/115878/search-snippet-does-not-appear-in-search-api-search-page
# Remember disable Tokenizer in Filter (This causes a lot of troubles in highlighting keyword)
$server = search_api_server_load('acquia_search_solr_server');
$index = search_api_index_load('node_index');
$query = new SearchApiQuery($index);
$query->condition('type', 'article'); // type must be indexed when configure in backend
$results = $query->execute();
// Nice results
$solr = new SearchApiSolrService($server);
$res = $solr->search($query);
print_r($res);
// Nice results
print_r($results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment