PHRAS-1895_PORT_PHRAS-1401_include_json_format_return_record (#2494)

* PHRAS-1895_PORT_PHRAS-1401 include json format return record

* PHRAS-1895_rollback deleted action ref PHRAS-1688
This commit is contained in:
KallooaSan
2018-02-28 20:31:45 +04:00
committed by jygaulier
parent 71f6e5d964
commit 00be9e51b0
11 changed files with 225 additions and 95 deletions

View File

@@ -59,14 +59,14 @@ class SearchController extends Controller
$result = $this->getSearchEngine()->query($query, $options); $result = $this->getSearchEngine()->query($query, $options);
$this->getUserManipulator()->logQuery($this->getAuthenticatedUser(), $result->getUserQuery()); $this->getUserManipulator()->logQuery($this->getAuthenticatedUser(), $result->getQueryText());
// log array of collectionIds (from $options) for each databox // log array of collectionIds (from $options) for each databox
$collectionsReferencesByDatabox = $options->getCollectionsReferencesByDatabox(); $collectionsReferencesByDatabox = $options->getCollectionsReferencesByDatabox();
foreach ($collectionsReferencesByDatabox as $sbid => $references) { foreach ($collectionsReferencesByDatabox as $sbid => $references) {
$databox = $this->findDataboxById($sbid); $databox = $this->findDataboxById($sbid);
$collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references); $collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references);
$this->getSearchEngineLogger()->log($databox, $result->getUserQuery(), $result->getTotal(), $collectionsIds); $this->getSearchEngineLogger()->log($databox, $result->getQueryText(), $result->getTotal(), $collectionsIds);
} }
$this->getSearchEngine()->clearCache(); $this->getSearchEngine()->clearCache();

View File

