mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
[SearchEngine] Add code documentation
This commit is contained in:
@@ -11,11 +11,6 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
|
||||
|
||||
/**
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class AbstractCharset
|
||||
{
|
||||
protected $table;
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\AbstractConfigurationPanel;
|
||||
@@ -19,11 +28,17 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
$this->searchEngine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'sphinx-search';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(Application $app, Request $request)
|
||||
{
|
||||
$configuration = $this->getConfiguration();
|
||||
@@ -38,6 +53,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $app['twig']->render('admin/search-engine/sphinx-search.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function post(Application $app, Request $request)
|
||||
{
|
||||
$configuration = $this->getConfiguration();
|
||||
@@ -61,6 +79,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $app->redirect($app['url_generator']->generate('admin_searchengine_get'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
$configuration = @json_decode(file_get_contents($this->getConfigPathFile()), true);
|
||||
@@ -96,6 +117,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveConfiguration(array $configuration)
|
||||
{
|
||||
file_put_contents($this->getConfigPathFile(), json_encode($configuration));
|
||||
@@ -103,6 +127,11 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the charset Sphinx Search supports
|
||||
*
|
||||
* @return array An array of charsets
|
||||
*/
|
||||
public function getAvailableCharsets()
|
||||
{
|
||||
if (null !== $this->charsets) {
|
||||
@@ -127,6 +156,13 @@ class ConfigurationPanel extends AbstractConfigurationPanel
|
||||
return $this->charsets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates Sphinx Search configuration depending on the service configuration
|
||||
*
|
||||
* @param array $databoxes The databoxes to index
|
||||
* @param array $configuration The configuration
|
||||
* @return string The sphinx search configuration
|
||||
*/
|
||||
public function generateSphinxConf(array $databoxes, array $configuration)
|
||||
{
|
||||
$defaults = array(
|
||||
|
@@ -71,6 +71,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAvailableDateFields()
|
||||
{
|
||||
if (!$this->dateFields) {
|
||||
@@ -89,12 +92,18 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
|
||||
return $this->dateFields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultSort()
|
||||
{
|
||||
return 'relevance';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAvailableSort()
|
||||
{
|
||||
return array(
|
||||
@@ -104,6 +113,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAvailableOrder()
|
||||
{
|
||||
return array(
|
||||
@@ -111,12 +123,18 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
'asc' => _('ascendant'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasStemming()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
if (false === $this->sphinx->Status()) {
|
||||
@@ -135,8 +153,7 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ConfigurationPanel
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configurationPanel()
|
||||
{
|
||||
@@ -156,11 +173,17 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function availableTypes()
|
||||
{
|
||||
return array(self::GEM_TYPE_RECORD, self::GEM_TYPE_STORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addRecord(\record_adapter $record)
|
||||
{
|
||||
if (!$this->rt_conn) {
|
||||
@@ -235,31 +258,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getSqlDateFields(\record_adapter $record)
|
||||
{
|
||||
$configuration = $this->getConfiguration();
|
||||
|
||||
$sql_fields = array();
|
||||
|
||||
foreach ($configuration['date_fields'] as $field_name) {
|
||||
|
||||
try {
|
||||
$value = $record->get_caption()->get_field($field_name)->get_serialized_values();
|
||||
} catch (\Exception $e) {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
$date = \DateTime::createFromFormat('Y/m/d H:i:s', $this->app['unicode']->parseDate($value));
|
||||
$value = $date->format('U');
|
||||
}
|
||||
|
||||
$sql_fields[] = $value ? : '-1';
|
||||
}
|
||||
|
||||
return ($sql_fields ? ', ' : '') . implode(',', $sql_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeRecord(\record_adapter $record)
|
||||
{
|
||||
if (!$this->rt_conn) {
|
||||
@@ -300,48 +301,75 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateRecord(\record_adapter $record)
|
||||
{
|
||||
$this->removeRecord($record);
|
||||
$this->addRecord($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addStory(\record_adapter $record)
|
||||
{
|
||||
return $this->addRecord($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeStory(\record_adapter $record)
|
||||
{
|
||||
return $this->removeRecord($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateStory(\record_adapter $record)
|
||||
{
|
||||
return $this->updateRecord($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addFeedEntry(\Feed_Entry_Adapter $entry)
|
||||
{
|
||||
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeFeedEntry(\Feed_Entry_Adapter $entry)
|
||||
{
|
||||
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateFeedEntry(\Feed_Entry_Adapter $entry)
|
||||
{
|
||||
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOptions(SearchEngineOptions $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
$this->applyOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resetOptions()
|
||||
{
|
||||
$this->options = new SearchEngineOptions();
|
||||
@@ -354,6 +382,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
$this->sphinx->ResetFilters();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($query, $offset, $perPage)
|
||||
{
|
||||
assert(is_int($offset));
|
||||
@@ -423,6 +454,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return new SearchEngineResult($results, $query, $duration, $offset, $available, $total, $error, $warning, $suggestions, $propositions, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function autocomplete($query)
|
||||
{
|
||||
$words = explode(" ", $this->cleanupQuery($query));
|
||||
@@ -430,6 +464,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this->getSuggestions(array_pop($words));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function excerpt($query, $fields, \record_adapter $record)
|
||||
{
|
||||
$index = '';
|
||||
@@ -462,6 +499,9 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this->sphinx->BuildExcerpts($fields_to_send, $index, $query, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resetCache()
|
||||
{
|
||||
return $this;
|
||||
@@ -608,6 +648,31 @@ class SphinxSearchEngine implements SearchEngineInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getSqlDateFields(\record_adapter $record)
|
||||
{
|
||||
$configuration = $this->getConfiguration();
|
||||
|
||||
$sql_fields = array();
|
||||
|
||||
foreach ($configuration['date_fields'] as $field_name) {
|
||||
|
||||
try {
|
||||
$value = $record->get_caption()->get_field($field_name)->get_serialized_values();
|
||||
} catch (\Exception $e) {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
$date = \DateTime::createFromFormat('Y/m/d H:i:s', $this->app['unicode']->parseDate($value));
|
||||
$value = $date->format('U');
|
||||
}
|
||||
|
||||
$sql_fields[] = $value ? : '-1';
|
||||
}
|
||||
|
||||
return ($sql_fields ? ', ' : '') . implode(',', $sql_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all keywords, operators, quotes from a query string
|
||||
*
|
||||
|
Reference in New Issue
Block a user