Commit 259b8c90 by tvdavid Committed by Carsten Brandt

Add support for elasticsearch suggestions

close #4505
parent 3fb68096
......@@ -12,7 +12,7 @@ Yii Framework 2 elasticsearch extension Change Log
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
- Enh: Make error messages more readable in HTML output (cebe)
- Enh: Added support for query stats (cebe)
- Enh: Added support for query suggesters (cebe)
- Enh: Added support for query suggesters (cebe, tvdavid)
- Chg #4451: Removed support for facets and replaced them with aggregations (cebe, tadaszelvys)
- Chg: asArray in ActiveQuery is now equal to using the normal Query. This means, that the output structure has changed and `with` is supported anymore. (cebe)
- Chg: Deletion of a record is now also considered successful if the record did not exist. (cebe)
......
......@@ -38,15 +38,11 @@ class Command extends Component
* @var array list of arrays or json strings that become parts of a query
*/
public $queryParts;
/**
* @var array list of arrays to highlight search results on one or more fields
* @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html
*/
public $highlight;
public $options = [];
/**
* Sends a request to the _search API and returns the result
* @param array $options
* @return mixed
*/
......@@ -69,6 +65,29 @@ class Command extends Component
}
/**
* Sends a request to the _suggest API and returns the result
* @param string|array $suggester the suggester body
* @param array $options
* @return mixed
* @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html
*/
public function suggest($suggester, $options = [])
{
if (empty($suggester)) {
$suggester = '{}';
}
if (is_array($suggester)) {
$suggester = Json::encode($suggester);
}
$url = [
$this->index !== null ? $this->index : '_all',
'_suggest'
];
return $this->db->post($url, array_merge($this->options, $options), $suggester);
}
/**
* Inserts a document into an index
* @param string $index
* @param string $type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment