You are here

protected function SearchApiSolrConnection::httpBuildQuery in Search API Solr 7

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.

Parameters

array $query: The query parameters which should be set.

string $parent: Internal use only.

Return value

string A query string to append (after "?") to a URL.

2 calls to SearchApiSolrConnection::httpBuildQuery()
SearchApiSolrConnection::constructUrl in includes/solr_connection.inc
Returns the HTTP URL for a certain servlet on the Solr server.
SearchApiSolrConnection::search in includes/solr_connection.inc
Executes a search on the Solr server.

File

includes/solr_connection.inc, line 896

Class

SearchApiSolrConnection
Represents a Solr server resource.

Code

protected function httpBuildQuery(array $query, $parent = '') {
  $params = array();
  foreach ($query as $key => $value) {
    $key = $parent ? $parent : rawurlencode($key);

    // Recurse into children.
    if (is_array($value)) {
      $value = $this
        ->httpBuildQuery($value, $key);
      if ($value) {
        $params[] = $value;
      }
    }
    elseif (!isset($value)) {
      $params[] = $key;
    }
    else {
      $params[] = $key . '=' . rawurlencode($value);
    }
  }
  return implode('&', $params);
}