mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Merge pull request #1395 from jygaulier/PHRAS-442_FACETS-IN-API
PHRAS-442
This commit is contained in:
@@ -271,13 +271,13 @@ class ElasticSearchEngine implements SearchEngineInterface
|
||||
$res = $this->client->search($params);
|
||||
|
||||
$results = new ArrayCollection();
|
||||
$suggestions = new ArrayCollection();
|
||||
|
||||
$n = 0;
|
||||
foreach ($res['hits']['hits'] as $hit) {
|
||||
$results[] = ElasticsearchRecordHydrator::hydrate($hit, $n++);
|
||||
}
|
||||
|
||||
/** @var FacetsResponse $facets */
|
||||
$facets = $this->facetsResponseFactory->__invoke($res);
|
||||
|
||||
$query['ast'] = $this->app['query_compiler']->parse($string)->dump();
|
||||
@@ -285,9 +285,20 @@ class ElasticSearchEngine implements SearchEngineInterface
|
||||
$query['query'] = $params['body'];
|
||||
$query['query_string'] = json_encode($params['body']);
|
||||
|
||||
return new SearchEngineResult($results, json_encode($query), $res['took'], $offset,
|
||||
$res['hits']['total'], $res['hits']['total'], null, null, $suggestions, [],
|
||||
$this->indexName, $facets);
|
||||
return new SearchEngineResult(
|
||||
$results, // ArrayCollection of results
|
||||
json_encode($query),
|
||||
$res['took'], // duration
|
||||
$offset, // offset start
|
||||
$res['hits']['total'], // available
|
||||
$res['hits']['total'], // total
|
||||
null, // error
|
||||
null, // warning
|
||||
$facets->getAsSuggestions(), // ArrayCollection of suggestions
|
||||
[], // propositions
|
||||
$this->indexName,
|
||||
$facets
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -3,6 +3,8 @@
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
|
||||
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use JsonSerializable;
|
||||
|
||||
class FacetsResponse implements JsonSerializable
|
||||
@@ -31,6 +33,23 @@ class FacetsResponse implements JsonSerializable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function getAsSuggestions()
|
||||
{
|
||||
$suggestions = new ArrayCollection();
|
||||
|
||||
// for es, suggestions are a flat view of facets (api backward compatibility)
|
||||
foreach ($this->facets as $facet) {
|
||||
foreach ($facet['values'] as $value) {
|
||||
$suggestions->add(new SearchEngineSuggestion($value['query'], $value['value'], $value['count']));
|
||||
}
|
||||
}
|
||||
|
||||
return $suggestions;
|
||||
}
|
||||
|
||||
private function buildBucketsValues($name, $buckets)
|
||||
{
|
||||
$values = array();
|
||||
|
@@ -74,7 +74,8 @@ class SearchEngineSuggestion
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'query' => $this->getSuggestion(),
|
||||
'suggestion' => $this->getSuggestion(),
|
||||
'query' => $this->getQuery(),
|
||||
'hits' => $this->getHits(),
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user