从RC4版本开始,您可以使用makeServletRequest()生成自定义的solr查询。在GitHub上查看一些示例。
以下是一些代码示例:
// Ping example
// class_exists('Apache_Solr_Service') ?: spl_autoload_register('_search_api_solr_autoload'); // make sure that SolrPhpClient class is loaded (use only for <=rc3)
$server = search_api_server_load('my_solr_server'); // CHANGE THIS
$solr = new SearchApiSolrService($server);
$result = $solr->ping();
drupal_set_message(print_r($result, TRUE));
// Simple search query (not fully tested)
// class_exists('Apache_Solr_Service') ?: spl_autoload_register('_search_api_solr_autoload'); // make sure that SolrPhpClient class is loaded (use only for <=rc3)
$server = search_api_server_load('my_solr_server'); // CHANGE THIS
$index = search_api_index_load('my_index'); // CHANGE THIS
$query = new SearchApiQuery($index);
$query->keys('foo');
$query->fields(array('title'));
$solr = new SearchApiSolrService($server);
$result = $solr->search($query);
drupal_set_message(print_r($result, TRUE));
// Custom path example for rc4 and above (not fully tested)
$server = search_api_server_load('my_solr_server');
$uri = SearchApiSolrConnection::LUKE_SERVLET . "?show=schema"; // or any other custom URL
$connection = $server->getSolrConnection(); // or: new SearchApiSolrService($server)
$response = $connection->makeServletRequest($uri);
drupal_set_message(print_r($response, TRUE));
// Example for assembling the right URL
$server = search_api_server_load('my_solr_server');
$url = 'http://' . $server->options['host'] . ':' . $server->options['port'] . $server->options['path'];
上面的代码在Drupal 7和Search API Solr [rc3]中在hook_init中进行了测试。
Acquia
如果您使用的是Acquia,则可以使用Acquia-Search-Proxy,该代理使您可以针对Acquia Search(Apachesolr + Search API Solr)发送自定义查询。另请参阅我的Acquia-Search-Proxy分支,其中包括一些其他改进。
通过CLI的示例自定义查询:
PATH_INFO="/admin/ping" php search-proxy.php
PATH_INFO="/admin/luke" QUERY_STRING="show=schema" php search-proxy.php
PATH_INFO="/select" QUERY_STRING="q=foo" php search-proxy.php
PATH_INFO="/admin/file" QUERY_STRING="contentType=text/xml;charset=utf-8&file=schema.xml" php search-proxy.php