@@ -1509,14 +1509,14 @@ class V1Controller extends Controller
$search_result = $this->getSearchEngine()->query((string)$request->get('query'), $options); $search_result = $this->getSearchEngine()->query((string)$request->get('query'), $options);
$this->getUserManipulator()->logQuery($this->getAuthenticatedUser(), $search_result->getUserQuery()); $this->getUserManipulator()->logQuery($this->getAuthenticatedUser(), $search_result->getQueryText());
// log array of collectionIds (from $options) for each databox // log array of collectionIds (from $options) for each databox
$collectionsReferencesByDatabox = $options->getCollectionsReferencesByDatabox(); $collectionsReferencesByDatabox = $options->getCollectionsReferencesByDatabox();
foreach ($collectionsReferencesByDatabox as $sbid => $references) { foreach ($collectionsReferencesByDatabox as $sbid => $references) {
$databox = $this->findDataboxById($sbid); $databox = $this->findDataboxById($sbid);
$collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references); $collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references);
$this->getSearchEngineLogger()->log($databox, $search_result->getUserQuery(), $search_result->getTotal(), $collectionsIds); $this->getSearchEngineLogger()->log($databox, $search_result->getQueryText(), $search_result->getTotal(), $collectionsIds);
} }
$this->getSearchEngine()->clearCache(); $this->getSearchEngine()->clearCache();

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Cache\Exception;
use Alchemy\Phrasea\Collection\Reference\CollectionReference; use Alchemy\Phrasea\Collection\Reference\CollectionReference;
use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Configuration\DisplaySettingService; use Alchemy\Phrasea\Core\Configuration\DisplaySettingService;
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions; use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContextFactory; use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContextFactory;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure; use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
@@ -132,9 +133,9 @@ class QueryController extends Controller
// since the query comes from a submited form, normalize crlf,cr,lf ... // since the query comes from a submited form, normalize crlf,cr,lf ...
$query = StringHelper::crlfNormalize($query); $query = StringHelper::crlfNormalize($query);
$json = array( $json = [
'query' => $query 'query' => $query
); ];
$options = SearchEngineOptions::fromRequest($this->app, $request); $options = SearchEngineOptions::fromRequest($this->app, $request);
@@ -168,7 +169,7 @@ class QueryController extends Controller
foreach ($collectionsReferencesByDatabox as $sbid => $references) { foreach ($collectionsReferencesByDatabox as $sbid => $references) {
$databox = $this->findDataboxById($sbid); $databox = $this->findDataboxById($sbid);
$collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references); $collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references);
$this->getSearchEngineLogger()->log($databox, $result->getUserQuery(), $result->getTotal(), $collectionsIds); $this->getSearchEngineLogger()->log($databox, $result->getQueryText(), $result->getTotal(), $collectionsIds);
} }
$proposals = $firstPage ? $result->getProposals() : false; $proposals = $firstPage ? $result->getProposals() : false;
@@ -274,29 +275,69 @@ class QueryController extends Controller
} else { } else {
$template = 'prod/results/records.html.twig'; $template = 'prod/results/records.html.twig';
} }
$json['results'] = $this->render($template, ['results'=> $result]); $json['results'] = $this->render($template, ['results'=> $result]);
/** Debug */
$json['parsed_query'] = $result->getEngineQuery();
/** End debug */
$fieldLabels = [];
// add technical fields // add technical fields
$fieldLabels = [];
foreach(ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) { foreach(ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) {
$fieldLabels[$k] = $this->app->trans($f['label']); $fieldLabels[$k] = $this->app->trans($f['label']);
} }
// add databox fields // add databox fields
// get infos about fields, fusionned and by databox
$fieldsInfos = []; // by databox
foreach ($this->app->getDataboxes() as $databox) { foreach ($this->app->getDataboxes() as $databox) {
$sbasId = $databox->get_sbas_id();
$fieldsInfos[$sbasId] = [];
foreach ($databox->get_meta_structure() as $field) { foreach ($databox->get_meta_structure() as $field) {
if (!isset($fieldLabels[$field->get_name()])) { $name = $field->get_name();
$fieldLabels[$field->get_name()] = $field->get_label($this->app['locale']); $fieldsInfos[$sbasId][$name] = [
'label' => $field->get_label($this->app['locale']),
'type' => $field->get_type(),
'business' => $field->isBusiness(),
'multi' => $field->is_multi(),
];
if (!isset($fieldLabels[$name])) {
$fieldLabels[$name] = $field->get_label($this->app['locale']);
} }
} }
} }
$facets = []; // populates fileds infos
$json['fields'] = $fieldsInfos;
// populates rawresults
// need acl so the result will not include business fields where not allowed
$acl = $this->getAclForUser();
$json['rawResults'] = [];
/** @var ElasticsearchRecord $record */
foreach($result->getResults() as $record) {
$rawRecord = $record->asArray();
$sbasId = $record->getDataboxId();
$baseId = $record->getBaseId();
$caption = $rawRecord['caption'];
if($acl && $acl->has_right_on_base($baseId, \ACL::CANMODIFRECORD)) {
$caption = array_merge($caption, $rawRecord['privateCaption']);
}
// read the fields following the structure order
$rawCaption = [];
foreach($fieldsInfos[$sbasId] as $fieldName=>$fieldInfos) {
if(array_key_exists($fieldName, $caption)) {
$rawCaption[$fieldName] = $caption[$fieldName];
}
}
$rawRecord['caption'] = $rawCaption;
unset($rawRecord['privateCaption']);
$json['rawResults'][$record->getId()] = $rawRecord;
}
// populates facets (aggregates)
$facets = [];
foreach ($result->getFacets() as $facet) { foreach ($result->getFacets() as $facet) {
$facetName = $facet['name']; $facetName = $facet['name'];
@@ -311,6 +352,9 @@ class QueryController extends Controller
$json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false; $json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false;
$json['prev_page'] = ($page > 1 && $result->getAvailable() > 0) ? ($page - 1) : false; $json['prev_page'] = ($page > 1 && $result->getAvailable() > 0) ? ($page - 1) : false;
$json['form'] = $options->serialize(); $json['form'] = $options->serialize();
$json['queryCompiled'] = $result->getQueryCompiled();
$json['queryAST'] = $result->getQueryAST();
$json['queryESLib'] = $result->getQueryESLib();
} }
catch(\Exception $e) { catch(\Exception $e) {
// we'd like a message from the parser so get all the exceptions messages // we'd like a message from the parser so get all the exceptions messages
@@ -319,9 +363,9 @@ class QueryController extends Controller
$msg .= ($msg ? "\n":"") . $e->getMessage(); $msg .= ($msg ? "\n":"") . $e->getMessage();
} }
$template = 'prod/results/help.html.twig'; $template = 'prod/results/help.html.twig';
$result = array( $result = [
'error' => $msg 'error' => $msg
); ];
$json['results'] = $this->render($template, ['results'=> $result]); $json['results'] = $this->render($template, ['results'=> $result]);
} }

