mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Fix PHRAS-322, add result debug informations (aggregations)
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
namespace Alchemy\Phrasea\Controller\Prod;
|
namespace Alchemy\Phrasea\Controller\Prod;
|
||||||
|
|
||||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
@@ -69,6 +70,7 @@ class Query implements ControllerProviderInterface
|
|||||||
$page = 1;
|
$page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var SearchEngineResult $result */
|
||||||
$result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options);
|
$result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options);
|
||||||
|
|
||||||
$app['manipulator.user']->logQuery($app['authentication']->getUser(), $result->getQuery());
|
$app['manipulator.user']->logQuery($app['authentication']->getUser(), $result->getQuery());
|
||||||
@@ -191,7 +193,12 @@ class Query implements ControllerProviderInterface
|
|||||||
);
|
);
|
||||||
|
|
||||||
$json['query'] = $query;
|
$json['query'] = $query;
|
||||||
|
|
||||||
|
/** Debug */
|
||||||
$json['parsed_query'] = $result->getQuery();
|
$json['parsed_query'] = $result->getQuery();
|
||||||
|
$json['aggregations'] = $result->getAggregations();
|
||||||
|
/** End debug */
|
||||||
|
|
||||||
$json['phrasea_props'] = $proposals;
|
$json['phrasea_props'] = $proposals;
|
||||||
$json['total_answers'] = (int) $result->getAvailable();
|
$json['total_answers'] = (int) $result->getAvailable();
|
||||||
$json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false;
|
$json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false;
|
||||||
|
|||||||
@@ -327,8 +327,27 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params = $this->createRecordQueryParams($recordQuery, $options, null);
|
$params = $this->createRecordQueryParams($recordQuery, $options, null);
|
||||||
$params['from'] = $offset;
|
$params['body']['from'] = $offset;
|
||||||
$params['size'] = $perPage;
|
$params['body']['size'] = $perPage;
|
||||||
|
|
||||||
|
// Debug at the moment. See https://phraseanet.atlassian.net/browse/PHRAS-322
|
||||||
|
$params['body']['aggs'] = array (
|
||||||
|
'Keywords' => array ('terms' =>
|
||||||
|
array ('field' => 'caption.Keywords.raw', 'size' => 10),
|
||||||
|
),
|
||||||
|
'Photographer' => array ('terms' =>
|
||||||
|
array ('field' => 'caption.Photographer.raw', 'size' => 10),
|
||||||
|
),
|
||||||
|
'Headline' => array ('terms' =>
|
||||||
|
array ('field' => 'caption.Headline.raw', 'size' => 10),
|
||||||
|
),
|
||||||
|
'City' => array ('terms' =>
|
||||||
|
array ('field' => 'caption.City.raw', 'size' => 10),
|
||||||
|
),
|
||||||
|
'Country' => array ('terms' =>
|
||||||
|
array ('field' => 'caption.Country.raw', 'size' => 10),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
$res = $this->doExecute('search', $params);
|
$res = $this->doExecute('search', $params);
|
||||||
|
|
||||||
@@ -349,7 +368,8 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
$query['query'] = json_encode($params);
|
$query['query'] = json_encode($params);
|
||||||
|
|
||||||
return new SearchEngineResult($results, json_encode($query), $res['took'], $offset,
|
return new SearchEngineResult($results, json_encode($query), $res['took'], $offset,
|
||||||
$res['hits']['total'], $res['hits']['total'], null, null, $suggestions, [], $this->indexName);
|
$res['hits']['total'], $res['hits']['total'], null, null, $suggestions, [],
|
||||||
|
$this->indexName, $res['aggregations']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ class SearchEngineResult
|
|||||||
protected $suggestions;
|
protected $suggestions;
|
||||||
protected $propositions;
|
protected $propositions;
|
||||||
protected $indexes;
|
protected $indexes;
|
||||||
|
protected $aggregations;
|
||||||
|
|
||||||
public function __construct(ArrayCollection $results, $query, $duration, $offsetStart, $available, $total, $error, $warning, ArrayCollection $suggestions, $propositions, $indexes)
|
public function __construct(ArrayCollection $results, $query, $duration, $offsetStart, $available, $total, $error,
|
||||||
|
$warning, ArrayCollection $suggestions, $propositions, $indexes, $aggregations = array())
|
||||||
{
|
{
|
||||||
$this->results = $results;
|
$this->results = $results;
|
||||||
$this->query = $query;
|
$this->query = $query;
|
||||||
@@ -40,6 +42,7 @@ class SearchEngineResult
|
|||||||
$this->suggestions = $suggestions;
|
$this->suggestions = $suggestions;
|
||||||
$this->propositions = $propositions;
|
$this->propositions = $propositions;
|
||||||
$this->indexes = $indexes;
|
$this->indexes = $indexes;
|
||||||
|
$this->aggregations = $aggregations;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -172,4 +175,12 @@ class SearchEngineResult
|
|||||||
{
|
{
|
||||||
return $this->indexes;
|
return $this->indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAggregations()
|
||||||
|
{
|
||||||
|
return $this->aggregations;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -472,8 +472,27 @@ function initAnswerForm() {
|
|||||||
query = JSON.parse(query);
|
query = JSON.parse(query);
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
console.log('Parsed Query:', query);
|
|
||||||
|
|
||||||
|
console.info('All Details:', query);
|
||||||
|
console.debug('Paths:');
|
||||||
|
console.debug(query._paths);
|
||||||
|
|
||||||
|
var aggs = datas.aggregations;
|
||||||
|
try {
|
||||||
|
aggs = JSON.parse(aggs);
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
|
||||||
|
console.debug('Aggregations:');
|
||||||
|
var toDisplay = [];
|
||||||
|
_.each(aggs, function(value, key) {
|
||||||
|
_.each(value.buckets, function(bucket, keyBis) {
|
||||||
|
if (!toDisplay[keyBis]) { toDisplay[keyBis] = {}; }
|
||||||
|
toDisplay[keyBis][key] = bucket.key + ' ('+ bucket.doc_count + ')';
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
console.table(toDisplay);
|
||||||
|
|
||||||
$('#answers').empty().append(datas.results).removeClass('loading');
|
$('#answers').empty().append(datas.results).removeClass('loading');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user