Make search engine a real service

This commit is contained in:
Romain Neutron
2014-01-07 16:09:49 +01:00
parent c6059c4a00
commit d7b4e61c10
27 changed files with 172 additions and 241 deletions

View File

@@ -78,7 +78,6 @@ class Root implements ControllerProviderInterface
$perPage = $modCol * $modRow;
$options = SearchEngineOptions::fromRequest($app, $request);
$app['phraseanet.SE']->setOptions($options);
$currentPage = (int) $request->request->get('pag', 0);
@@ -87,7 +86,7 @@ class Root implements ControllerProviderInterface
$currentPage = 1;
}
$result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage);
$result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage, $options);
$userQuery = new UserQuery();
$userQuery->setUsrId($app['authentication']->getUser()->get_id());

View File

@@ -64,8 +64,6 @@ class Query implements ControllerProviderInterface
$perPage = (int) $app['authentication']->getUser()->getPrefs('images_per_page');
$app['phraseanet.SE']->setOptions($options);
$page = (int) $request->request->get('pag');
$firstPage = $page < 1;
@@ -74,7 +72,7 @@ class Query implements ControllerProviderInterface
$page = 1;
}
$result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage);
$result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options);
$userQuery = new UserQuery();
$userQuery->setUsrId($app['authentication']->getUser()->get_id());
@@ -195,6 +193,7 @@ class Query implements ControllerProviderInterface
'results' => $result,
'highlight' => $result->getQuery(),
'searchEngine' => $app['phraseanet.SE'],
'searchOptions' => $options,
'suggestions' => $prop
]
);
@@ -224,7 +223,6 @@ class Query implements ControllerProviderInterface
try {
$options = SearchEngineOptions::hydrate($app, $optionsSerial);
$app['phraseanet.SE']->setOptions($options);
} catch (\Exception $e) {
$app->abort(400, 'Provided search engine options are not valid');
}
@@ -232,7 +230,7 @@ class Query implements ControllerProviderInterface
$pos = (int) $request->request->get('pos', 0);
$query = $request->request->get('query', '');
$record = new \record_preview($app, 'RESULT', $pos, '', $app['phraseanet.SE'], $query);
$record = new \record_preview($app, 'RESULT', $pos, '', $app['phraseanet.SE'], $query, $options);
return $app->json([
'current' => $app['twig']->render('prod/preview/result_train.html.twig', [

View File

@@ -63,7 +63,7 @@ class Records implements ControllerProviderInterface
$app->abort(400);
}
$searchEngine = null;
$searchEngine = $options = null;
$train = '';
if ('' === $env = strtoupper($request->get('env', ''))) {
@@ -75,7 +75,6 @@ class Records implements ControllerProviderInterface
try {
$options = SearchEngineOptions::hydrate($app, $request->get('options_serial'));
$searchEngine = $app['phraseanet.SE'];
$searchEngine->setOptions($options);
} catch (\Exception $e) {
$app->abort(400, 'Search-engine options are not valid or missing');
}
@@ -91,7 +90,8 @@ class Records implements ControllerProviderInterface
$pos < 0 ? 0 : $pos,
$request->get('cont', ''),
$searchEngine,
$query
$query,
$options
);
if ($record->is_from_reg()) {
@@ -116,7 +116,8 @@ class Records implements ControllerProviderInterface
"desc" => $app['twig']->render('prod/preview/caption.html.twig', [
'record' => $record,
'highlight' => $query,
'searchEngine' => $searchEngine
'searchEngine' => $searchEngine,
'searchOptions' => $options,
]),
"html_preview" => $app['twig']->render('common/preview.html.twig', [
'record' => $record

View File

@@ -115,11 +115,11 @@ class Tooltip implements ControllerProviderInterface
$record = new \record_adapter($app, $sbas_id, $record_id, $number);
$search_engine = $app['phraseanet.SE'];
$search_engine_options = null;
if ($context == 'answer') {
try {
$search_engine_options = SearchEngineOptions::hydrate($app, $app['request']->request->get('options_serial'));
$search_engine->setOptions($search_engine_options);
} catch (\Exception $e) {
}
@@ -132,6 +132,7 @@ class Tooltip implements ControllerProviderInterface
'view' => $context,
'highlight' => $app['request']->request->get('query'),
'searchEngine' => $search_engine,
'searchOptions' => $search_engine_options,
]);
}

View File

@@ -25,11 +25,6 @@ class PhraseaEngine implements SearchEngineInterface
{
private $initialized;
/**
*
* @var SearchEngineOptions
*/
private $options;
private $app;
private $dateFields;
private $configuration;
@@ -47,7 +42,6 @@ class PhraseaEngine implements SearchEngineInterface
public function __construct(Application $app)
{
$this->app = $app;
$this->options = new SearchEngineOptions();
}
/**
@@ -339,28 +333,12 @@ class PhraseaEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function setOptions(SearchEngineOptions $options)
public function query($query, $offset, $perPage, SearchEngineOptions $options = null)
{
$this->options = $options;
return $this;
if (null === $options) {
$options = new SearchEngineOptions();
}
/**
* {@inheritdoc}
*/
public function resetOptions()
{
$this->options = new SearchEngineOptions();
return $this;
}
/**
* {@inheritdoc}
*/
public function query($query, $offset, $perPage)
{
$this->initialize();
$this->checkSession();
@@ -372,8 +350,8 @@ class PhraseaEngine implements SearchEngineInterface
$query = "all";
}
if ($this->options->getRecordType()) {
$query .= ' AND recordtype=' . $this->options->getRecordType();
if ($options->getRecordType()) {
$query .= ' AND recordtype=' . $options->getRecordType();
}
$sql = 'SELECT query, query_time, duration, total FROM cache WHERE session_id = :ses_id';
@@ -394,8 +372,8 @@ class PhraseaEngine implements SearchEngineInterface
if ($this->resetCacheNextQuery === true) {
phrasea_clear_cache($this->app['session']->get('phrasea_session_id'));
$this->addQuery($query);
$this->executeQuery($query);
$this->addQuery($query, $options);
$this->executeQuery($query, $options);
$sql = 'SELECT query, query_time, duration, total FROM cache WHERE session_id = :ses_id';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
@@ -534,13 +512,13 @@ class PhraseaEngine implements SearchEngineInterface
* @param string $query
* @return PhraseaEngine
*/
private function executeQuery($query)
private function executeQuery($query, SearchEngineOptions $options)
{
$nbanswers = $total_time = 0;
$sort = '';
if ($this->options->getSortBy()) {
switch ($this->options->getSortOrder()) {
if ($options->getSortBy()) {
switch ($options->getSortOrder()) {
case SearchEngineOptions::SORT_MODE_ASC:
$sort = '+';
break;
@@ -549,13 +527,13 @@ class PhraseaEngine implements SearchEngineInterface
$sort = '-';
break;
}
$sort .= '0' . $this->options->getSortBy();
$sort .= '0' . $options->getSortBy();
}
foreach ($this->queries as $sbas_id => $qry) {
$BF = [];
foreach ($this->options->getBusinessFieldsOn() as $collection) {
foreach ($options->getBusinessFieldsOn() as $collection) {
// limit business field query to databox local collection
if ($sbas_id === $collection->get_sbas_id()) {
$BF[] = $collection->get_base_id();
@@ -570,10 +548,10 @@ class PhraseaEngine implements SearchEngineInterface
, $this->app['conf']->get(['main', 'key'])
, $this->app['session']->get('usr_id')
, false
, $this->options->getSearchType() == SearchEngineOptions::RECORD_GROUPING ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY
, $options->getSearchType() == SearchEngineOptions::RECORD_GROUPING ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY
, $sort
, $BF
, $this->options->isStemmed() ? $this->options->getLocale() : null
, $options->isStemmed() ? $options->getLocale() : null
);
if ($results) {
@@ -603,7 +581,7 @@ class PhraseaEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function autocomplete($query)
public function autocomplete($query, SearchEngineOptions $options)
{
return new ArrayCollection();
}
@@ -611,8 +589,12 @@ class PhraseaEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function excerpt($query, $fields, \record_adapter $record)
public function excerpt($query, $fields, \record_adapter $record, SearchEngineOptions $options = null)
{
if (null === $options) {
$options = new SearchEngineOptions();
}
$ret = [];
$this->initialize();
@@ -670,13 +652,13 @@ class PhraseaEngine implements SearchEngineInterface
* @param string $query
* @return PhraseaEngine
*/
private function addQuery($query)
private function addQuery($query, SearchEngineOptions $options)
{
foreach ($this->options->getDataboxes() as $databox) {
foreach ($options->getDataboxes() as $databox) {
$this->queries[$databox->get_sbas_id()] = $query;
}
$status = $this->options->getStatus();
$status = $options->getStatus();
foreach ($this->queries as $sbas => $qs) {
if ($status) {
@@ -704,32 +686,32 @@ class PhraseaEngine implements SearchEngineInterface
$this->queries[$sbas] .= ' AND (recordstatus=' . $requestStat . ')';
}
}
if ($this->options->getFields()) {
if ($options->getFields()) {
$this->queries[$sbas] .= ' IN (' . implode(' OR ', array_map(function (\databox_field $field) {
return $field->get_name();
}, $this->options->getFields())) . ')';
}, $options->getFields())) . ')';
}
if (($this->options->getMinDate() || $this->options->getMaxDate()) && $this->options->getDateFields()) {
if ($this->options->getMinDate()) {
$this->queries[$sbas] .= ' AND ( ' . implode(' >= ' . $this->options->getMinDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $this->options->getDateFields())) . ' >= ' . $this->options->getMinDate()->format('Y-m-d') . ' ) ';
if (($options->getMinDate() || $options->getMaxDate()) && $options->getDateFields()) {
if ($options->getMinDate()) {
$this->queries[$sbas] .= ' AND ( ' . implode(' >= ' . $options->getMinDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $options->getDateFields())) . ' >= ' . $options->getMinDate()->format('Y-m-d') . ' ) ';
}
if ($this->options->getMaxDate()) {
$this->queries[$sbas] .= ' AND ( ' . implode(' <= ' . $this->options->getMaxDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $this->options->getDateFields())) . ' <= ' . $this->options->getMaxDate()->format('Y-m-d') . ' ) ';
if ($options->getMaxDate()) {
$this->queries[$sbas] .= ' AND ( ' . implode(' <= ' . $options->getMaxDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $options->getDateFields())) . ' <= ' . $options->getMaxDate()->format('Y-m-d') . ' ) ';
}
}
}
$this->singleParse('main', $query);
$this->singleParse('main', $query, $options);
foreach ($this->queries as $sbas => $db_query) {
$this->singleParse($sbas, $this->queries[$sbas]);
$this->singleParse($sbas, $this->queries[$sbas], $options);
}
$base_ids = array_map(function (\collection $collection) {
return $collection->get_base_id();
}, $this->options->getCollections());
}, $options->getCollections());
foreach ($this->options->getDataboxes() as $databox) {
foreach ($options->getDataboxes() as $databox) {
$sbas_id = $databox->get_sbas_id();
$this->colls[$sbas_id] = [];
@@ -771,9 +753,9 @@ class PhraseaEngine implements SearchEngineInterface
* @param string $query
* @return PhraseaEngine
*/
private function singleParse($sbas, $query)
private function singleParse($sbas, $query, SearchEngineOptions $options)
{
$this->qp[$sbas] = new PhraseaEngineQueryParser($this->app, $this->options->getLocale());
$this->qp[$sbas] = new PhraseaEngineQueryParser($this->app, $options->getLocale());
$this->qp[$sbas]->debug = false;
$simple_treeq = $this->qp[$sbas]->parsequery($query);

View File

@@ -162,32 +162,16 @@ interface SearchEngineInterface
*/
public function updateFeedEntry(FeedEntry $entry);
/**
* Set options to search-engine
*
* @param SearchEngineOptions $options
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function setOptions(SearchEngineOptions $options);
/**
* Reset search-engine options
*
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function resetOptions();
/**
*
* @param string $query
* @param integer $offset
* @param integer $perPage
* @param SearchEngineOptions $options
*
* @return SearchEngineResult
*/
public function query($query, $offset, $perPage);
public function query($query, $offset, $perPage, SearchEngineOptions $options = null);
/**
* Return an array of suggestions corresponding to the last word of the
@@ -197,7 +181,7 @@ interface SearchEngineInterface
*
* @return ArrayCollection A collection of SearchEngineSuggestion
*/
public function autocomplete($query);
public function autocomplete($query, SearchEngineOptions $options);
/**
* Highlight the fields of a record
@@ -208,7 +192,7 @@ interface SearchEngineInterface
*
* @return array The array of highlighted fields
*/
public function excerpt($query, $fields, \record_adapter $record);
public function excerpt($query, $fields, \record_adapter $record, SearchEngineOptions $options = null);
/**
* Reset the cache of the SE (if applicable)

View File

@@ -44,13 +44,11 @@ class SphinxSearchEngine implements SearchEngineInterface
private $dateFields;
protected $configuration;
protected $configurationPanel;
protected $options;
protected $app;
public function __construct(Application $app, $host, $port, $rt_host, $rt_port)
{
$this->app = $app;
$this->options = new SearchEngineOptions();
$this->sphinx = new \SphinxClient();
$this->sphinx->SetServer($host, $port);
@@ -417,28 +415,6 @@ class SphinxSearchEngine implements SearchEngineInterface
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
}
/**
* {@inheritdoc}
*/
public function setOptions(SearchEngineOptions $options)
{
$this->options = $options;
$this->applyOptions($options);
return $this;
}
/**
* {@inheritdoc}
*/
public function resetOptions()
{
$this->options = new SearchEngineOptions();
$this->resetSphinx();
return $this;
}
private function resetSphinx()
{
$this->sphinx->ResetGroupBy();
@@ -450,8 +426,14 @@ class SphinxSearchEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function query($query, $offset, $perPage)
public function query($query, $offset, $perPage, SearchEngineOptions $options = null)
{
if (null === $options) {
$options = new SearchEngineOptions();
}
$this->applyOptions($options);
assert(is_int($offset));
assert($offset >= 0);
assert(is_int($perPage));
@@ -468,7 +450,7 @@ class SphinxSearchEngine implements SearchEngineInterface
$this->sphinx->SetLimits($offset, $perPage);
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$index = $this->getQueryIndex($query);
$index = $this->getQueryIndex($query, $options);
$res = $this->sphinx->Query($query, $index);
$results = new ArrayCollection();
@@ -513,7 +495,7 @@ class SphinxSearchEngine implements SearchEngineInterface
}
}
$suggestions = $this->getSuggestions($query);
$suggestions = $this->getSuggestions($query, $options);
$propositions = '';
}
@@ -523,29 +505,37 @@ class SphinxSearchEngine implements SearchEngineInterface
/**
* {@inheritdoc}
*/
public function autocomplete($query)
public function autocomplete($query, SearchEngineOptions $options)
{
$this->applyOptions($options);
$words = explode(" ", $this->cleanupQuery($query));
return $this->getSuggestions(array_pop($words));
return $this->getSuggestions(array_pop($words), $options);
}
/**
* {@inheritdoc}
*/
public function excerpt($query, $fields, \record_adapter $record)
public function excerpt($query, $fields, \record_adapter $record, SearchEngineOptions $options = null)
{
if (null === $options) {
$options = new SearchEngineOptions();
}
$this->applyOptions($options);
$index = '';
// in this case search is done on metas
if ($this->options->getFields() || $this->options->getBusinessFieldsOn()) {
if ($this->options->isStemmed() && $this->options->getLocale()) {
$index = 'metadatas' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $this->options->getLocale();
if ($options->getFields() || $options->getBusinessFieldsOn()) {
if ($options->isStemmed() && $options->getLocale()) {
$index = 'metadatas' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $options->getLocale();
} else {
$index = 'metadatas' . $this->CRCdatabox($record->get_databox());
}
} else {
if ($this->options->isStemmed() && $this->options->getLocale()) {
$index = 'documents' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $this->options->getLocale();
if ($options->isStemmed() && $options->getLocale()) {
$index = 'documents' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $options->getLocale();
} else {
$index = 'documents' . $this->CRCdatabox($record->get_databox());
}
@@ -775,7 +765,7 @@ class SphinxSearchEngine implements SearchEngineInterface
* @param string $query
* @return ArrayCollection An array collection of SearchEngineSuggestion
*/
private function getSuggestions($query)
private function getSuggestions($query, SearchEngineOptions $options)
{
// First we split the query into simple words
$words = explode(" ", $this->cleanupQuery(mb_strtolower($query)));
@@ -798,10 +788,10 @@ class SphinxSearchEngine implements SearchEngineInterface
}
// As we got words, we look for alternate word for each of them
if (function_exists('enchant_broker_init') && $this->options->getLocale()) {
if (function_exists('enchant_broker_init') && $options->getLocale()) {
$broker = enchant_broker_init();
if (enchant_broker_dict_exists($broker, $this->options->getLocale())) {
$dictionnary = enchant_broker_request_dict($broker, $this->options->getLocale());
if (enchant_broker_dict_exists($broker, $options->getLocale())) {
$dictionnary = enchant_broker_request_dict($broker, $options->getLocale());
foreach ($words as $word) {
@@ -820,7 +810,7 @@ class SphinxSearchEngine implements SearchEngineInterface
* @todo enhance the trigramm query, as it could be sent in one batch
*/
foreach ($altVersions as $word => $versions) {
$altVersions[$word] = array_unique(array_merge($versions, $this->get_sugg_trigrams($word)));
$altVersions[$word] = array_unique(array_merge($versions, $this->get_sugg_trigrams($word, $options)));
}
// We now build an array of all possibilities based on the original query
@@ -842,7 +832,7 @@ class SphinxSearchEngine implements SearchEngineInterface
$max_results = 0;
foreach ($queries as $alt_query) {
$results = $this->sphinx->Query($alt_query, $this->getQueryIndex($alt_query));
$results = $this->sphinx->Query($alt_query, $this->getQueryIndex($alt_query, $options));
if ($results !== false && isset($results['total_found'])) {
if ($results['total_found'] > 0) {
@@ -886,7 +876,7 @@ class SphinxSearchEngine implements SearchEngineInterface
return $trigrams;
}
private function get_sugg_trigrams($word)
private function get_sugg_trigrams($word, SearchEngineOptions $options)
{
$trigrams = $this->BuildTrigrams($word);
$query = "\"$trigrams\"/1";
@@ -903,7 +893,7 @@ class SphinxSearchEngine implements SearchEngineInterface
$indexes = [];
foreach ($this->options->getDataboxes() as $databox) {
foreach ($options->getDataboxes() as $databox) {
$indexes[] = 'suggest' . $this->CRCdatabox($databox);
}
@@ -926,29 +916,29 @@ class SphinxSearchEngine implements SearchEngineInterface
return $words;
}
private function getQueryIndex($query)
private function getQueryIndex($query, SearchEngineOptions $options)
{
$index = '*';
$index_keys = [];
foreach ($this->options->getDataboxes() as $databox) {
foreach ($options->getDataboxes() as $databox) {
$index_keys[] = $this->CRCdatabox($databox);
}
if (count($index_keys) > 0) {
if ($this->options->getFields() || $this->options->getBusinessFieldsOn()) {
if ($query !== '' && $this->options->isStemmed() && $this->options->getLocale()) {
$index = 'metadatas' . implode('_stemmed_' . $this->options->getLocale() . ', metadatas', $index_keys) . '_stemmed_' . $this->options->getLocale();
$index .= ', metas_realtime_stemmed_' . $this->options->getLocale() . '_' . implode(', metas_realtime_stemmed_' . $this->options->getLocale() . '_', $index_keys);
if ($options->getFields() || $options->getBusinessFieldsOn()) {
if ($query !== '' && $options->isStemmed() && $options->getLocale()) {
$index = 'metadatas' . implode('_stemmed_' . $options->getLocale() . ', metadatas', $index_keys) . '_stemmed_' . $options->getLocale();
$index .= ', metas_realtime_stemmed_' . $options->getLocale() . '_' . implode(', metas_realtime_stemmed_' . $options->getLocale() . '_', $index_keys);
} else {
$index = 'metadatas' . implode(',metadatas', $index_keys);
$index .= ', metas_realtime' . implode(', metas_realtime', $index_keys);
}
} else {
if ($query !== '' && $this->options->isStemmed() && $this->options->getLocale()) {
$index = 'documents' . implode('_stemmed_' . $this->options->getLocale() . ', documents', $index_keys) . '_stemmed_' . $this->options->getLocale();
$index .= ', docs_realtime_stemmed_' . $this->options->getLocale() . '_' . implode(', docs_realtime_stemmed_' . $this->options->getLocale() . '_', $index_keys);
if ($query !== '' && $options->isStemmed() && $options->getLocale()) {
$index = 'documents' . implode('_stemmed_' . $options->getLocale() . ', documents', $index_keys) . '_stemmed_' . $options->getLocale();
$index .= ', docs_realtime_stemmed_' . $options->getLocale() . '_' . implode(', docs_realtime_stemmed_' . $options->getLocale() . '_', $index_keys);
} else {
$index = 'documents' . implode(', documents', $index_keys);
$index .= ', docs_realtime' . implode(', docs_realtime', $index_keys);
@@ -1079,5 +1069,4 @@ class SphinxSearchEngine implements SearchEngineInterface
{
return $this;
}
}

View File

@@ -870,11 +870,9 @@ class API_V1_adapter extends API_V1_Abstract
$perPage = (int) $request->get('per_page') ? : 10;
$query = (string) $request->get('query');
$this->app['phraseanet.SE']->setOptions($options);
$this->app['phraseanet.SE']->resetCache();
$search_result = $this->app['phraseanet.SE']->query($query, $offsetStart, $perPage);
$search_result = $this->app['phraseanet.SE']->query($query, $offsetStart, $perPage, $options);
$userQuery = new UserQuery();
$userQuery->setUsrId($this->app['authentication']->getUser()->get_id());

View File

@@ -11,11 +11,12 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
interface caption_interface
{
public function __construct(Application $app, record_Interface $record, databox $databox);
public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null);
public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null);
}

View File

@@ -11,6 +11,7 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Symfony\Component\Yaml\Dumper as YamlDumper;
class caption_record implements caption_interface, cache_cacheableInterface
@@ -284,9 +285,9 @@ class caption_record implements caption_interface, cache_cacheableInterface
*
* @return array
*/
public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false)
public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null)
{
return $this->highlight_fields($highlight, $grep_fields, $searchEngine, $includeBusiness);
return $this->highlight_fields($highlight, $grep_fields, $searchEngine, $includeBusiness, $options);
}
/**
@@ -296,7 +297,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @param SearchEngineInterface $searchEngine
* @return array
*/
protected function highlight_fields($highlight, Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false)
protected function highlight_fields($highlight, Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null)
{
$fields = [];
@@ -317,7 +318,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
}
if ($searchEngine instanceof SearchEngineInterface) {
$ret = $searchEngine->excerpt($highlight, $fields, $this->record);
$ret = $searchEngine->excerpt($highlight, $fields, $this->record, $options);
if ($ret) {
$n = -1;

View File

@@ -14,6 +14,7 @@ use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Metadata\Tag\TfFilename;
use Alchemy\Phrasea\Metadata\Tag\TfBasename;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Doctrine\ORM\EntityManager;
use MediaAlchemyst\Specification\SpecificationInterface;
use MediaVorus\Media\MediaInterface;
@@ -871,7 +872,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*
* @return string
*/
public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null)
public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null, SearchEngineOptions $options = null)
{
$cache = !$highlight && !$searchEngine && !$removeExtension;
@@ -896,7 +897,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
}
if (count($fields_to_retrieve) > 0) {
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine);
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine, false, $options);
$titles = [];
foreach ($retrieved_fields as $key => $value) {
if (trim($value['value'] === ''))

View File

@@ -13,6 +13,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Basket;
use Alchemy\Phrasea\Model\Entities\BasketElement;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
class record_preview extends record_adapter
{
@@ -89,7 +90,7 @@ class record_preview extends record_adapter
*
* @return record_preview
*/
public function __construct(Application $app, $env, $pos, $contId, SearchEngineInterface $search_engine = null, $query = '')
public function __construct(Application $app, $env, $pos, $contId, SearchEngineInterface $search_engine = null, $query = '', SearchEngineOptions $options = null)
{
$number = null;
$this->env = $env;
@@ -101,7 +102,7 @@ class record_preview extends record_adapter
throw new \LogicException('Search Engine should be provided');
}
$results = $search_engine->query($query, (int) ($pos), 1);
$results = $search_engine->query($query, (int) ($pos), 1, $options);
if ($results->getResults()->isEmpty()) {
throw new Exception('Record introuvable');

View File

@@ -12,15 +12,15 @@
{% endif %}
{% if view == 'answer' %}
{{cap_ans.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
{{cap_ans.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}}
{% elseif view == 'lazaret' %}
{{cap_laz.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
{{cap_laz.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}}
{% elseif view == 'preview' %}
{{cap_prev.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
{{cap_prev.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}}
{% elseif view == 'basket' %}
{{cap_bas.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
{{cap_bas.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}}
{% elseif view == 'overview' %}
{{cap_ovr.format_caption(record, highlight|default(''), searchEngine|default(null), business)}}
{{cap_ovr.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}}
{% elseif view == 'publi' %}
{{cap_pub.format_caption(record, '', null, business)}}
{{cap_pub.format_caption(record, '', null, null, business)}}
{% endif %}

View File

@@ -1,5 +1,5 @@
{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}
<div class="desc{% if loop.index is odd %}im{% endif %}pair"><b>{{ value.label }}</b> : {{ value.value | thesaurus }}</div>
{% endfor %}
{% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}

View File

@@ -1,5 +1,5 @@
{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}
<div class="desc{% if loop.index is odd %}im{% endif %}pair"><b>{{ value.label }}</b> : {{ value.value | thesaurus }}</div>
{% endfor %}
{% endmacro %}

View File

@@ -1,5 +1,5 @@
{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}
<div class="desc{% if loop.index is odd %}im{% endif %}pair"><b>{{ value.label }}</b> : {{ value.value | thesaurus }}</div>
{% endfor %}
{% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}

View File

@@ -1,5 +1,5 @@
{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}
<div class="desc{% if loop.index is odd %}im{% endif %}pair"><b>{{ value.label }}</b> : {{ value.value | thesaurus }}</div>
{% endfor %}
{% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}

View File

@@ -1,5 +1,5 @@
{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}
<div><b>{{ value.label }}</b> : {{ value.value }}</div>
{% endfor %}
{% endmacro %}

View File

@@ -1,5 +1,5 @@
{% macro format_caption(record, highlight, searchEngine, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %}
{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %}
{% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}
<div class="desc{% if loop.index is odd %}im{% endif %}pair"><b>{{ value.label }}</b> : {{ value.value | thesaurus }}</div>
{% endfor %}
{% endmacro %}

View File

@@ -83,7 +83,7 @@
<div class="lightbox_container">
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(first_item.getRecord(app).get_base_id(), 'canmodifrecord') %}
{% if first_item %}
{{caption.format_caption(first_item.getRecord(app), '', null, business)}}
{{caption.format_caption(first_item.getRecord(app), '', null, null, business)}}
{% endif %}
</div>
</div>

View File

@@ -95,7 +95,7 @@
<div class="lightbox_container">
{% if basket_element %}
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
{{caption.format_caption(basket_element.getRecord(app), '', null, business)}}
{{caption.format_caption(basket_element.getRecord(app), '', null, null, business)}}
{% endif %}
</div>
</div>

View File

@@ -83,7 +83,7 @@
<div class="lightbox_container PNB">
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(first_item.getRecord(app).get_base_id(), 'canmodifrecord') %}
{% if first_item %}
{{caption.format_caption(first_item.getRecord(app), '', null, business)}}
{{caption.format_caption(first_item.getRecord(app), '', null, null, business)}}
{% endif %}
</div>
</div>

View File

@@ -98,7 +98,7 @@
<div class="lightbox_container PNB">
{% if basket_element %}
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
{{caption.format_caption(basket_element.getRecord(app), '', null, business)}}
{{caption.format_caption(basket_element.getRecord(app), '', null, null, business)}}
{% endif %}
</div>
</div>

View File

@@ -13,9 +13,9 @@
</div>
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
{% if record.is_from_reg() %}
{{caption.format_caption(record, '', null, business)}}
{{caption.format_caption(record, '', null, null, business)}}
{% else %}
{{caption.format_caption(record, highlight, searchEngine, business)}}
{{caption.format_caption(record, highlight, searchEngine, searchOptions, business)}}
{% endif %}
<hr style="margin:10px 0;"/>
{% include 'common/technical_datas.html.twig' %}

View File

@@ -15,7 +15,7 @@
<div class='desc' style='max-height:{{th_size+70}}px;overflow-y:auto;'>
<div class="fixeddesc">
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
{{caption.format_caption(record, highlight, searchEngine, business)}}
{{caption.format_caption(record, highlight, searchEngine, searchOptions, business)}}
{% if app['authentication'].getUser().getPrefs('technical_display') == 'group' %}<hr/>{{record.get_technical_infos|raw}}{% endif %}
</div>
</div>

View File

@@ -47,8 +47,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options->onCollections($databox->get_collections());
$this->options = $options;
self::$searchEngine->setOptions($options);
}
public static function tearDownAfterClass()
@@ -74,7 +72,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(1, $results->getTotal());
$result = $results->getResults()->first();
@@ -92,7 +90,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(1, $results->getTotal());
$result = $results->getResults()->first();
@@ -120,17 +118,15 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options = $this->getOptions();
$options->setDateFields([$date_field]);
$options->setMinDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-23 01:01:00'));
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
$options->setMinDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-20 01:01:00'));
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -191,17 +187,15 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options = $this->getOptions();
$options->setDateFields([$date_field]);
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-20 01:01:00'));
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-23 01:01:00'));
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -225,17 +219,15 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options->setDateFields([$date_field]);
$options->setMinDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-18 01:01:00'));
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-20 01:01:00'));
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
$options->setMaxDate(\DateTime::createFromFormat('Y-m-d H:i:s', '2012-12-22 01:01:00'));
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -279,7 +271,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->editRecord($query_string, $record);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(0, $results->getTotal());
}
@@ -294,7 +286,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(1, $results->getTotal());
}
@@ -313,7 +305,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(1, $results->getTotal());
}
@@ -345,7 +337,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options = $this->getDefaultOptions();
$options->setStemming(true);
$options->setLocale($language);
self::$searchEngine->setOptions($options);
$record = self::$DI['record_2'];
$index_string = sprintf(
@@ -367,7 +358,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex([$language]);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -410,13 +401,11 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$field = $this->editRecord($query_string, $record);
$options->setFields([$field]);
self::$searchEngine->setOptions($options);
self::$searchEngine->addRecord($record);
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -429,13 +418,12 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->editRecord($query_string, $record, true, true);
$options->allowBusinessFieldsOn([$record->get_collection()]);
self::$searchEngine->setOptions($options);
self::$searchEngine->addRecord($record);
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -450,7 +438,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(0, $results->getTotal());
}
@@ -474,9 +462,8 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
self::$searchEngine->addRecord($record);
$this->updateIndex();
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
}
@@ -494,7 +481,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(0, $results->getTotal());
}
@@ -511,15 +498,14 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(0, $results->getTotal());
$options = $this->getDefaultOptions();
$options->setFields([$field]);
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
}
@@ -536,8 +522,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options->setStemming(true);
$options->setLocale($language);
self::$searchEngine->setOptions($options);
$field = $this->editRecord($index_string, $record);
self::$searchEngine->addRecord($record);
@@ -546,14 +530,13 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
$options->setFields([$field]);
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
}
@@ -587,15 +570,13 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options = $this->getDefaultOptions();
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
self::$searchEngine->setOptions($options);
$this->editRecord($query_string, $story);
self::$searchEngine->addStory($story);
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -606,8 +587,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$options = $this->getDefaultOptions();
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
self::$searchEngine->setOptions($options);
self::$searchEngine->addStory($story);
$this->updateIndex();
@@ -618,7 +597,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -635,10 +614,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
}
@@ -650,7 +628,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$record->set_binary_status('10000');
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
self::$searchEngine->setOptions($options);
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOnOverOn';
$this->editRecord($query_string, $record);
@@ -659,7 +636,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -671,7 +648,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$record->set_binary_status('10000');
$options->setStatus([4 => ['off' => [$record->get_databox()->get_sbas_id()]]]);
self::$searchEngine->setOptions($options);
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
$this->editRecord($query_string, $record);
@@ -680,7 +656,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
}
@@ -692,7 +668,6 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$record->set_binary_status('00000');
$options->setStatus([4 => ['off' => [$record->get_databox()->get_sbas_id()]]]);
self::$searchEngine->setOptions($options);
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
$this->editRecord($query_string, $record);
@@ -701,7 +676,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(1, $results->getTotal());
}
@@ -718,10 +693,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
self::$searchEngine->setOptions($options);
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $options);
$this->assertEquals(0, $results->getTotal());
$record->set_binary_status('10000');
@@ -730,7 +704,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$this->assertEquals(1, $results->getTotal());
}
@@ -745,7 +719,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
$this->updateIndex();
self::$searchEngine->resetCache();
$results = self::$searchEngine->query($query_string, 0, 1);
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
$fields = [];
$foundRecord = $results->getResults()->first();
@@ -759,7 +733,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
}
$found = false;
foreach (self::$searchEngine->excerpt($query_string, $fields, $foundRecord) as $field) {
foreach (self::$searchEngine->excerpt($query_string, $fields, $foundRecord, $this->options) as $field) {
if (strpos($field, '[[em]]') !== false && strpos($field, '[[/em]]') !== false) {
$found = true;
break;

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine;
use Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Alchemy\Tests\Phrasea\SearchEngine\SearchEngineAbstractTest;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
@@ -150,7 +151,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
$process->run();
usleep(500000);
$suggestions = self::$searchEngine->autocomplete('jean');
$suggestions = self::$searchEngine->autocomplete('jean', $this->options);
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $suggestions);
$this->assertGreaterThan(2, count($suggestions));