mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
[SearchEngine] Update PR to latest master
This commit is contained in:
@@ -20,6 +20,7 @@ use Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\FtpServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\ORMServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\TaskManagerServiceProvider;
|
||||
use FFMpeg\FFMpegServiceProvider;
|
||||
use Grom\Silex\ImagineServiceProvider;
|
||||
@@ -126,6 +127,7 @@ class Application extends SilexApplication
|
||||
$this->register(new ORMServiceProvider());
|
||||
$this->register(new PhraseanetServiceProvider());
|
||||
$this->register(new PHPExiftoolServiceProvider());
|
||||
$this->register(new SearchEngineServiceProvider());
|
||||
$this->register(new SessionServiceProvider(), array(
|
||||
'session.test' => $this->getEnvironment() == 'test'
|
||||
));
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\Core\Service\Builder;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
@@ -20,12 +21,17 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['phraseanet.SE'] = $app->share(function($app) {
|
||||
return $app['phraseanet.core']['SearchEngine'];
|
||||
});
|
||||
$configuration = $app['phraseanet.configuration']
|
||||
->getService($app['phraseanet.configuration']
|
||||
->getSearchEngine());
|
||||
|
||||
$service = Builder::create($app, $configuration);
|
||||
|
||||
return $service->getDriver();
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ class PhraseaEngine extends ServiceAbstract
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->searchEngine = new PhraseaSearchEngine();
|
||||
$this->searchEngine = PhraseaSearchEngine::create($this->app);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ class SphinxSearch extends ServiceAbstract
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
|
||||
$this->searchEngine = new SphinxSearchEngine($options['host'], $options['port'], $options['rt_host'], $options['rt_port']);
|
||||
$this->searchEngine = new SphinxSearchEngine($this->app, $options['host'], $options['port'], $options['rt_host'], $options['rt_port']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
use Silex\Application;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
interface ConfigurationPanelInterface
|
||||
|
@@ -11,33 +11,64 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Phrasea;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
class PhraseaEngine implements SearchEngineInterface
|
||||
{
|
||||
private static $initialized = false;
|
||||
/**
|
||||
*
|
||||
* @var SearchEngineOptions
|
||||
*/
|
||||
protected $options;
|
||||
protected $queries = array();
|
||||
protected $arrayq = array();
|
||||
protected $colls = array();
|
||||
protected $qp = array();
|
||||
protected $needthesaurus = array();
|
||||
protected $configurationPanel;
|
||||
protected $resetCacheNextQuery = false;
|
||||
private $options;
|
||||
private $queries = array();
|
||||
private $arrayq = array();
|
||||
private $colls = array();
|
||||
private $qp = array();
|
||||
private $needthesaurus = array();
|
||||
private $configurationPanel;
|
||||
private $resetCacheNextQuery = false;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->options = new SearchEngineOptions();
|
||||
|
||||
$this->initialize();
|
||||
$this->checkSession();
|
||||
}
|
||||
|
||||
private function checkSession()
|
||||
{
|
||||
if (!$this->app['phraseanet.user']) {
|
||||
throw new \RuntimeException('Phrasea currently support only authenticated queries');
|
||||
}
|
||||
|
||||
if (!phrasea_open_session($this->app['session']->get('phrasea_session_id'), $this->app['phraseanet.user']->get_id())) {
|
||||
if (!$ses_id = phrasea_create_session((string) $this->app['phraseanet.user']->get_id())) {
|
||||
throw new \Exception_InternalServerError('Unable to create phrasea session');
|
||||
}
|
||||
$this->app['session']->set('phrasea_session_id', $ses_id);
|
||||
}
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
{
|
||||
if(!self::$initialized) {
|
||||
|
||||
\phrasea::start($this->app['phraseanet.configuration']);
|
||||
|
||||
self::$initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +142,7 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
*/
|
||||
public function updateRecord(\record_adapter $record)
|
||||
{
|
||||
$record->set_binary_status(\databox_status::dec2bin(bindec($record->get_status()) & ~7 | 4));
|
||||
$record->set_binary_status(\databox_status::dec2bin($this->app, bindec($record->get_status()) & ~7 | 4));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -197,12 +228,9 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
$query .= ' AND recordtype=' . $this->options->getRecordType();
|
||||
}
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$sql = 'SELECT query, query_time, duration, total FROM cache WHERE session_id = :ses_id';
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':ses_id' => $session->get_ses_id()));
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':ses_id' => $this->app['session']->get('phrasea_session_id')));
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -217,24 +245,24 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
}
|
||||
|
||||
if ($this->resetCacheNextQuery === true) {
|
||||
phrasea_clear_cache($session->get_ses_id());
|
||||
phrasea_clear_cache($this->app['session']->get('phrasea_session_id'));
|
||||
$this->addQuery($query);
|
||||
$this->executeQuery($query);
|
||||
|
||||
$sql = 'SELECT query, query_time, duration, total FROM cache WHERE session_id = :ses_id';
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':ses_id' => $session->get_ses_id()));
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':ses_id' => $this->app['session']->get('phrasea_session_id')));
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
} else {
|
||||
/**
|
||||
* @todo clean this in DB
|
||||
*/
|
||||
$this->total_available = $this->total_results = $session->get_session_prefs('phrasea_engine_n_results');
|
||||
$this->total_available = $this->total_results = $this->app['session']->get('phrasea_engine_n_results');
|
||||
}
|
||||
|
||||
|
||||
$res = phrasea_fetch_results(
|
||||
$session->get_ses_id(), $offset + 1, $perPage, false
|
||||
$this->app['session']->get('phrasea_session_id'), $offset + 1, $perPage, false
|
||||
);
|
||||
|
||||
$rs = array();
|
||||
@@ -251,7 +279,8 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
foreach ($rs as $data) {
|
||||
try {
|
||||
$records->add(new \record_adapter(
|
||||
\phrasea::sbasFromBas($data['base_id']),
|
||||
$this->app,
|
||||
\phrasea::sbasFromBas($this->app, $data['base_id']),
|
||||
$data['record_id'],
|
||||
$resultNumber
|
||||
));
|
||||
@@ -264,16 +293,17 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
|
||||
return new SearchEngineResult($records, $query, $row['duration'], $offset, $row['total'], $row['total'], $error, '', new ArrayCollection(), new ArrayCollection(), '');
|
||||
}
|
||||
|
||||
public static function create(Application $app)
|
||||
{
|
||||
return new static($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
private function executeQuery($query)
|
||||
{
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$dateLog = date("Y-m-d H:i:s");
|
||||
$nbanswers = $total_time = 0;
|
||||
$sort = '';
|
||||
@@ -299,12 +329,12 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
}
|
||||
|
||||
$results = phrasea_query2(
|
||||
$session->get_ses_id()
|
||||
$this->app['session']->get('phrasea_session_id')
|
||||
, $sbas_id
|
||||
, $this->colls[$sbas_id]
|
||||
, $this->arrayq[$sbas_id]
|
||||
, $registry->get('GV_sit')
|
||||
, $session->get_usr_id()
|
||||
, $this->app['phraseanet.registry']->get('GV_sit')
|
||||
, $this->app['session']->get('usr_id')
|
||||
, false
|
||||
, $this->options->searchType() == SearchEngineOptions::RECORD_GROUPING ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY
|
||||
, $sort
|
||||
@@ -316,26 +346,26 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
$nbanswers += $results["nbanswers"];
|
||||
}
|
||||
|
||||
$logger = $session->get_logger($appbox->get_databox($sbas_id));
|
||||
|
||||
$conn2 = \connection::getPDOConnection($sbas_id);
|
||||
|
||||
$sql3 = "INSERT INTO log_search
|
||||
(id, log_id, date, search, results, coll_id )
|
||||
VALUES
|
||||
(null, :log_id, :date, :query, :nbresults, :colls)";
|
||||
|
||||
$params = array(
|
||||
':log_id' => $logger->get_id()
|
||||
, ':date' => $dateLog
|
||||
, ':query' => $query
|
||||
, ':nbresults' => $results["nbanswers"]
|
||||
, ':colls' => implode(',', $this->colls[$sbas_id])
|
||||
);
|
||||
|
||||
$stmt = $conn2->prepare($sql3);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
// $logger = $session->get_logger($this->appbox->get_databox($sbas_id));
|
||||
//
|
||||
// $conn2 = \connection::getPDOConnection($sbas_id);
|
||||
//
|
||||
// $sql3 = "INSERT INTO log_search
|
||||
// (id, log_id, date, search, results, coll_id )
|
||||
// VALUES
|
||||
// (null, :log_id, :date, :query, :nbresults, :colls)";
|
||||
//
|
||||
// $params = array(
|
||||
// ':log_id' => $logger->get_id()
|
||||
// , ':date' => $dateLog
|
||||
// , ':query' => $query
|
||||
// , ':nbresults' => $results["nbanswers"]
|
||||
// , ':colls' => implode(',', $this->colls[$sbas_id])
|
||||
// );
|
||||
//
|
||||
// $stmt = $conn2->prepare($sql3);
|
||||
// $stmt->execute($params);
|
||||
// $stmt->closeCursor();
|
||||
}
|
||||
|
||||
$sql = 'UPDATE cache
|
||||
@@ -344,17 +374,19 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
|
||||
$params = array(
|
||||
'query' => $query,
|
||||
':ses_id' => $session->get_ses_id(),
|
||||
':ses_id' => $this->app['session']->get('phrasea_session_id'),
|
||||
':duration' => $total_time,
|
||||
':total' => $nbanswers,
|
||||
);
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
\User_Adapter::saveQuery($query);
|
||||
|
||||
if ($this->app['phraseanet.user']) {
|
||||
\User_Adapter::saveQuery($this->app, $query);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -373,10 +405,8 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
$res = phrasea_fetch_results(
|
||||
$session->get_ses_id(), ($record->get_number() + 1), 1, true, "[[em]]", "[[/em]]"
|
||||
$this->app['session']->get('phrasea_session_id'), ($record->get_number() + 1), 1, true, "[[em]]", "[[/em]]"
|
||||
);
|
||||
|
||||
if ( ! isset($res['results']) || ! is_array($res['results'])) {
|
||||
@@ -514,7 +544,7 @@ class PhraseaEngine implements SearchEngineInterface
|
||||
|
||||
private function singleParse($sbas, $query)
|
||||
{
|
||||
$this->qp[$sbas] = new PhraseaEngineQueryParser($this->options->getLocale());
|
||||
$this->qp[$sbas] = new PhraseaEngineQueryParser($this->app, $this->options->getLocale());
|
||||
$this->qp[$sbas]->debug = false;
|
||||
|
||||
if ($sbas == 'main') {
|
||||
|
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Phrasea;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package searchEngine
|
||||
@@ -84,15 +86,17 @@ class PhraseaEngineQueryParser
|
||||
*/
|
||||
public $proposals = Array("QRY" => "", "BASES" => array(), "QUERIES" => array());
|
||||
|
||||
public $app;
|
||||
/**
|
||||
* Current language for thesaurus
|
||||
* @var <type>
|
||||
*/
|
||||
public $lng = null;
|
||||
public $lng;
|
||||
protected $unicode;
|
||||
|
||||
public function __construct($lng = "???")
|
||||
public function __construct(Application $app, $lng = "???")
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->lng = $lng;
|
||||
$this->unicode = new \unicode();
|
||||
|
||||
@@ -1723,13 +1727,12 @@ class PhraseaEngineQueryParser
|
||||
public function addsimple($t, $type, $nodetype, $pnum, $tree, $depth)
|
||||
{
|
||||
$nok = 0;
|
||||
$registry = \registry::get_instance();
|
||||
$w = $t["VALUE"];
|
||||
if ($w != "?" && $w != "*") { // on laisse passer les 'isolés' pour les traiter plus tard comme des mots vides
|
||||
for ($i = 0; $i < strlen($w); $i ++ ) {
|
||||
$c = substr($w, $i, 1);
|
||||
if ($c == "?" || $c == "*") {
|
||||
if ($nok < $registry->get('GV_min_letters_truncation')) {
|
||||
if ($nok < $this->app['phraseanet.registry']->get('GV_min_letters_truncation')) {
|
||||
if ($this->errmsg != "")
|
||||
$this->errmsg .= sprintf("\\n");
|
||||
$this->errmsg .= _('qparser:: Formulation incorrecte, necessite plus de caractere : ') . "<br>" . $registry->get('GV_min_letters_truncation');
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface;
|
||||
use Silex\Application;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
|
@@ -11,15 +11,14 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Silex\Application;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
require_once __DIR__ . '/../../../../vendor/sphinx/sphinxapi.php';
|
||||
@@ -45,9 +44,11 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
protected $rt_conn;
|
||||
protected $configurationPanel;
|
||||
protected $options;
|
||||
protected $app;
|
||||
|
||||
public function __construct($host, $port, $rt_host, $rt_port)
|
||||
public function __construct(Application $app, $host, $port, $rt_host, $rt_port)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->options = new SearchEngineOptions();
|
||||
|
||||
$this->sphinx = new \SphinxClient();
|
||||
@@ -297,9 +298,10 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
try {
|
||||
$record =
|
||||
new \record_adapter(
|
||||
$match['attrs']['sbas_id']
|
||||
, $match['attrs']['record_id']
|
||||
, $resultOffset
|
||||
$this->app,
|
||||
$match['attrs']['sbas_id'],
|
||||
$match['attrs']['record_id'],
|
||||
$resultOffset
|
||||
);
|
||||
|
||||
$results->add($record);
|
||||
|
@@ -149,7 +149,7 @@ class module_console_checkExtension extends Command
|
||||
$tbases[$kbase]["searchcoll"] = $tcoll;
|
||||
$tbases[$kbase]["mask_xor"] = $tbases[$kbase]["mask_and"] = 0;
|
||||
|
||||
$qp = new PhraseaEngineQueryParser();
|
||||
$qp = new PhraseaEngineQueryParser($this->container);
|
||||
$treeq = $qp->parsequery($input->getOption('query'));
|
||||
$arrayq = $qp->makequery($treeq);
|
||||
|
||||
|
@@ -501,70 +501,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
|
||||
$this->base_id = $collection->get_base_id();
|
||||
|
||||
try {
|
||||
$sphinx_rt = sphinxrt::get_instance($this->app['phraseanet.registry']);
|
||||
|
||||
$sbas_id = $this->get_sbas_id();
|
||||
$sbas_params = phrasea::sbas_params($this->app);
|
||||
|
||||
if (isset($sbas_params[$sbas_id])) {
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(
|
||||
str_replace(
|
||||
array('.', '%')
|
||||
, '_'
|
||||
, sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($this->get_caption()->get_fields(null, true) as $field) {
|
||||
|
||||
if (!$field->is_indexable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$databox_field = $field->get_databox_field();
|
||||
|
||||
foreach ($field->get_values() as $value) {
|
||||
|
||||
$sphinx_rt->delete(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_en", "metadatas" . $sbas_crc . "_stemmed_fr"), "metas_realtime" . $sbas_crc, $value->getId());
|
||||
|
||||
$sphinx_rt->replace_in_metas(
|
||||
"metas_realtime" . $sbas_crc
|
||||
, $value->getId()
|
||||
, $databox_field->get_id()
|
||||
, $this->get_record_id()
|
||||
, $sbas_id
|
||||
, phrasea::collFromBas($this->app, $this->get_base_id())
|
||||
, ($this->is_grouping() ? '1' : '0')
|
||||
, $this->get_type()
|
||||
, $value->getValue()
|
||||
, ($databox_field->isBusiness() ? '1' : '0')
|
||||
, $this->get_creation_date()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$all_datas = array();
|
||||
|
||||
foreach ($this->get_caption()->get_fields(null, true) as $field) {
|
||||
if (!$field->is_indexable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$all_datas[] = $field->get_serialized_values();
|
||||
}
|
||||
|
||||
$all_datas = implode(' ', $all_datas);
|
||||
$sphinx_rt->delete(array("documents" . $sbas_crc, "documents" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc . "_stemmed_en"), "docs_realtime" . $sbas_crc, $this->get_record_id());
|
||||
|
||||
$sphinx_rt->replace_in_documents(
|
||||
"docs_realtime" . $sbas_crc, $this->get_record_id(), $all_datas, $sbas_id, phrasea::collFromBas($this->app, $this->get_base_id()), ($this->is_grouping() ? '1' : '0'), $this->get_type(), $this->get_creation_date()
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
$this->app['phrasea.SE']->updateRecord($this);
|
||||
|
||||
$this->app['phraseanet.logger']($this->get_databox())
|
||||
->log($this, Session_Logger::EVENT_MOVE, $collection->get_coll_id(), '');
|
||||
@@ -1298,19 +1235,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
|
||||
try {
|
||||
$sphinx = sphinxrt::get_instance($this->app['phraseanet.registry']);
|
||||
|
||||
$sbas_params = phrasea::sbas_params($this->app);
|
||||
$sbas_id = $this->get_sbas_id();
|
||||
if (isset($sbas_params[$sbas_id])) {
|
||||
$params = $sbas_params[$sbas_id];
|
||||
$sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
|
||||
$sphinx->update_status(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_en", "metadatas" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc), $this->get_sbas_id(), $this->get_record_id(), strrev($status));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
$this->delete_data_from_cache(self::CACHE_STATUS);
|
||||
|
||||
return $this;
|
||||
|
@@ -1517,6 +1517,22 @@
|
||||
<default></default>
|
||||
<comment></comment>
|
||||
</field>
|
||||
<field>
|
||||
<name>duration</name>
|
||||
<type>float</type>
|
||||
<null></null>
|
||||
<extra></extra>
|
||||
<default></default>
|
||||
<comment></comment>
|
||||
</field>
|
||||
<field>
|
||||
<name>total</name>
|
||||
<type>int(11) unsigned</type>
|
||||
<null></null>
|
||||
<extra></extra>
|
||||
<default></default>
|
||||
<comment></comment>
|
||||
</field>
|
||||
</fields>
|
||||
<indexes>
|
||||
<index>
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
@@ -9,15 +10,14 @@ require_once __DIR__ . '/SearchEngineAbstractTest.php';
|
||||
|
||||
class PhraseaEngineTest extends SearchEngineAbstractTest
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
public function initialize()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
self::$searchEngine = new PhraseaEngine();
|
||||
self::$searchEngine = PhraseaEngine::create(self::$DI['app']);
|
||||
}
|
||||
|
||||
protected function updateIndex()
|
||||
{
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$appbox = self::$DI['app']['phraseanet.appbox'];
|
||||
$cmd = '/usr/local/bin/phraseanet_indexer '
|
||||
. ' -h=' . $appbox->get_host() . ' -P=' . $appbox->get_port()
|
||||
. ' -b=' . $appbox->get_dbname() . ' -u=' . $appbox->get_user()
|
||||
|
@@ -8,35 +8,37 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.i
|
||||
|
||||
abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedAbstract
|
||||
{
|
||||
|
||||
protected static $searchEngine;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
foreach (self::$records['record_24']->get_databox()->get_meta_structure()->get_elements() as $field) {
|
||||
if ( ! $field->isBusiness()) {
|
||||
continue;
|
||||
}
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( ! $found) {
|
||||
$field = \databox_field::create(self::$records['record_24']->get_databox(), 'testBusiness' . mt_rand(), false);
|
||||
$field->set_business(true);
|
||||
$field->save();
|
||||
}
|
||||
}
|
||||
protected static $initialized = false;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
break;
|
||||
|
||||
if (!self::$initialized) {
|
||||
$found = false;
|
||||
foreach (self::$DI['record_24']->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_24']->get_databox(), 'testBusiness' . mt_rand(), false);
|
||||
$field->set_business(true);
|
||||
$field->save();
|
||||
}
|
||||
|
||||
foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! self::$searchEngine instanceof SearchEngineInterface) {
|
||||
$this->initialize();
|
||||
|
||||
if (!self::$searchEngine instanceof SearchEngineInterface) {
|
||||
$this->markTestSkipped('Unable to initialize search Engine');
|
||||
}
|
||||
|
||||
@@ -45,6 +47,8 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
self::$searchEngine->setOptions($options);
|
||||
}
|
||||
|
||||
abstract public function initialize();
|
||||
|
||||
protected function updateIndex()
|
||||
{
|
||||
@@ -86,7 +90,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
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);
|
||||
@@ -110,7 +114,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testRecordNotIndexed()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultNotIndexed';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
@@ -122,7 +126,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testAddRecord()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'defaultAdd';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
@@ -137,7 +141,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testUpdateRecord()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
|
||||
self::$searchEngine->addRecord($record);
|
||||
$this->updateIndex();
|
||||
@@ -156,7 +160,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
protected function getDefaultOptions()
|
||||
{
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$appbox = self::$DI['app']['phraseanet.appbox'];
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
break;
|
||||
}
|
||||
@@ -173,7 +177,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
$options->setLocale('fr');
|
||||
self::$searchEngine->setOptions($options);
|
||||
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'stemmedfr';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
@@ -189,7 +193,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
public function testUpdateQueryOnField()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'onfield';
|
||||
|
||||
@@ -208,7 +212,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
public function testBusinessFieldAvailable()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'businessAvailable';
|
||||
|
||||
@@ -226,7 +230,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testBusinessFieldNotAvailable()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'businessNotAvailable';
|
||||
|
||||
$this->editRecord($query_string, $record, true, true);
|
||||
@@ -243,7 +247,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'anotherfield';
|
||||
|
||||
$selectedField = $this->editRecord($query_string, $record);
|
||||
@@ -267,11 +271,11 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testUpdateNonIndexableRecord()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot_no_index_' . $record->get_record_id() . '_';
|
||||
|
||||
$field = $this->editRecord($query_string, $record, false);
|
||||
if ( ! $field) {
|
||||
if (!$field) {
|
||||
$this->markTestSkipped('No non-indexable field found');
|
||||
}
|
||||
|
||||
@@ -285,7 +289,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testDeleteRecord()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'deleteRecord';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
@@ -324,7 +328,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testAddStory()
|
||||
{
|
||||
$story = self::$records['record_story_1'];
|
||||
$story = self::$DI['record_story_1'];
|
||||
$query_string = 'story' . $story->get_record_id() . 'addStory';
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
@@ -344,7 +348,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testUpdateStory()
|
||||
{
|
||||
$story = self::$records['record_story_1'];
|
||||
$story = self::$DI['record_story_1'];
|
||||
|
||||
$options = $this->getDefaultOptions();
|
||||
$options->setSearchType(SearchEngineOptions::RECORD_GROUPING);
|
||||
@@ -368,7 +372,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
public function testStatusQueryOnOverOff()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$record->set_binary_status('00000');
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryOff';
|
||||
@@ -389,7 +393,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$record->set_binary_status('10000');
|
||||
|
||||
$options->setStatus(array(4 => array('on' => array($record->get_databox()->get_sbas_id()))));
|
||||
@@ -410,7 +414,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$record->set_binary_status('10000');
|
||||
|
||||
$options->setStatus(array(4 => array('off' => array($record->get_databox()->get_sbas_id()))));
|
||||
@@ -431,9 +435,9 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$record->set_binary_status('00000');
|
||||
|
||||
|
||||
$options->setStatus(array(4 => array('off' => array($record->get_databox()->get_sbas_id()))));
|
||||
self::$searchEngine->setOptions($options);
|
||||
|
||||
@@ -451,7 +455,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
public function testStatusQueryUpdate()
|
||||
{
|
||||
$options = $this->getDefaultOptions();
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$record->set_binary_status('00000');
|
||||
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'statusQueryUpdate';
|
||||
@@ -479,7 +483,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
|
||||
public function testExcerptFromSimpleQuery()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
$query_string = 'boomboklot' . $record->get_record_id() . 'excerptSimpleQuery';
|
||||
|
||||
$this->editRecord($query_string, $record);
|
||||
@@ -491,6 +495,8 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
$results = self::$searchEngine->query($query_string, 0, 1);
|
||||
$fields = array();
|
||||
$foundRecord = $results->results()->first();
|
||||
|
||||
$this->assertInstanceOf('\record_adapter', $foundRecord);
|
||||
|
||||
foreach ($foundRecord->get_caption()->get_fields() as $field) {
|
||||
$fields[$field->get_name()] = array(
|
||||
@@ -507,7 +513,7 @@ abstract class SearchEngineAbstractTest extends \PhraseanetPHPUnitAuthenticatedA
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $found) {
|
||||
if (!$found) {
|
||||
$this->fail('Unable to build the excerpt');
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
@@ -16,8 +17,10 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
self::$searchEngine = new SphinxSearchEngine('127.0.0.1', 9306, '127.0.0.1', 9308);
|
||||
|
||||
$app = new Application('test');
|
||||
$appbox = $app['phraseanet.appbox'];
|
||||
self::$searchEngine = new SphinxSearchEngine($app, '127.0.0.1', 9306, '127.0.0.1', 9308);
|
||||
|
||||
self::$config = tempnam(sys_get_temp_dir(), 'tmp_sphinx.conf');
|
||||
$configFile = self::$searchEngine->configurationPanel()->generateSphinxConf($appbox->get_databoxes(), self::$searchEngine->configurationPanel()->getConfiguration());
|
||||
@@ -34,8 +37,12 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
|
||||
self::$searchd = new Process($searchd . ' -c ' . self::$config);
|
||||
self::$searchd->run();
|
||||
|
||||
self::$searchEngine = new SphinxSearchEngine('127.0.0.1', 9306, '127.0.0.1', 9308);
|
||||
|
||||
self::$searchEngine = new SphinxSearchEngine($app, '127.0.0.1', 9306, '127.0.0.1', 9308);
|
||||
}
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
@@ -51,14 +58,9 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testAutocomplete()
|
||||
{
|
||||
$record = self::$records['record_24'];
|
||||
$record = self::$DI['record_24'];
|
||||
|
||||
$toupdate = array();
|
||||
|
||||
@@ -90,7 +92,7 @@ class SphinxSearchEngineTest extends SearchEngineAbstractTest
|
||||
$process = new Process($indexer . ' --all --rotate -c ' . self::$config);
|
||||
$process->run();
|
||||
|
||||
$appbox = \appbox::get_instance(self::$core);
|
||||
$appbox = self::$DI['app']['phraseanet.appbox'];
|
||||
self::$searchEngine->buildSuggestions($appbox->get_databoxes(), self::$config, 0);
|
||||
|
||||
$suggestions = self::$searchEngine->autoComplete('jean');
|
||||
|
Reference in New Issue
Block a user