Update searchEngine

This commit is contained in:
Romain Neutron
2012-09-21 15:05:44 +02:00
parent 5bd18f61e4
commit 95a447f496
7 changed files with 89 additions and 88 deletions

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @package searchEngine * @package searchEngine
@@ -40,12 +42,12 @@ class searchEngine_adapter
* @param registryInterface $registry * @param registryInterface $registry
* @return searchEngine_adapter * @return searchEngine_adapter
*/ */
public function __construct(registryInterface $registry) public function __construct(Application $app)
{ {
if ($registry->get('GV_sphinx')) { if ($app['phraseanet.registry']->get('GV_sphinx')) {
$this->search_engine = new searchEngine_adapter_sphinx_engine(); $this->search_engine = new searchEngine_adapter_sphinx_engine($app);
} elseif (function_exists('phrasea_query2')) { } elseif (function_exists('phrasea_query2')) {
$this->search_engine = new searchEngine_adapter_phrasea_engine(); $this->search_engine = new searchEngine_adapter_phrasea_engine($app);
} else { } else {
throw new Exception('No search engine available, try phrasea2 or sphinx'); throw new Exception('No search engine available, try phrasea2 or sphinx');
} }

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @package searchEngine * @package searchEngine
@@ -18,7 +20,7 @@
interface searchEngine_adapter_interface interface searchEngine_adapter_interface
{ {
public function __construct(); public function __construct(Application $app);
public function set_options(searchEngine_options $options); public function set_options(searchEngine_options $options);
@@ -42,7 +44,7 @@ interface searchEngine_adapter_interface
public function get_parsed_query(); public function get_parsed_query();
public function get_suggestions(Session_Handler $session); public function get_suggestions($I18n);
public function get_error(); public function get_error();

View File

@@ -9,6 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration;
/** /**
* *
* @package searchEngine * @package searchEngine
@@ -124,13 +127,15 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
* @var string * @var string
*/ */
protected $opt_record_type; protected $opt_record_type;
protected $app;
/** /**
* *
* @return searchEngine_adapter_phrasea_engine * @return searchEngine_adapter_phrasea_engine
*/ */
public function __construct() public function __construct(Application $app)
{ {
$this->app = $app;
return $this; return $this;
} }
@@ -238,12 +243,11 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$query .= ' AND recordtype=' . $this->opt_record_type; $query .= ' AND recordtype=' . $this->opt_record_type;
} }
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
$session = $appbox->get_session();
$sql = 'SELECT query, query_time FROM cache WHERE session_id = :ses_id'; $sql = 'SELECT query, query_time FROM cache WHERE session_id = :ses_id';
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute(array(':ses_id' => $session->get_ses_id())); $stmt->execute(array(':ses_id' => $this->app['session']->get('phrasea_session_id')));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -265,7 +269,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
self::addQuery($query); self::addQuery($query);
self::query(); self::query();
} else { } else {
$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');
} }
$results = new set_result(); $results = new set_result();
@@ -275,7 +279,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$this->offset_start = $courcahnum = (($page - 1) * $perPage); $this->offset_start = $courcahnum = (($page - 1) * $perPage);
$res = phrasea_fetch_results( $res = phrasea_fetch_results(
$session->get_ses_id(), (int) (($page - 1) * $perPage) + 1, $perPage, false $this->app['session']->get('phrasea_session_id'), (int) (($page - 1) * $perPage) + 1, $perPage, false
); );
$rs = array(); $rs = array();
@@ -284,9 +288,10 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
foreach ($rs as $irec => $data) { foreach ($rs as $irec => $data) {
try { try {
$sbas_id = phrasea::sbasFromBas($data['base_id']); $sbas_id = phrasea::sbasFromBas($this->app, $data['base_id']);
$record = new record_adapter( $record = new record_adapter(
$this->app,
$sbas_id, $sbas_id,
$data['record_id'], $data['record_id'],
$courcahnum $courcahnum
@@ -308,9 +313,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
*/ */
public function reset_cache() public function reset_cache()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); phrasea_clear_cache($this->app['session']->get('phrasea_session_id'));
$session = $appbox->get_session();
phrasea_clear_cache($session->get_ses_id());
$this->reseted = true; $this->reseted = true;
return $this; return $this;
@@ -332,12 +335,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
return $status; return $status;
} }
/** public function get_suggestions($I18n)
*
* @param Session_Handler $session
* @return array
*/
public function get_suggestions(Session_Handler $session)
{ {
$props = array(); $props = array();
foreach ($this->qp['main']->proposals['QUERIES'] as $prop) { foreach ($this->qp['main']->proposals['QUERIES'] as $prop) {
@@ -366,8 +364,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
*/ */
protected function query() protected function query()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
$session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
$dateLog = date("Y-m-d H:i:s"); $dateLog = date("Y-m-d H:i:s");
@@ -378,7 +375,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$params = array( $params = array(
'query' => $this->get_parsed_query() 'query' => $this->get_parsed_query()
, ':ses_id' => $session->get_ses_id() , ':ses_id' => $this->app['session']->get('phrasea_session_id')
); );
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $appbox->get_connection()->prepare($sql);
@@ -406,16 +403,16 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$BF = array(); $BF = array();
foreach ($this->options->get_business_fields() as $base_id) { foreach ($this->options->get_business_fields() as $base_id) {
$BF[] = phrasea::collFromBas($base_id); $BF[] = phrasea::collFromBas($this->app, $base_id);
} }
$this->results[$sbas_id] = phrasea_query2( $this->results[$sbas_id] = phrasea_query2(
$session->get_ses_id() $this->app['session']->get('phrasea_session_id')
, $sbas_id , $sbas_id
, $this->colls[$sbas_id] , $this->colls[$sbas_id]
, $this->arrayq[$sbas_id] , $this->arrayq[$sbas_id]
, $registry->get('GV_sit') , $registry->get('GV_sit')
, (string) $session->get_usr_id() , (string) $this->app['phraseanet.user']->get_id()
, false , false
, $this->opt_search_type == 1 ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY , $this->opt_search_type == 1 ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY
, $sort , $sort
@@ -427,9 +424,9 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
if ($this->results[$sbas_id]) if ($this->results[$sbas_id])
$nbanswers += $this->results[$sbas_id]["nbanswers"]; $nbanswers += $this->results[$sbas_id]["nbanswers"];
$logger = $session->get_logger($appbox->get_databox($sbas_id)); $logger = $this->app['phraseanet.logger']($appbox->get_databox($sbas_id));
$conn2 = connection::getPDOConnection($sbas_id); $conn2 = connection::getPDOConnection($this->app, $sbas_id);
$sql3 = "INSERT INTO log_search $sql3 = "INSERT INTO log_search
(id, log_id, date, search, results, coll_id ) (id, log_id, date, search, results, coll_id )
@@ -451,9 +448,9 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$this->total_time = $total_time; $this->total_time = $total_time;
User_Adapter::saveQuery($this->query); User_Adapter::saveQuery($this->app, $this->query);
$session->set_session_prefs('phrasea_engine_n_results', $nbanswers); $this->app['session']->set('phrasea_engine_n_results', $nbanswers);
$this->total_available = $this->total_results = $nbanswers; $this->total_available = $this->total_results = $nbanswers;
@@ -467,9 +464,8 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
*/ */
protected function singleParse($sbas) protected function singleParse($sbas)
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
$session = $appbox->get_session(); $this->qp[$sbas] = new searchEngine_adapter_phrasea_queryParser($this->app, $this->app['locale']);
$this->qp[$sbas] = new searchEngine_adapter_phrasea_queryParser(Session_Handler::get_locale());
$this->qp[$sbas]->debug = false; $this->qp[$sbas]->debug = false;
if ($sbas == 'main') if ($sbas == 'main')
$simple_treeq = $this->qp[$sbas]->parsequery($this->query); $simple_treeq = $this->qp[$sbas]->parsequery($this->query);
@@ -498,7 +494,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$qry .= trim($query); $qry .= trim($query);
} }
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
foreach ($appbox->get_databoxes() as $databox) { foreach ($appbox->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $coll) { foreach ($databox->get_collections() as $coll) {
@@ -597,10 +593,8 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
{ {
$ret = array(); $ret = array();
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$res = phrasea_fetch_results( $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'])) { if ( ! isset($res['results']) || ! is_array($res['results'])) {

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @package searchEngine * @package searchEngine
@@ -88,9 +90,11 @@ class searchEngine_adapter_phrasea_queryParser
*/ */
public $lng = null; public $lng = null;
protected $unicode; protected $unicode;
protected $app;
public function __construct($lng = "???") public function __construct(Application $app, $lng = "???")
{ {
$this->app = $app;
$this->lng = $lng; $this->lng = $lng;
$this->unicode = new unicode(); $this->unicode = new unicode();
@@ -1721,7 +1725,7 @@ class searchEngine_adapter_phrasea_queryParser
public function addsimple($t, $type, $nodetype, $pnum, $tree, $depth) public function addsimple($t, $type, $nodetype, $pnum, $tree, $depth)
{ {
$nok = 0; $nok = 0;
$registry = registry::get_instance(); $registry = $this->app['phraseanet.registry'];
$w = $t["VALUE"]; $w = $t["VALUE"];
if ($w != "?" && $w != "*") { // on laisse passer les 'isolés' pour les traiter plus tard comme des mots vides 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 ++ ) { for ($i = 0; $i < strlen($w); $i ++ ) {

View File

@@ -10,6 +10,9 @@ require_once __DIR__ . '/../../../../vendor/sphinx/sphinxapi.php';
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration;
/** /**
* *
* @package searchEngine * @package searchEngine
@@ -47,14 +50,16 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
* @var boolean * @var boolean
*/ */
protected $search_unique_record = false; protected $search_unique_record = false;
protected $app;
/** /**
* *
* @return searchEngine_adapter_sphinx_engine * @return searchEngine_adapter_sphinx_engine
*/ */
public function __construct() public function __construct(Application $app)
{ {
$registry = registry::get_instance(); $this->app = $app;
$registry = $this->app['phraseanet.registry'];
$this->sphinx = new SphinxClient (); $this->sphinx = new SphinxClient ();
$this->sphinx->SetArrayResult(true); $this->sphinx->SetArrayResult(true);
@@ -82,9 +87,9 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$this->locale = $options->get_locale(); $this->locale = $options->get_locale();
foreach ($options->get_bases() as $bas) { foreach ($options->get_bases() as $bas) {
$this->distinct_sbas[phrasea::sbasFromBas($bas)] = true; $this->distinct_sbas[phrasea::sbasFromBas($this->app, $bas)] = true;
$key = phrasea::sbasFromBas($bas) . '_' . phrasea::collFromBas($bas); $key = phrasea::sbasFromBas($this->app, $bas) . '_' . phrasea::collFromBas($this->app, $bas);
$sbas_id = phrasea::sbasFromBas($bas); $sbas_id = phrasea::sbasFromBas($this->app, $bas);
$sbas_ids[$sbas_id] = $sbas_id; $sbas_ids[$sbas_id] = $sbas_id;
$filters[] = crc32($key); $filters[] = crc32($key);
} }
@@ -97,7 +102,7 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$filters = array(); $filters = array();
$appbox = \appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
foreach ($sbas_ids as $sbas_id) { foreach ($sbas_ids as $sbas_id) {
$fields = $appbox->get_databox($sbas_id)->get_meta_structure(); $fields = $appbox->get_databox($sbas_id)->get_meta_structure();
@@ -118,14 +123,14 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$this->search_in_field = true; $this->search_in_field = true;
foreach ($options->get_business_fields() as $base_id) { foreach ($options->get_business_fields() as $base_id) {
$crc_coll_business[] = crc32(phrasea::collFromBas($base_id) . '_1'); $crc_coll_business[] = crc32(phrasea::collFromBas($this->app, $base_id) . '_1');
$crc_coll_business[] = crc32(phrasea::collFromBas($base_id) . '_0'); $crc_coll_business[] = crc32(phrasea::collFromBas($this->app, $base_id) . '_0');
} }
$non_business = array_diff($options->get_bases(), $options->get_business_fields()); $non_business = array_diff($options->get_bases(), $options->get_business_fields());
foreach ($non_business as $base_id) { foreach ($non_business as $base_id) {
$crc_coll_business[] = crc32(phrasea::collFromBas($base_id) . '_0'); $crc_coll_business[] = crc32(phrasea::collFromBas($this->app, $base_id) . '_0');
} }
$this->sphinx->SetFilter('crc_coll_business', $crc_coll_business); $this->sphinx->SetFilter('crc_coll_business', $crc_coll_business);
@@ -137,7 +142,7 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$this->sphinx->SetFilter('crc_struct_id', $filters); $this->sphinx->SetFilter('crc_struct_id', $filters);
} }
$appbox = \appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
/** /**
* @todo : enhance : check status better * @todo : enhance : check status better
*/ */
@@ -265,8 +270,6 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
assert(is_int($offset)); assert(is_int($offset));
assert($offset >= 0); assert($offset >= 0);
assert(is_int($perPage)); assert(is_int($perPage));
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$page = ceil($offset / $perPage) + 1; $page = ceil($offset / $perPage) + 1;
@@ -281,7 +284,7 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$index = '*'; $index = '*';
$params = phrasea::sbas_params(); $params = phrasea::sbas_params($this->app);
$index_keys = array(); $index_keys = array();
foreach ($params as $sbas_id => $params) { foreach ($params as $sbas_id => $params) {
@@ -295,10 +298,10 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$index = ''; $index = '';
$found = false; $found = false;
if ($this->query !== '' && $this->options->get_use_stemming()) { if ($this->query !== '' && $this->options->get_use_stemming()) {
if ($session->get_I18n() == 'fr') { if ($this->app['locale.I18n'] == 'fr') {
$index .= ', documents' . implode('_stemmed_fr, documents', $index_keys) . '_stemmed_fr'; $index .= ', documents' . implode('_stemmed_fr, documents', $index_keys) . '_stemmed_fr';
$found = true; $found = true;
} elseif ($session->get_I18n() == 'en') { } elseif ($this->app['locale.I18n'] == 'en') {
$index .= ', documents' . implode('_stemmed_en, documents', $index_keys) . '_stemmed_en'; $index .= ', documents' . implode('_stemmed_en, documents', $index_keys) . '_stemmed_en';
$found = true; $found = true;
} }
@@ -309,11 +312,11 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
} else { } else {
$index = ''; $index = '';
$found = false; $found = false;
if ($this->query !== '' && $this->options->get_use_stemming() && $session->get_I18n() == 'fr') { if ($this->query !== '' && $this->options->get_use_stemming() && $this->app['locale.I18n'] == 'fr') {
if ($session->get_I18n() == 'fr') { if ($this->app['locale.I18n'] == 'fr') {
$index .= ', metadatas' . implode('_stemmed_fr, metadatas', $index_keys) . '_stemmed_fr'; $index .= ', metadatas' . implode('_stemmed_fr, metadatas', $index_keys) . '_stemmed_fr';
$found = true; $found = true;
} elseif ($session->get_I18n() == 'en') { } elseif ($this->app['locale.I18n'] == 'en') {
$index .= ', metadatas' . implode('_stemmed_en, metadatas', $index_keys) . '_stemmed_en'; $index .= ', metadatas' . implode('_stemmed_en, metadatas', $index_keys) . '_stemmed_en';
$found = true; $found = true;
} }
@@ -351,6 +354,7 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
try { try {
$record = $record =
new record_adapter( new record_adapter(
$this->app,
$match['attrs']['sbas_id'] $match['attrs']['sbas_id']
, $match['attrs']['record_id'] , $match['attrs']['record_id']
, $courcahnum , $courcahnum
@@ -444,7 +448,7 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$this->sphinx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC"); $this->sphinx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
$this->sphinx->SetLimits(0, 10); $this->sphinx->SetLimits(0, 10);
$params = phrasea::sbas_params(); $params = phrasea::sbas_params($this->app);
$index_keys = array(); $index_keys = array();
foreach ($params as $sbas_id => $p) { foreach ($params as $sbas_id => $p) {
@@ -476,17 +480,12 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
return $ret; return $ret;
} }
/** public function get_suggestions($I18n, $only_last_word = false)
*
* @param Session_Handler $session
* @return array
*/
public function get_suggestions(Session_Handler $session, $only_last_word = false)
{ {
if ( ! $this->current_index) if ( ! $this->current_index)
$this->current_index = '*'; $this->current_index = '*';
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
$supposed_qry = mb_strtolower($this->query); $supposed_qry = mb_strtolower($this->query);
$pieces = explode(" ", str_replace(array("all", "last", "et", "ou", "sauf", "and", "or", "except", "in", "dans", "'", '"', "(", ")", "_", "-"), ' ', $supposed_qry)); $pieces = explode(" ", str_replace(array("all", "last", "et", "ou", "sauf", "and", "or", "except", "in", "dans", "'", '"', "(", ")", "_", "-"), ' ', $supposed_qry));
@@ -506,7 +505,7 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$pieces = array(array_pop($pieces)); $pieces = array(array_pop($pieces));
} }
$tag = $session->get_I18n(); $tag = $I18n;
$suggestions = array(); $suggestions = array();
@@ -650,13 +649,12 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
*/ */
public function build_excerpt($query, array $fields, record_adapter $record) public function build_excerpt($query, array $fields, record_adapter $record)
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = $this->app['phraseanet.appbox'];
$session = $appbox->get_session();
$selected_sbas_id = $record->get_sbas_id(); $selected_sbas_id = $record->get_sbas_id();
$index = ''; $index = '';
$params = phrasea::sbas_params(); $params = phrasea::sbas_params($this->app);
$index_keys = array(); $index_keys = array();
foreach ($params as $sbas_id => $params) { foreach ($params as $sbas_id => $params) {
@@ -670,10 +668,10 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
$index = ''; $index = '';
$found = false; $found = false;
if ($this->options->get_use_stemming()) { if ($this->options->get_use_stemming()) {
if ($session->get_I18n() == 'fr') { if ($this->app['locale.I18n'] == 'fr') {
$index .= 'documents' . implode('_stemmed_fr, documents', $index_keys) . '_stemmed_fr'; $index .= 'documents' . implode('_stemmed_fr, documents', $index_keys) . '_stemmed_fr';
$found = true; $found = true;
} elseif ($session->get_I18n() == 'en') { } elseif ($this->app['locale.I18n'] == 'en') {
$index .= 'documents' . implode('_stemmed_en, documents', $index_keys) . '_stemmed_en'; $index .= 'documents' . implode('_stemmed_en, documents', $index_keys) . '_stemmed_en';
$found = true; $found = true;
} }
@@ -683,11 +681,11 @@ class searchEngine_adapter_sphinx_engine extends searchEngine_adapter_abstract i
} else { } else {
$index = ''; $index = '';
$found = false; $found = false;
if ($this->options->get_use_stemming() && $session->get_I18n() == 'fr') { if ($this->options->get_use_stemming() && $this->app['locale.I18n'] == 'fr') {
if ($session->get_I18n() == 'fr') { if ($this->app['locale.I18n'] == 'fr') {
$index .= 'metadatas' . implode('_stemmed_fr, metadatas', $index_keys) . '_stemmed_fr'; $index .= 'metadatas' . implode('_stemmed_fr, metadatas', $index_keys) . '_stemmed_fr';
$found = true; $found = true;
} elseif ($session->get_I18n() == 'en') { } elseif ($this->app['locale.I18n'] == 'en') {
$index .= 'metadatas' . implode('_stemmed_en, metadatas', $index_keys) . '_stemmed_en'; $index .= 'metadatas' . implode('_stemmed_en, metadatas', $index_keys) . '_stemmed_en';
$found = true; $found = true;
} }

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Core\Configuration;
/** /**
* *
* @package searchEngine * @package searchEngine
@@ -119,12 +121,9 @@ class searchEngine_results
* *
* @return array * @return array
*/ */
public function get_suggestions() public function get_suggestions($I18n)
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); return $this->engine->get_suggestions($I18n);
$session = $appbox->get_session();
return $this->engine->get_suggestions($session);
} }
/** /**

View File

@@ -9,6 +9,8 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
/** /**
* *
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
@@ -16,6 +18,7 @@
*/ */
class sphinx_configuration class sphinx_configuration
{ {
protected $app;
const OPT_ALL_SBAS = 'all'; const OPT_ALL_SBAS = 'all';
const OPT_LIBSTEMMER_NONE = 'none'; const OPT_LIBSTEMMER_NONE = 'none';
const OPT_LIBSTEMMER_FR = 'fr'; const OPT_LIBSTEMMER_FR = 'fr';
@@ -25,23 +28,22 @@ class sphinx_configuration
const OPT_MIN_PREFIX_LEN = 0; const OPT_MIN_PREFIX_LEN = 0;
const OPT_MIN_INFIX_LEN = 1; const OPT_MIN_INFIX_LEN = 1;
public function __construct() public function __construct(Application $app)
{ {
$this->app = $app;
} }
public function get_available_charsets() public function get_available_charsets()
{ {
$available_charsets = array(); $available_charsets = array();
$dir = __DIR__ . '/charsetTable/'; $dir = __DIR__ . '/charsetTable/';
echo $dir; $registry = $this->app['phraseanet.registry'];
$registry = registry::get_instance();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
if ($file->isDir() || strpos($file->getPathname(), '/.svn/') !== false) { if ($file->isDir() || strpos($file->getPathname(), '/.svn/') !== false) {
continue; continue;
} }
if ($file->isFile()) { if ($file->isFile()) {
$classname = str_replace(array($registry->get('GV_RootPath') . 'lib/classes/', '.class.php', '/'), array('', '', '_'), $file->getPathname()); $classname = str_replace(array(realpath(__DIR__ . '/..') . '/', '.class.php', '/'), array('', '', '_'), $file->getPathname());
$available_charsets[$classname] = new $classname; $available_charsets[$classname] = new $classname;
} }
} }
@@ -71,7 +73,7 @@ class sphinx_configuration
$options['charset_tables'] = array_unique($options['charset_tables']); $options['charset_tables'] = array_unique($options['charset_tables']);
$lb = phrasea::sbas_params(); $lb = phrasea::sbas_params($this->app);
$conf = ''; $conf = '';
@@ -88,7 +90,7 @@ class sphinx_configuration
$charsets = explode("\n", $charsets); $charsets = explode("\n", $charsets);
$last_detect = false; $last_detect = false;
for ($i = (count($charsets) - 1); $i >= 0; $i -- ) { for ($i = (count($charsets) - 1); $i >= 0; $i--) {
if (trim($charsets[$i]) === '') { if (trim($charsets[$i]) === '') {
unset($charsets[$i]); unset($charsets[$i]);
continue; continue;