Elastica\Query\Fuzzy::setField PHP Method

setField() public method

Set field for fuzzy query.
public setField ( string $fieldName, string $value )
$fieldName string Field name
$value string String to search for
    public function setField($fieldName, $value)
    {
        if (!is_string($value) || !is_string($fieldName)) {
            throw new InvalidException('The field and value arguments must be of type string.');
        }
        if (count($this->getParams()) > 0 && key($this->getParams()) !== $fieldName) {
            throw new InvalidException('Fuzzy query can only support a single field.');
        }
        return $this->setParam($fieldName, ['value' => $value]);
    }

Usage Example

示例#1
0
 /**
  * @group unit
  */
 public function testBadArguments()
 {
     $this->setExpectedException('Elastica\\Exception\\InvalidException');
     $query = new Fuzzy();
     $query->addField('name', array(array('value' => 'Baden')));
     $this->setExpectedException('Elastica\\Exception\\InvalidException');
     $query = new Fuzzy();
     $query->setField('name', array());
     $this->setExpectedException('Elastica\\Exception\\InvalidException');
     $query = new Fuzzy();
     $query->setField('name', 'value');
     $query->setField('name1', 'value1');
 }
All Usage Examples Of Elastica\Query\Fuzzy::setField