You are here

public function SolrBaseQuery::addParam in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 Solr_Base_Query.php \SolrBaseQuery::addParam()
  2. 6.3 Solr_Base_Query.php \SolrBaseQuery::addParam()

Adds a param to be sent when running the Solr search.

If the param is single-valued, this will replace rather than add the value.

Parameters

string $name: A Solr param name, e.g. 'q' or 'fl'.

$value: A Solr param value: an array of values, or a string for a single value.

Return value

DrupalSolrQueryInterface The called object.

Overrides DrupalSolrQueryInterface::addParam

2 calls to SolrBaseQuery::addParam()
SolrBaseQuery::addParams in ./Solr_Base_Query.php
Adds multiple params to be sent when running the Solr search.
SolrBaseQuery::replaceParam in ./Solr_Base_Query.php
Replaces a param to be sent when running the Solr search.

File

./Solr_Base_Query.php, line 505
This class allows you to make operations on a query that will be sent to Apache Solr. methods such as adding and removing sorts, remove and replace parameters, adding and removing filters, getters and setters for various parameters and more

Class

SolrBaseQuery

Code

public function addParam($name, $value) {
  if (isset($this
    ->getSingleValueParams()[$name])) {
    if (is_array($value)) {
      $value = end($value);
    }
    $this->params[$name] = $this
      ->normalizeParamValue($value);
    return $this;
  }

  // We never actually populate $this->params['fq'].  Instead
  // we manage everything via the filter methods.
  if ($name == 'fq') {
    if (is_array($value)) {
      array_walk_recursive($value, array(
        $this,
        'addFq',
      ));
      return $this;
    }
    else {
      return $this
        ->addFq($value);
    }
  }
  if (!isset($this->params[$name])) {
    $this->params[$name] = array();
  }
  if (!is_array($value)) {

    // Convert to array for array_map.
    $param_values = array(
      $value,
    );
  }
  else {

    // Convert to a numerically keyed array.
    $param_values = array_values($value);
  }
  $this->params[$name] = array_merge($this->params[$name], array_map(array(
    $this,
    'normalizeParamValue',
  ), $param_values));
  return $this;
}