updated to 7.x-1.4
This commit is contained in:
@@ -58,10 +58,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starting point for the Solr API. Represents a Solr server resource and has
|
||||
* methods for pinging, adding, deleting, committing, optimizing and searching.
|
||||
* Represents a Solr server resource.
|
||||
*
|
||||
* Contains methods for pinging, adding, deleting, committing, optimizing and
|
||||
* searching.
|
||||
*/
|
||||
|
||||
class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
|
||||
/**
|
||||
@@ -133,13 +134,6 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
*/
|
||||
protected $update_url;
|
||||
|
||||
/**
|
||||
* The HTTP method to use for search requests.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
|
||||
/**
|
||||
* HTTP Basic Authentication header to set for requests to the Solr server.
|
||||
*
|
||||
@@ -208,8 +202,6 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
* information to add basic HTTP authentication to all requests to the
|
||||
* Solr server. Not set by default.
|
||||
* - http_pass: See "http_user".
|
||||
* - http_method: The HTTP method to use for searches. Can be either "GET"
|
||||
* or "POST". Defaults to "POST".
|
||||
*/
|
||||
public function __construct(array $options) {
|
||||
$options += array(
|
||||
@@ -219,16 +211,12 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
'path' => 'solr',
|
||||
'http_user' => NULL,
|
||||
'http_pass' => NULL,
|
||||
'http_method' => 'POST',
|
||||
);
|
||||
$this->options = $options;
|
||||
|
||||
$path = '/' . trim($options['path'], '/') . '/';
|
||||
$this->base_url = $options['scheme'] . '://' . $options['host'] . ':' . $options['port'] . $path;
|
||||
|
||||
// Make sure we always have a valid method set, default to POST.
|
||||
$this->method = $options['http_method'] == 'GET' ? 'GET' : 'POST';
|
||||
|
||||
// Set HTTP Basic Authentication parameter, if login data was set.
|
||||
if (strlen($options['http_user']) && strlen($options['http_pass'])) {
|
||||
$this->http_auth = 'Basic ' . base64_encode($options['http_user'] . ':' . $options['http_pass']);
|
||||
@@ -429,7 +417,7 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
}
|
||||
$response = $this->sendRawGet($url);
|
||||
$this->stats = simplexml_load_string($response->data);
|
||||
if ($this->env_id) {
|
||||
if ($cid) {
|
||||
cache_set($cid, $response->data, 'cache_search_api_solr');
|
||||
}
|
||||
}
|
||||
@@ -813,15 +801,15 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
*
|
||||
* Will be synchronous unless $waitSearcher is set to FALSE.
|
||||
*
|
||||
* @param $type
|
||||
* @param string $type
|
||||
* Either "commit" or "optimize".
|
||||
* @param $waitSearcher
|
||||
* @param bool $waitSearcher
|
||||
* (optional) Wait until a new searcher is opened and registered as the main
|
||||
* query searcher, making the changes visible. Defaults to true.
|
||||
* @param $timeout
|
||||
* @param int $timeout
|
||||
* Seconds to wait until timing out with an exception. Defaults to an hour.
|
||||
*
|
||||
* @return
|
||||
* @return object
|
||||
* A response object.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
@@ -845,7 +833,20 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Like PHP's built in http_build_query(), but uses rawurlencode() and no [] for repeated params.
|
||||
* Generates an URL-encoded query string.
|
||||
*
|
||||
* Works like PHP's built in http_build_query() (or drupal_http_build_query())
|
||||
* but uses rawurlencode() and no [] for repeated params, to be compatible
|
||||
* with the Java-based servers Solr runs on.
|
||||
*
|
||||
*
|
||||
* @param array $query
|
||||
* The query parameters which should be set.
|
||||
* @param string $parent
|
||||
* Internal use only.
|
||||
*
|
||||
* @return string
|
||||
* A query string to append (after "?") to a URL.
|
||||
*/
|
||||
protected function httpBuildQuery(array $query, $parent = '') {
|
||||
$params = array();
|
||||
@@ -870,7 +871,7 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements SearchApiSolrConnectionInterface::search().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function search($query = NULL, array $params = array(), $method = 'GET') {
|
||||
// Always use JSON. See
|
||||
@@ -887,15 +888,18 @@ class SearchApiSolrConnection implements SearchApiSolrConnectionInterface {
|
||||
// PHP's built-in http_build_query() doesn't give us the format Solr wants.
|
||||
$queryString = $this->httpBuildQuery($params);
|
||||
|
||||
if ($this->method == 'GET') {
|
||||
if ($method == 'GET' || $method == 'AUTO') {
|
||||
$searchUrl = $this->constructUrl(self::SEARCH_SERVLET, array(), $queryString);
|
||||
return $this->sendRawGet($searchUrl);
|
||||
}
|
||||
else if ($this->method == 'POST') {
|
||||
$searchUrl = $this->constructUrl(self::SEARCH_SERVLET);
|
||||
$options['data'] = $queryString;
|
||||
$options['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
return $this->sendRawPost($searchUrl, $options);
|
||||
if ($method == 'GET' || strlen($searchUrl) <= variable_get('search_api_solr_http_get_max_length', 4000)) {
|
||||
return $this->sendRawGet($searchUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// Method is POST, or AUTO with a long query
|
||||
$searchUrl = $this->constructUrl(self::SEARCH_SERVLET);
|
||||
$options['data'] = $queryString;
|
||||
$options['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
return $this->sendRawPost($searchUrl, $options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user