mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00

Conflicts: composer.json composer.lock config/configuration.sample.yml lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Application/Api.php lib/Alchemy/Phrasea/Controller/Admin/Collection.php lib/Alchemy/Phrasea/Controller/Admin/Users.php lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php lib/Alchemy/Phrasea/Controller/Prod/Export.php lib/Alchemy/Phrasea/Controller/Prod/Language.php lib/Alchemy/Phrasea/Controller/Prod/Push.php lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php lib/Alchemy/Phrasea/Controller/Report/Informations.php lib/Alchemy/Phrasea/Controller/Report/Root.php lib/Alchemy/Phrasea/Controller/Root/Developers.php lib/Alchemy/Phrasea/Controller/Root/Login.php lib/Alchemy/Phrasea/Controller/Root/Session.php lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php lib/Alchemy/Phrasea/Controller/Utils/ConnectionTest.php lib/Alchemy/Phrasea/Controller/Utils/PathFileTest.php lib/Alchemy/Phrasea/Core/Version.php lib/Alchemy/Phrasea/Form/Login/PhraseaAuthenticationForm.php lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php lib/classes/API/OAuth2/Application.php lib/classes/API/V1/adapter.php lib/classes/Feed/Adapter.php lib/classes/Feed/Aggregate.php lib/classes/Feed/Collection.php lib/classes/Feed/Entry/Adapter.php lib/classes/ZipArchiveImproved.php lib/classes/caption/Field/Value.php lib/classes/caption/record.php lib/classes/eventsmanager/notify/feed.php lib/classes/media/subdef.php lib/classes/module/report/connexion.php lib/classes/module/report/download.php lib/classes/record/adapter.php lib/classes/registry.php lib/classes/set/export.php lib/classes/setup.php lib/classes/task/abstract.php lib/classes/task/period/emptyColl.php lib/classes/uuid.php lib/conf.d/_GV_template.inc lib/conf.d/bases_structure.xml lib/conf.d/configuration.yml lib/conf.d/minifyGroupsConfig.php locale/de_DE/LC_MESSAGES/phraseanet.mo locale/de_DE/LC_MESSAGES/phraseanet.po locale/en_GB/LC_MESSAGES/phraseanet.mo locale/en_GB/LC_MESSAGES/phraseanet.po locale/fr_FR/LC_MESSAGES/phraseanet.mo locale/fr_FR/LC_MESSAGES/phraseanet.po locale/nl_NL/LC_MESSAGES/phraseanet.mo locale/nl_NL/LC_MESSAGES/phraseanet.po locale/phraseanet.pot templates/web/account/account.html.twig templates/web/account/base.html.twig templates/web/admin/databox/databox.html.twig templates/web/admin/index.html.twig templates/web/admin/setup.html.twig templates/web/admin/tree.html.twig templates/web/client/index.html.twig templates/web/common/caption.html.twig templates/web/common/caption_templates/answer.html.twig templates/web/common/caption_templates/basket_element.html.twig templates/web/common/caption_templates/internal_publi.html.twig templates/web/common/caption_templates/lazaret.html.twig templates/web/common/caption_templates/overview.html.twig templates/web/common/caption_templates/preview.html.twig templates/web/common/index_bootstrap.html.twig templates/web/common/indexfloat.html.twig templates/web/common/thumbnail.html.twig templates/web/developers/application_form.html.twig templates/web/lightbox/IE6/feed.html.twig templates/web/lightbox/IE6/validate.html.twig templates/web/lightbox/feed.html.twig templates/web/lightbox/validate.html.twig templates/web/prod/actions/Download/prepare.html.twig templates/web/prod/actions/publish/publish.html.twig templates/web/prod/index.html.twig templates/web/prod/preview/caption.html.twig templates/web/prod/results/answerlist.html.twig templates/web/thesaurus/accept.html.twig templates/web/thesaurus/export-text-dialog.html.twig templates/web/thesaurus/export-text.html.twig templates/web/thesaurus/export-topics-dialog.html.twig templates/web/thesaurus/export-topics.html.twig templates/web/thesaurus/index.html.twig templates/web/thesaurus/link-field-step1.html.twig templates/web/thesaurus/link-field-step2.html.twig templates/web/thesaurus/link-field-step3.html.twig templates/web/thesaurus/new-term.html.twig templates/web/thesaurus/properties.html.twig templates/web/thesaurus/search.html.twig templates/web/thesaurus/thesaurus.html.twig tests/Alchemy/Tests/Phrasea/Application/ApiJsonTest.php tests/Alchemy/Tests/Phrasea/Application/ApiYamlTest.php tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php tests/Alchemy/Tests/Phrasea/Application/OAuth2Test.php tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php tests/Alchemy/Tests/Phrasea/Authentication/PersistentCookie/ManagerTest.php tests/Alchemy/Tests/Phrasea/Cache/RedisCacheTest.php tests/Alchemy/Tests/Phrasea/Command/Compile/ConfigurationTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/SubdefsTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJSONPTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/BasketTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/BridgeTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/EditTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/MoveCollectionTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/PrinterTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/TooltipTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/UsrListsTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/WorkZoneTest.php tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php tests/Alchemy/Tests/Phrasea/Controller/Utils/PathFileTestTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/FTPServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/PhraseanetServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/TaskManagerServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Http/XSendFile/NginxModeTest.php tests/Alchemy/Tests/Phrasea/Metadata/Tag/TfEditDateTest.php tests/Alchemy/Tests/Phrasea/Metadata/Tag/TfMimeTypeTest.php tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php tests/classes/Feed/Feed_AggregateTest.php tests/classes/PhraseanetPHPUnitAbstract.php tests/db-ref.sqlite
779 lines
25 KiB
PHP
779 lines
25 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\SearchEngine;
|
|
|
|
use Alchemy\Phrasea\Application;
|
|
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
|
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
|
|
|
|
abstract class SearchEngineAbstractTest extends \PhraseanetAuthenticatedTestCase
|
|
{
|
|
protected $options;
|
|
protected static $searchEngine;
|
|
protected static $searchEngineClass;
|
|
private static $initialized = false;
|
|
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
|
|
if (!self::$initialized) {
|
|
$found = false;
|
|
foreach (self::$DI['record_2']->get_databox()->get_meta_structure()->get_elements() as $field) {
|
|
if (!$field->isBusiness()) {
|
|
continue;
|
|
}
|
|
$found = true;
|
|
}
|
|
|
|
if (!$found) {
|
|
$field = \databox_field::create(self::$DI['app'], self::$DI['record_2']->get_databox(), 'testBusiness' . mt_rand(), false);
|
|
$field->set_business(true);
|
|
$field->save();
|
|
}
|
|
|
|
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
$this->initialize();
|
|
|
|
if (!self::$searchEngine instanceof SearchEngineInterface) {
|
|
$this->markTestSkipped('Unable to initialize search Engine');
|
|
}
|
|
|
|
self::$DI['app']['phraseanet.SE'] = self::$searchEngine;
|
|
self::$DI['app']['phraseanet.SE.subscriber'] = self::$searchEngine->createSubscriber(self::$DI['app']);
|
|
|
|
$options = new SearchEngineOptions();
|
|
$options->onCollections($databox->get_collections());
|
|
|
|
$this->options = $options;
|
|
}
|
|
|
|
public static function tearDownAfterClass()
|
|
{
|
|
self::$searchEngine = self::$searchEngineClass = self::$initialized = null;
|
|
parent::tearDownAfterClass();
|
|
}
|
|
|
|
/**
|
|
* @return SearchEngineOptions
|
|
*/
|
|
private function getOptions()
|
|
{
|
|
return $this->options;
|
|
}
|
|
|
|
public function testQueryRecordId()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'recordid=' . $record->get_record_id();
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
|
|
$result = $results->getResults()->first();
|
|
|
|
$this->assertEquals($record->get_record_id(), $result->get_record_id());
|
|
$this->assertEquals($record->get_sbas_id(), $result->get_sbas_id());
|
|
}
|
|
|
|
public function testQueryStoryId()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'storyid=' . $record->get_record_id();
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
|
|
$result = $results->getResults()->first();
|
|
|
|
$this->assertEquals($record->get_record_id(), $result->get_record_id());
|
|
$this->assertEquals($record->get_sbas_id(), $result->get_sbas_id());
|
|
}
|
|
|
|
public function testQueryByDateMin()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'dateMin';
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
$date_field = $this->editDateRecord('2012-12-21 12:12:00', $record);
|
|
|
|
if (!$date_field) {
|
|
$this->markTestSkipped('unable to add a date to record');
|
|
}
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
$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->resetCache();
|
|
$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->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
private function editDateRecord($date, \record_adapter $record)
|
|
{
|
|
$date_field = null;
|
|
|
|
foreach ($record->get_databox()->get_meta_structure() as $databox_field) {
|
|
if ($databox_field->get_type() != \databox_field::TYPE_DATE) {
|
|
continue;
|
|
}
|
|
|
|
$date_field = $databox_field;
|
|
|
|
break;
|
|
}
|
|
|
|
if ($date_field) {
|
|
|
|
$toupdate = [];
|
|
|
|
try {
|
|
$values = $record->get_caption()->get_field($databox_field->get_name())->get_values();
|
|
$value = array_pop($values);
|
|
$meta_id = $value->getId();
|
|
} catch (\Exception $e) {
|
|
$meta_id = null;
|
|
}
|
|
|
|
$toupdate[$databox_field->get_id()] = [
|
|
'meta_id' => $meta_id
|
|
, 'meta_struct_id' => $databox_field->get_id()
|
|
, 'value' => $date
|
|
];
|
|
|
|
$record->set_metadatas($toupdate);
|
|
}
|
|
|
|
return $date_field;
|
|
}
|
|
|
|
public function testQueryByDateMax()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'dateMax';
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
$date_field = $this->editDateRecord('2012-12-21 12:12:00', $record);
|
|
|
|
if (!$date_field) {
|
|
$this->markTestSkipped('unable to add a date to record');
|
|
}
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
$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->resetCache();
|
|
$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->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testQueryByDateRange()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'dateRange';
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
$date_field = $this->editDateRecord('2012-12-21 12:12:00', $record);
|
|
|
|
if (!$date_field) {
|
|
$this->markTestSkipped('unable to add a date to record');
|
|
}
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
$options = $this->getOptions();
|
|
$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->resetCache();
|
|
$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->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
protected function editRecord($string2add, \record_adapter &$record, $indexable = true, $business = false)
|
|
{
|
|
$toupdate = [];
|
|
$field = null;
|
|
|
|
foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
|
|
|
|
if ($indexable !== $field->is_indexable() || $field->isBusiness() !== $business) {
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
$values = $record->get_caption()->get_field($field->get_name())->get_values();
|
|
$value = array_pop($values);
|
|
$meta_id = $value->getId();
|
|
} catch (\Exception $e) {
|
|
$meta_id = null;
|
|
}
|
|
|
|
$toupdate[$field->get_id()] = [
|
|
'meta_id' => $meta_id
|
|
, 'meta_struct_id' => $field->get_id()
|
|
, 'value' => $string2add
|
|
];
|
|
break;
|
|
}
|
|
|
|
$record->set_metadatas($toupdate);
|
|
|
|
return $field;
|
|
}
|
|
|
|
public function testRecordNotIndexed()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultNotIndexed';
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->resetCache();
|
|
$this->updateIndex();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testAddRecord()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultAdd';
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testUpdateRecord()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'updateRecord';
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->updateRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
protected function getDefaultOptions()
|
|
{
|
|
$appbox = self::$DI['app']['phraseanet.appbox'];
|
|
foreach ($appbox->get_databoxes() as $databox) {
|
|
break;
|
|
}
|
|
$options = new SearchEngineOptions();
|
|
$options->onCollections($databox->get_collections());
|
|
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideStemmData
|
|
*/
|
|
public function testUpdateRecordWithStemm($language, $word, $stemm)
|
|
{
|
|
if (!self::$searchEngine->hasStemming()) {
|
|
$this->markTestSkipped(sprintf(
|
|
'%s does not support stemm, passing stemmatization for language %s',
|
|
get_class(self::$searchEngine),
|
|
$language
|
|
));
|
|
}
|
|
|
|
$options = $this->getDefaultOptions();
|
|
$options->setStemming(true);
|
|
$options->setLocale($language);
|
|
|
|
$record = self::$DI['record_2'];
|
|
$index_string = sprintf(
|
|
'boomboklot%dstemmed%s %s',
|
|
$record->get_record_id(),
|
|
$language,
|
|
$word
|
|
);
|
|
$query_string = sprintf(
|
|
'boomboklot%dstemmed%s %s',
|
|
$record->get_record_id(),
|
|
$language,
|
|
$stemm
|
|
);
|
|
|
|
$this->editRecord($index_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex([$language]);
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function provideStemmData()
|
|
{
|
|
$stemms = [];
|
|
|
|
$examples = [
|
|
'fr' => ['word' => 'chevaux', 'stemm' => 'cheval'],
|
|
'en' => ['word' => 'consistency', 'stemm' => 'consistent'],
|
|
'de' => ['word' => 'aufeinanderfolgender', 'stemm' => 'aufeinanderfolg'],
|
|
'nl' => ['word' => 'lichamelijk', 'stemm' => 'licham'],
|
|
];
|
|
|
|
foreach (Application::getAvailableLanguages() as $languageCode => $name) {
|
|
$data = explode('_', $languageCode);
|
|
$code = $data[0];
|
|
|
|
if (!isset($examples[$code])) {
|
|
$this->fail(sprintf('Missing stemm examples for language %s', $code));
|
|
}
|
|
|
|
$stemms[] = [
|
|
$code,
|
|
$examples[$code]['word'],
|
|
$examples[$code]['stemm'],
|
|
];
|
|
}
|
|
|
|
return $stemms;
|
|
}
|
|
|
|
public function testUpdateQueryOnField()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
$record = self::$DI['record_2'];
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'onfield';
|
|
|
|
$field = $this->editRecord($query_string, $record);
|
|
$options->setFields([$field]);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testBusinessFieldAvailable()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
$record = self::$DI['record_2'];
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'businessAvailable';
|
|
|
|
$this->editRecord($query_string, $record, true, true);
|
|
$options->allowBusinessFieldsOn([$record->get_collection()]);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testBusinessFieldNotAvailable()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'businessNotAvailable';
|
|
|
|
$this->editRecord($query_string, $record, true, true);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
public function testUpdateQueryOnEmptyField()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'anotherfield';
|
|
|
|
$selectedField = $this->editRecord($query_string, $record);
|
|
|
|
foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
|
|
if ($selectedField->get_id() != $field->get_id()) {
|
|
$options->setFields([$field]);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
public function testUpdateNonIndexableRecord()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot_no_index_' . $record->get_record_id() . '_';
|
|
|
|
$field = $this->editRecord($query_string, $record, false);
|
|
if (!$field) {
|
|
$this->markTestSkipped('No non-indexable field found');
|
|
}
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
public function testDeleteRecord()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'deleteRecord';
|
|
|
|
$field = $this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
self::$searchEngine->removeRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
|
|
$options = $this->getDefaultOptions();
|
|
$options->setFields([$field]);
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideStemmData
|
|
*/
|
|
public function testDeleteRecordWithinStemmContext($language, $word, $stemm)
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$index_string = 'boomboklot' . $record->get_record_id() . 'deleteRecordInStemmContext '.$word;
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'deleteRecordInStemmContext '.$stemm;
|
|
|
|
$options = $this->getDefaultOptions();
|
|
$options->setStemming(true);
|
|
$options->setLocale($language);
|
|
|
|
$field = $this->editRecord($index_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
self::$searchEngine->removeRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
|
|
$options->setFields([$field]);
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
public function testAvailableTypes()
|
|
{
|
|
$this->assertTrue(is_array(self::$searchEngine->getAvailableTypes()));
|
|
foreach (self::$searchEngine->getAvailableTypes() as $type) {
|
|
$this->assertTrue(in_array($type, [SearchEngineInterface::GEM_TYPE_ENTRY, SearchEngineInterface::GEM_TYPE_RECORD, SearchEngineInterface::GEM_TYPE_STORY]));
|
|
}
|
|
}
|
|
|
|
public function testConfigurationPanel()
|
|
{
|
|
$this->assertInstanceOf('\\Alchemy\\Phrasea\\SearchEngine\\ConfigurationPanelInterface', self::$searchEngine->getConfigurationPanel());
|
|
}
|
|
|
|
public function testStatus()
|
|
{
|
|
foreach (self::$searchEngine->getStatus() as $StatusKeyValue) {
|
|
$this->assertTrue(is_array($StatusKeyValue));
|
|
$this->assertTrue(is_scalar($StatusKeyValue[0]));
|
|
$this->assertTrue(is_scalar($StatusKeyValue[1]));
|
|
}
|
|
}
|
|
|
|
public function testAddStory()
|
|
{
|
|
$story = self::$DI['record_story_1'];
|
|
$query_string = 'story' . $story->get_record_id() . 'addStory';
|
|
|
|
$options = $this->getDefaultOptions();
|
|
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
|
|
|
|
$this->editRecord($query_string, $story);
|
|
|
|
self::$searchEngine->addStory($story);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testUpdateStory()
|
|
{
|
|
$story = self::$DI['record_story_1'];
|
|
|
|
$options = $this->getDefaultOptions();
|
|
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
|
|
|
|
self::$searchEngine->addStory($story);
|
|
$this->updateIndex();
|
|
|
|
$query_string = 'story' . $story->get_record_id() . 'updateStory';
|
|
$this->editRecord($query_string, $story);
|
|
|
|
self::$searchEngine->updateStory($story);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testStatusQueryOnOverOff()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
$record = self::$DI['record_2'];
|
|
$record->set_binary_status('00000');
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
public function testStatusQueryOnOverOn()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
|
|
$record = self::$DI['record_2'];
|
|
$record->set_binary_status('10000');
|
|
|
|
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOnOverOn';
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testStatusQueryOffOverOn()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
|
|
$record = self::$DI['record_2'];
|
|
$record->set_binary_status('10000');
|
|
|
|
$options->setStatus([4 => ['off' => [$record->get_databox()->get_sbas_id()]]]);
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
}
|
|
|
|
public function testStatusQueryOffOverOff()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
|
|
$record = self::$DI['record_2'];
|
|
$record->set_binary_status('00000');
|
|
|
|
$options->setStatus([4 => ['off' => [$record->get_databox()->get_sbas_id()]]]);
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testStatusQueryUpdate()
|
|
{
|
|
$options = $this->getDefaultOptions();
|
|
$record = self::$DI['record_2'];
|
|
$record->set_binary_status('00000');
|
|
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryUpdate';
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
$options->setStatus([4 => ['on' => [$record->get_databox()->get_sbas_id()]]]);
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $options);
|
|
$this->assertEquals(0, $results->getTotal());
|
|
|
|
$record->set_binary_status('10000');
|
|
|
|
self::$searchEngine->updateRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$this->assertEquals(1, $results->getTotal());
|
|
}
|
|
|
|
public function testExcerptFromSimpleQuery()
|
|
{
|
|
$record = self::$DI['record_2'];
|
|
$query_string = 'boomboklot' . $record->get_record_id() . 'excerptSimpleQuery';
|
|
|
|
$this->editRecord($query_string, $record);
|
|
|
|
self::$searchEngine->addRecord($record);
|
|
$this->updateIndex();
|
|
|
|
self::$searchEngine->resetCache();
|
|
$results = self::$searchEngine->query($query_string, 0, 1, $this->options);
|
|
$fields = [];
|
|
$foundRecord = $results->getResults()->first();
|
|
|
|
$this->assertInstanceOf('\record_adapter', $foundRecord);
|
|
|
|
foreach ($foundRecord->get_caption()->get_fields() as $field) {
|
|
foreach ($field->get_values() as $metaId => $v) {
|
|
$values[$metaId] = array(
|
|
'value' => $v->getValue(),
|
|
'from_thesaurus' => false,
|
|
'qjs' => null,
|
|
);
|
|
}
|
|
|
|
$fields[$field->get_name()] = array(
|
|
'values' => $values,
|
|
'separator' => ';',
|
|
);
|
|
}
|
|
|
|
$found = false;
|
|
$highlightedValues = self::$searchEngine->excerpt($query_string, $fields, $foundRecord);
|
|
foreach ($highlightedValues as $fieldValues) {
|
|
foreach ($fieldValues as $metaId => $field) {
|
|
if (strpos($field, '[[em]]') !== false && strpos($field, '[[/em]]') !== false) {
|
|
$found = true;
|
|
break 2;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$found && count($highlightedValues) > 0) {
|
|
$this->fail('Unable to build the excerpt');
|
|
}
|
|
}
|
|
|
|
public function testCreateSubscriber()
|
|
{
|
|
$classname = self::$searchEngineClass;
|
|
$this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $classname::createSubscriber(self::$DI['app']));
|
|
}
|
|
|
|
abstract public function initialize();
|
|
|
|
abstract public function testAutocomplete();
|
|
|
|
abstract protected function updateIndex(array $stemms = []);
|
|
}
|