Fix PHRAS-322, add result debug informations (aggregations)

This commit is contained in:
Damien Alexandre
2014-10-14 18:51:02 +02:00
parent 3438295ca3
commit f196155049
4 changed files with 62 additions and 5 deletions

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -69,6 +70,7 @@ class Query implements ControllerProviderInterface
$page = 1;
}
/** @var SearchEngineResult $result */
$result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options);
$app['manipulator.user']->logQuery($app['authentication']->getUser(), $result->getQuery());
@@ -191,7 +193,12 @@ class Query implements ControllerProviderInterface
);
$json['query'] = $query;
/** Debug */
$json['parsed_query'] = $result->getQuery();
$json['aggregations'] = $result->getAggregations();
/** End debug */
$json['phrasea_props'] = $proposals;
$json['total_answers'] = (int) $result->getAvailable();
$json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false;

View File

@@ -327,8 +327,27 @@ class ElasticSearchEngine implements SearchEngineInterface
}
$params = $this->createRecordQueryParams($recordQuery, $options, null);
$params['from'] = $offset;
$params['size'] = $perPage;
$params['body']['from'] = $offset;
$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);
@@ -349,7 +368,8 @@ class ElasticSearchEngine implements SearchEngineInterface
$query['query'] = json_encode($params);
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']);
}
/**

View File

@@ -26,8 +26,10 @@ class SearchEngineResult
protected $suggestions;
protected $propositions;
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->query = $query;
@@ -40,6 +42,7 @@ class SearchEngineResult
$this->suggestions = $suggestions;
$this->propositions = $propositions;
$this->indexes = $indexes;
$this->aggregations = $aggregations;
return $this;
}
@@ -172,4 +175,12 @@ class SearchEngineResult
{
return $this->indexes;
}
/**
* @return array
*/
public function getAggregations()
{
return $this->aggregations;
}
}

View File

@@ -472,8 +472,27 @@ function initAnswerForm() {
query = JSON.parse(query);
}
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');