View File

@@ -53,6 +53,42 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
private $flags = []; private $flags = [];
private $highlight = []; private $highlight = [];
public function asArray()
{
return [
'_index' => $this->_index,
'_type' => $this->_type,
'_id' => $this->_id,
'_version' => $this->_version,
'_score' => $this->_score,
'databoxId' => $this->databoxId,
'recordId' => $this->recordId,
'collectionId' => $this->collectionId,
'baseId' => $this->baseId,
'collectionName' => $this->collectionName,
'mimeType' => $this->mimeType,
'title' => $this->title,
'originalName' => $this->originalName,
'updated' => $this->updated,
'created' => $this->created,
'sha256' => $this->sha256,
'width' => $this->width,
'height' => $this->height,
'size' => $this->size,
'uuid' => $this->uuid,
'position' => $this->position,
'type' => $this->type,
'status' => $this->status,
'isStory' => $this->isStory,
'caption' => $this->caption,
'privateCaption' => $this->privateCaption,
'exif' => $this->exif,
'subdefs' => $this->subdefs,
'flags' => $this->flags,
'highlight' => $this->highlight,
];
}
/** /**
* @param string $index * @param string $index
* @param string $type * @param string $type

View File

@@ -26,4 +26,4 @@ class V1SearchRecordsResultTransformer extends V1SearchTransformer
{ {
return $this->collection($resultView->getRecords(), $this->recordTransformer); return $this->collection($resultView->getRecords(), $this->recordTransformer);
} }
} }

View File

@@ -36,7 +36,7 @@ abstract class V1SearchTransformer extends TransformerAbstract
return $suggestion->toArray(); return $suggestion->toArray();
}, $result->getSuggestions()->toArray()), }, $result->getSuggestions()->toArray()),
'facets' => $result->getFacets(), 'facets' => $result->getFacets(),
'query' => $result->getEngineQuery(), 'query' => $result->getQueryText(),
]; ];
} }

View File

@@ -273,35 +273,35 @@ class ElasticSearchEngine implements SearchEngineInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function query($string, SearchEngineOptions $options = null) public function query($queryText, SearchEngineOptions $options = null)
{ {
$options = $options ?: new SearchEngineOptions(); $options = $options ?: new SearchEngineOptions();
$context = $this->context_factory->createContext($options); $context = $this->context_factory->createContext($options);
/** @var QueryCompiler $query_compiler */ /** @var QueryCompiler $query_compiler */
$query_compiler = $this->app['query_compiler']; $query_compiler = $this->app['query_compiler'];
$recordQuery = $query_compiler->compile($string, $context); $queryAST = $query_compiler->parse($queryText)->dump();
$queryCompiled = $query_compiler->compile($queryText, $context);
$params = $this->createRecordQueryParams($recordQuery, $options, null); $queryESLib = $this->createRecordQueryParams($queryCompiled, $options, null);
// ask ES to return field _version (incremental version number of document) // ask ES to return field _version (incremental version number of document)
$params['body']['version'] = true; $queryESLib['body']['version'] = true;
$params['body']['from'] = $options->getFirstResult(); $queryESLib['body']['from'] = $options->getFirstResult();
$params['body']['size'] = $options->getMaxResults(); $queryESLib['body']['size'] = $options->getMaxResults();
if($this->options->getHighlight()) { if($this->options->getHighlight()) {
$params['body']['highlight'] = $this->buildHighlightRules($context); $queryESLib['body']['highlight'] = $this->buildHighlightRules($context);
} }
$aggs = $this->getAggregationQueryParams($options); $aggs = $this->getAggregationQueryParams($options);
if ($aggs) { if ($aggs) {
$params['body']['aggs'] = $aggs; $queryESLib['body']['aggs'] = $aggs;
} }
$res = $this->client->search($params); $res = $this->client->search($queryESLib);
$results = new ArrayCollection(); $results = new ArrayCollection();
$n = 0; $n = 0;
foreach ($res['hits']['hits'] as $hit) { foreach ($res['hits']['hits'] as $hit) {
$results[] = ElasticsearchRecordHydrator::hydrate($hit, $n++); $results[] = ElasticsearchRecordHydrator::hydrate($hit, $n++);
@@ -310,16 +310,13 @@ class ElasticSearchEngine implements SearchEngineInterface
/** @var FacetsResponse $facets */ /** @var FacetsResponse $facets */
$facets = $this->facetsResponseFactory->__invoke($res); $facets = $this->facetsResponseFactory->__invoke($res);
$query['ast'] = $query_compiler->parse($string)->dump();
$query['query_main'] = $recordQuery;
$query['query'] = $params['body'];
$query['query_string'] = json_encode($params['body'], JSON_PRETTY_PRINT);
return new SearchEngineResult( return new SearchEngineResult(
$options, $options,
$results, // ArrayCollection of results $results, // ArrayCollection of results
$string, // the query as typed by the user $queryText, // the query as typed by the user
json_encode($query), $queryAST,
$queryCompiled,
$queryESLib,
$res['took'], // duration $res['took'], // duration
$options->getFirstResult(), $options->getFirstResult(),
$res['hits']['total'], // available $res['hits']['total'], // available

View File

@@ -17,8 +17,10 @@ use Doctrine\Common\Collections\ArrayCollection;
class SearchEngineResult class SearchEngineResult
{ {
protected $results; protected $results;
protected $user_query; protected $queryText;
protected $engine_query; protected $queryAST;
protected $queryCompiled;
protected $queryESLib;
protected $duration; protected $duration;
protected $offsetStart; protected $offsetStart;
protected $available; protected $available;
@@ -37,11 +39,12 @@ class SearchEngineResult
private $options; private $options;
/** /**
* SearchEngineResult constructor.
* @param SearchEngineOptions $options * @param SearchEngineOptions $options
* @param ArrayCollection $results * @param ArrayCollection $results
* @param string $user_query query as user typed, "dog" * @param string $queryText
* @param string $engine_query query parsed for engine, "{"ast":"<text:\"dog\">","query_main" .... * @param string $queryAST
* @param string $queryCompiled
* @param string $queryESLib
* @param float $duration * @param float $duration
* @param int $offsetStart * @param int $offsetStart
* @param int $available * @param int $available
@@ -49,15 +52,17 @@ class SearchEngineResult
* @param mixed $error * @param mixed $error
* @param mixed $warning * @param mixed $warning
* @param ArrayCollection $suggestions * @param ArrayCollection $suggestions
* @param array $propositions * @param Array $propositions
* @param array $indexes * @param Array $indexes
* @param FacetsResponse|null $facets * @param FacetsResponse $facets
*/ */
public function __construct( public function __construct(
SearchEngineOptions $options, SearchEngineOptions $options,
ArrayCollection $results, ArrayCollection $results,
$user_query, $queryText,
$engine_query, $queryAST,
$queryCompiled,
$queryESLib,
$duration, $duration,
$offsetStart, $offsetStart,
$available, $available,
@@ -70,10 +75,11 @@ class SearchEngineResult
FacetsResponse $facets = null FacetsResponse $facets = null
) { ) {
$this->options = $options; $this->options = $options;
$this->results = $results; $this->results = $results;
$this->user_query = $user_query; $this->queryText = $queryText;
$this->engine_query = $engine_query; $this->queryAST = $queryAST;
$this->queryCompiled = $queryCompiled;
$this->queryESLib = $queryESLib;
$this->duration = (float) $duration; $this->duration = (float) $duration;
$this->offsetStart = (int) $offsetStart; $this->offsetStart = (int) $offsetStart;
$this->available = (int) $available; $this->available = (int) $available;
@@ -104,35 +110,30 @@ class SearchEngineResult
return $this->results; return $this->results;
} }
/**
* The query related to these results
* @obsolete use getUserQuery (unparsed query) or getEngineQuery (parsed)
*
* @return string
*/
public function getQuery()
{
return $this->getEngineQuery();
}
/** /**
* The unparsed query related to these results * The unparsed query related to these results
* *
* @return string * @return string
*/ */
public function getUserQuery() public function getQueryText()
{ {
return $this->user_query; return $this->queryText;
} }
/**
* The parsed query related to these results public function getQueryAST()
*
* @return string
*/
public function getEngineQuery()
{ {
return $this->engine_query; return $this->queryAST;
}
public function getQueryCompiled()
{
return $this->queryCompiled;
}
public function getQueryESLib()
{
return $this->queryESLib;
} }
/** /**

View File

@@ -59,10 +59,10 @@ class ApiJsonTest extends ApiTestCase
); );
$record = \record_adapter::createFromFile($file, $app); $record = \record_adapter::createFromFile($file, $app);
$story['story_records'] = array(array( $story['story_records'] = [[
'databox_id' => $record->getDataboxId(), 'databox_id' => $record->getDataboxId(),
'record_id' => $record->getRecordId() 'record_id' => $record->getRecordId()
)); ]];
$client = $this->getClient(); $client = $this->getClient();
$client->request( $client->request(
@@ -74,7 +74,7 @@ class ApiJsonTest extends ApiTestCase
'HTTP_ACCEPT' => $this->getAcceptMimeType(), 'HTTP_ACCEPT' => $this->getAcceptMimeType(),
'CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json',
], ],
json_encode(array('stories' => array($story))) json_encode(['stories' => [$story]])
); );
$content = $this->unserialize($client->getResponse()->getContent()); $content = $this->unserialize($client->getResponse()->getContent());
@@ -105,10 +105,10 @@ class ApiJsonTest extends ApiTestCase
); );
$record = \record_adapter::createFromFile($file, self::$DI['app']); $record = \record_adapter::createFromFile($file, self::$DI['app']);
$records = array( $records = [
'databox_id' => $record->getDataboxId(), 'databox_id' => $record->getDataboxId(),
'record_id' => $record->getRecordId() 'record_id' => $record->getRecordId()
); ];
self::$DI['client']->request( self::$DI['client']->request(
'POST', 'POST',
@@ -119,7 +119,7 @@ class ApiJsonTest extends ApiTestCase
'HTTP_ACCEPT' => $this->getAcceptMimeType(), 'HTTP_ACCEPT' => $this->getAcceptMimeType(),
'CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json',
], ],
json_encode(array('story_records' => array($records))) json_encode(['story_records' => [$records]])
); );
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
@@ -147,10 +147,10 @@ class ApiJsonTest extends ApiTestCase
$story->appendChild($record); $story->appendChild($record);
$route = sprintf('/api/v1/stories/%s/%s/delrecords', $story->getDataboxId(), $story->getRecordId()); $route = sprintf('/api/v1/stories/%s/%s/delrecords', $story->getDataboxId(), $story->getRecordId());
$records = array( $records = [
'databox_id' => $record->getDataboxId(), 'databox_id' => $record->getDataboxId(),
'record_id' => $record->getRecordId() 'record_id' => $record->getRecordId()
); ];
self::$DI['client']->request( self::$DI['client']->request(
'DELETE', 'DELETE',
@@ -161,7 +161,7 @@ class ApiJsonTest extends ApiTestCase
'HTTP_ACCEPT' => $this->getAcceptMimeType(), 'HTTP_ACCEPT' => $this->getAcceptMimeType(),
'CONTENT_TYPE' => 'application/json', 'CONTENT_TYPE' => 'application/json',
], ],
json_encode(array('story_records' => array($records))) json_encode(['story_records' => [$records]])
); );
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
@@ -877,7 +877,6 @@ class ApiJsonTest extends ApiTestCase
$this->setToken($this->userAccessToken); $this->setToken($this->userAccessToken);
$response = $this->request('POST', '/api/v1/records/search/', $this->getParameters(), ['HTTP_Accept' => $this->getAcceptMimeType()]); $response = $this->request('POST', '/api/v1/records/search/', $this->getParameters(), ['HTTP_Accept' => $this->getAcceptMimeType()]);
$content = $this->unserialize($response->getContent()); $content = $this->unserialize($response->getContent());
$this->evaluateResponse200($response); $this->evaluateResponse200($response);
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
@@ -909,7 +908,7 @@ class ApiJsonTest extends ApiTestCase
$mock = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface'); $mock = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface');
$app['phraseanet.SE'] = $mock; $app['phraseanet.SE'] = $mock;
$mock $mock
->expects($this->once()) ->expects($this->once())
->method('query') ->method('query')
->withAnyParameters() ->withAnyParameters()
@@ -1065,7 +1064,7 @@ class ApiJsonTest extends ApiTestCase
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/'; $route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/';
self::$DI['client']->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); self::$DI['client']->request('GET', $route, $this->getParameters(), [], array('HTTP_Accept' => $this->getAcceptMimeType()));
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());
@@ -1093,7 +1092,7 @@ class ApiJsonTest extends ApiTestCase
$route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/'; $route = '/api/v1/records/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/embed/';
self::$DI['client']->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); self::$DI['client']->request('GET', $route, $this->getParameters(), [], array('HTTP_Accept' => $this->getAcceptMimeType()));
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent()); $content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
$this->evaluateResponse200(self::$DI['client']->getResponse()); $this->evaluateResponse200(self::$DI['client']->getResponse());

View File

@@ -23,8 +23,11 @@ class SearchEngineResultTest extends \PhraseanetTestCase
self::$DI['record_2'] self::$DI['record_2']
]); ]);
$user_query = 'Gotainer'; $queryText = 'azerty';
$engine_query = '{text:"Gotainer"}'; // fake, real is really more complex $queryAST = '<text:"azerty">'; // fake, real is really more complex
$queryCompiled = '{match:"azerty"}'; // fake, real is really more complex
$queryESLib = '{index:"test", match:{"azerty"}}'; // fake, real is really more complex
$duration = 1 / 3; $duration = 1 / 3;
$offsetStart = 23; $offsetStart = 23;
$available = 25; $available = 25;
@@ -32,12 +35,30 @@ class SearchEngineResultTest extends \PhraseanetTestCase
$error = 'this is an error message'; $error = 'this is an error message';
$warning = 'this is a warning message'; $warning = 'this is a warning message';
$suggestions = new ArrayCollection([ $suggestions = new ArrayCollection([
new SearchEngineSuggestion($user_query, 'Richard', 22) new SearchEngineSuggestion($queryText, 'Richard', 22)
]); ]);
$propositions = new ArrayCollection(); $propositions = new ArrayCollection();
$indexes = 'new-index'; $indexes = 'new-index';
$result = new SearchEngineResult($options, $results, $user_query, $engine_query, $duration, $offsetStart, $available, $total, $error, $warning, $suggestions, $propositions, $indexes); $result = new SearchEngineResult(
$options,
$results,
$queryText, // the query as typed by the user
$queryAST,
$queryCompiled,
$queryESLib,
$duration,
$offsetStart,
$available,
$total,
$error,
$warning,
$suggestions,
$propositions,
$indexes
);
$this->assertEquals($warning, $result->getWarning()); $this->assertEquals($warning, $result->getWarning());
$this->assertEquals(2, $result->getTotalPages(23)); $this->assertEquals(2, $result->getTotalPages(23));
@@ -45,8 +66,12 @@ class SearchEngineResultTest extends \PhraseanetTestCase
$this->assertEquals($total, $result->getTotal()); $this->assertEquals($total, $result->getTotal());
$this->assertEquals($suggestions, $result->getSuggestions()); $this->assertEquals($suggestions, $result->getSuggestions());
$this->assertEquals($results, $result->getResults()); $this->assertEquals($results, $result->getResults());
$this->assertEquals($user_query, $result->getUserQuery());
$this->assertEquals($engine_query, $result->getEngineQuery()); $this->assertEquals($queryText, $result->getQueryText());
$this->assertEquals($queryAST, $result->getQueryAST());
$this->assertEquals($queryCompiled, $result->getQueryCompiled());
$this->assertEquals($queryESLib, $result->getQueryESLib());
$this->assertEquals($propositions, $result->getProposals()); $this->assertEquals($propositions, $result->getProposals());
$this->assertEquals($indexes, $result->getIndexes()); $this->assertEquals($indexes, $result->getIndexes());
$this->assertEquals($error, $result->getError()); $this->assertEquals($error, $result->getError());
@@ -62,8 +87,11 @@ class SearchEngineResultTest extends \PhraseanetTestCase
self::$DI['record_2'] self::$DI['record_2']
]); ]);
$user_query = 'Gotainer'; $queryText = 'azerty';
$engine_query = '{text:"Gotainer"}'; // fake, real is really more complex $queryAST = '<text:"azerty">'; // fake, real is really more complex
$queryCompiled = '{match:"azerty"}'; // fake, real is really more complex
$queryESLib = '{index:"test", match:{"azerty"}}'; // fake, real is really more complex
$duration = 1 / 3; $duration = 1 / 3;
$offsetStart = 0; $offsetStart = 0;
$available = 25; $available = 25;
@@ -71,12 +99,30 @@ class SearchEngineResultTest extends \PhraseanetTestCase
$error = 'this is an error message'; $error = 'this is an error message';
$warning = 'this is a warning message'; $warning = 'this is a warning message';
$suggestions = new ArrayCollection([ $suggestions = new ArrayCollection([
new SearchEngineSuggestion($user_query, 'Richard', 22) new SearchEngineSuggestion($queryText, 'Richard', 22)
]); ]);
$propositions = new ArrayCollection(); $propositions = new ArrayCollection();
$indexes = 'new-index'; $indexes = 'new-index';
$result = new SearchEngineResult($options, $results, $user_query, $engine_query, $duration, $offsetStart, $available, $total, $error, $warning, $suggestions, $propositions, $indexes); $result = new SearchEngineResult(
$options,
$results,
$queryText, // the query as typed by the user
$queryAST,
$queryCompiled,
$queryESLib,
$duration,
$offsetStart,
$available,
$total,
$error,
$warning,
$suggestions,
$propositions,
$indexes
);
$this->assertEquals(1, $result->getCurrentPage(10)); $this->assertEquals(1, $result->getCurrentPage(10));
$this->assertEquals(1, $result->getCurrentPage(25)); $this->assertEquals(1, $result->getCurrentPage(25));

View File

@@ -206,11 +206,18 @@ abstract class PhraseanetAuthenticatedWebTestCase extends \PhraseanetAuthenticat
$elasticsearchRecord->setDataboxId($record->getDataboxId()); $elasticsearchRecord->setDataboxId($record->getDataboxId());
$elasticsearchRecord->setRecordId($record->getRecordId()); $elasticsearchRecord->setRecordId($record->getRecordId());
$queryText = '';
$queryAST = '<NULL>'; // fake, real is really more complex
$queryCompiled = '{match_all:[]}'; // fake, real is really more complex
$queryESLib = '{index:"test", match:{""}}'; // fake, real is really more complex
$result = new SearchEngineResult( $result = new SearchEngineResult(
new SearchEngineOptions(), new SearchEngineOptions(),
new ArrayCollection([$elasticsearchRecord]), // Records new ArrayCollection([$elasticsearchRecord]), // Records
'', // Query as user typed $queryText, // the query as typed by the user
'{}', // Query as engine parsed $queryAST,
$queryCompiled,
$queryESLib,
0, // Duration 0, // Duration
0, // offsetStart 0, // offsetStart
1, // available 1, // available