[SearchEngine] Add code documentation

This commit is contained in:
Romain Neutron
2012-10-30 16:17:48 +01:00
parent ca29ab9f86
commit 5be95d55fc
11 changed files with 436 additions and 52 deletions

View File

@@ -1,14 +1,31 @@
<?php <?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; namespace Alchemy\Phrasea\SearchEngine;
abstract class AbstractConfigurationPanel implements ConfigurationPanelInterface abstract class AbstractConfigurationPanel implements ConfigurationPanelInterface
{ {
/**
* Return the path to the file where the configuration is saved
*
* @return string The path to the file
*/
public function getConfigPathFile() public function getConfigPathFile()
{ {
return __DIR__ . '/../../../../config/'.$this->getName().'.json'; return __DIR__ . '/../../../../config/'.$this->getName().'.json';
} }
/**
* {@inheritdoc}
*/
public function getAvailableDateFields(array $databoxes) public function getAvailableDateFields(array $databoxes)
{ {
$date_fields = array(); $date_fields = array();

View File

@@ -1,21 +1,67 @@
<?php <?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; namespace Alchemy\Phrasea\SearchEngine;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
interface ConfigurationPanelInterface interface ConfigurationPanelInterface
{ {
/**
* Handles the GET request to the configuration panel
*
* @param Application $app
* @param Request $request
* @return Response
*/
public function get(Application $app, Request $request); public function get(Application $app, Request $request);
/**
* Handles the POST request to the configuration panel
*
* @param Application $app
* @param Request $request
* @return Response
*/
public function post(Application $app, Request $request); public function post(Application $app, Request $request);
/**
* Return the associated search engine name
*
* @return string The name
*/
public function getName(); public function getName();
/**
* Returns the configuration of the search engine
*
* @return array The configuration
*/
public function getConfiguration(); public function getConfiguration();
/**
* Saves the search engine configuration
*
* @param array $configuration
* @return ConfigurationPanelInterface
*/
public function saveConfiguration(array $configuration); public function saveConfiguration(array $configuration);
/**
* Return the names of the date fields
*
* @param array $databoxes
* @return array An array of date fields names
*/
public function getAvailableDateFields(array $databoxes); public function getAvailableDateFields(array $databoxes);
} }

View File

@@ -1,5 +1,14 @@
<?php <?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\Phrasea; namespace Alchemy\Phrasea\SearchEngine\Phrasea;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
@@ -16,11 +25,17 @@ class ConfigurationPanel extends AbstractConfigurationPanel
$this->searchEngine = $engine; $this->searchEngine = $engine;
} }
/**
* {@inheritdoc}
*/
public function getName() public function getName()
{ {
return 'phrasea-engine'; return 'phrasea-engine';
} }
/**
* {@inheritdoc}
*/
public function get(Application $app, Request $request) public function get(Application $app, Request $request)
{ {
$configuration = $this->getConfiguration(); $configuration = $this->getConfiguration();
@@ -34,6 +49,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $app['twig']->render('admin/search-engine/phrasea.html.twig', $params); return $app['twig']->render('admin/search-engine/phrasea.html.twig', $params);
} }
/**
* {@inheritdoc}
*/
public function post(Application $app, Request $request) public function post(Application $app, Request $request)
{ {
$configuration = $this->getConfiguration(); $configuration = $this->getConfiguration();
@@ -50,6 +68,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $app->redirect($app['url_generator']->generate('admin_searchengine_get')); return $app->redirect($app['url_generator']->generate('admin_searchengine_get'));
} }
/**
* {@inheritdoc}
*/
public function getConfiguration() public function getConfiguration()
{ {
$configuration = @json_decode(file_get_contents($this->getConfigPathFile()), true); $configuration = @json_decode(file_get_contents($this->getConfigPathFile()), true);
@@ -69,6 +90,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $configuration; return $configuration;
} }
/**
* {@inheritdoc}
*/
public function saveConfiguration(array $configuration) public function saveConfiguration(array $configuration)
{ {
file_put_contents($this->getConfigPathFile(), json_encode($configuration)); file_put_contents($this->getConfigPathFile(), json_encode($configuration));

View File

@@ -47,6 +47,9 @@ class PhraseaEngine implements SearchEngineInterface
$this->options = new SearchEngineOptions(); $this->options = new SearchEngineOptions();
} }
/**
* {@inheritdoc}
*/
public function getAvailableDateFields() public function getAvailableDateFields()
{ {
if (!$this->dateFields) { if (!$this->dateFields) {
@@ -66,6 +69,9 @@ class PhraseaEngine implements SearchEngineInterface
return $this->dateFields; return $this->dateFields;
} }
/**
* {@inheritdoc}
*/
public function getConfiguration() public function getConfiguration()
{ {
if (!$this->configuration) { if (!$this->configuration) {
@@ -75,6 +81,9 @@ class PhraseaEngine implements SearchEngineInterface
return $this->configuration; return $this->configuration;
} }
/**
* {@inheritdoc}
*/
public function getDefaultSort() public function getDefaultSort()
{ {
$configuration = $this->getConfiguration(); $configuration = $this->getConfiguration();
@@ -82,6 +91,9 @@ class PhraseaEngine implements SearchEngineInterface
return $configuration['default_sort']; return $configuration['default_sort'];
} }
/**
* {@inheritdoc}
*/
public function getAvailableSort() public function getAvailableSort()
{ {
$date_fields = $this->getAvailableDateFields(); $date_fields = $this->getAvailableDateFields();
@@ -95,6 +107,9 @@ class PhraseaEngine implements SearchEngineInterface
return $sort; return $sort;
} }
/**
* {@inheritdoc}
*/
public function getAvailableOrder() public function getAvailableOrder()
{ {
return array( return array(
@@ -103,6 +118,9 @@ class PhraseaEngine implements SearchEngineInterface
); );
} }
/**
* {@inheritdoc}
*/
public function hasStemming() public function hasStemming()
{ {
return false; return false;
@@ -168,6 +186,9 @@ class PhraseaEngine implements SearchEngineInterface
return $status; return $status;
} }
/**
* {@inheritdoc}
*/
public function configurationPanel() public function configurationPanel()
{ {
if (!$this->configurationPanel) { if (!$this->configurationPanel) {

View File

@@ -30,16 +30,34 @@ interface SearchEngineInterface
*/ */
public function status(); public function status();
/**
* @return ConfigurationPanelInterface
*/
public function configurationPanel(); public function configurationPanel();
/**
* @return array an array of field names
*/
public function getAvailableDateFields(); public function getAvailableDateFields();
/**
* @return array an array containing criteria values as key and criteria names as value
*/
public function getAvailableSort(); public function getAvailableSort();
/**
* @return string The default sort
*/
public function getDefaultSort(); public function getDefaultSort();
/**
* @return array an array containing sort order values as key and sort order names as value
*/
public function getAvailableOrder(); public function getAvailableOrder();
/**
* @return Boolean return true if the search engine supports stemmed search
*/
public function hasStemming(); public function hasStemming();
/** /**
@@ -120,10 +138,30 @@ interface SearchEngineInterface
*/ */
public function removeFeedEntry(\Feed_Entry_Adapter $entry); public function removeFeedEntry(\Feed_Entry_Adapter $entry);
/**
* Update an entry in the index
*
* @param \Feed_Entry_Adapter $entry
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function updateFeedEntry(\Feed_Entry_Adapter $entry); public function updateFeedEntry(\Feed_Entry_Adapter $entry);
/**
* Set options to search-engine
*
* @param SearchEngineOptions $options
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function setOptions(SearchEngineOptions $options); public function setOptions(SearchEngineOptions $options);
/**
* Reset search-engine options
*
* @return SearchEngineInterface
* @throws RuntimeException
*/
public function resetOptions(); public function resetOptions();
/** /**

View File

@@ -103,15 +103,23 @@ class SearchEngineOptions
protected $business_fields = array(); protected $business_fields = array();
/** /**
* Defines locale code to use for query
* *
* @param string $locale * @param string $locale An i18n locale code
*/ */
public function setLocale($locale) public function setLocale($locale)
{ {
if (!preg_match('/[a-z]{2,3}/', $locale)) {
throw new \InvalidArgumentException('Locale must be a valid i18n code');
}
$this->i18n = $locale; $this->i18n = $locale;
return $this;
} }
/** /**
* Returns the locale value
* *
* @return string * @return string
*/ */
@@ -134,6 +142,12 @@ class SearchEngineOptions
return $this; return $this;
} }
/**
* Allows business fields query on the given collections
*
* @param array $collection An array of collection
* @return SearchEngineOptions
*/
public function allowBusinessFieldsOn(Array $collection) public function allowBusinessFieldsOn(Array $collection)
{ {
$this->business_fields = $collection; $this->business_fields = $collection;
@@ -141,6 +155,11 @@ class SearchEngineOptions
return $this; return $this;
} }
/**
* Reset business fields settings
*
* @return SearchEngineOptions
*/
public function disallowBusinessFields() public function disallowBusinessFields()
{ {
$this->business_fields = array(); $this->business_fields = array();
@@ -148,12 +167,19 @@ class SearchEngineOptions
return $this; return $this;
} }
/**
* Returns an array of collection on which business fields are allowed to
* search on
*
* @return array An array of collection
*/
public function businessFieldsOn() public function businessFieldsOn()
{ {
return $this->business_fields; return $this->business_fields;
} }
/** /**
* Returns the sort criteria
* *
* @return string * @return string
*/ */
@@ -163,6 +189,7 @@ class SearchEngineOptions
} }
/** /**
* Returns the sort order
* *
* @return string * @return string
*/ */
@@ -172,6 +199,7 @@ class SearchEngineOptions
} }
/** /**
* Tells whether to use stemming or not
* *
* @param boolean $boolean * @param boolean $boolean
* @return SearchEngineOptions * @return SearchEngineOptions
@@ -184,6 +212,7 @@ class SearchEngineOptions
} }
/** /**
* Return wheter the use of stemming is enabled or not
* *
* @return boolean * @return boolean
*/ */
@@ -193,6 +222,7 @@ class SearchEngineOptions
} }
/** /**
* Set document type to search for
* *
* @param int $search_type * @param int $search_type
* @return SearchEngineOptions * @return SearchEngineOptions
@@ -213,6 +243,7 @@ class SearchEngineOptions
} }
/** /**
* Returns the type of documents type to search for
* *
* @return int * @return int
*/ */
@@ -221,6 +252,12 @@ class SearchEngineOptions
return $this->search_type; return $this->search_type;
} }
/**
* Set the collections where to search for
*
* @param array $collections An array of collection
* @return SearchEngineOptions
*/
public function onCollections(Array $collections) public function onCollections(Array $collections)
{ {
$this->collections = $collections; $this->collections = $collections;
@@ -229,14 +266,21 @@ class SearchEngineOptions
} }
/** /**
* Returns the collections on which the search occurs
* *
* @return array * @return array An array of collection
*/ */
public function collections() public function collections()
{ {
return $this->collections; return $this->collections;
} }
/**
* Returns an array containing all the databoxes where the search will
* happen
*
* @return array
*/
public function databoxes() public function databoxes()
{ {
$databoxes = array(); $databoxes = array();
@@ -512,7 +556,9 @@ class SearchEngineOptions
$options->setMaxDate($value); $options->setMaxDate($value);
break; break;
case 'i18n': case 'i18n':
if ($value) {
$options->setLocale($value); $options->setLocale($value);
}
break; break;
case 'stemming': case 'stemming':
$options->useStemming($value); $options->useStemming($value);
@@ -539,7 +585,6 @@ class SearchEngineOptions
throw new \RuntimeException(sprintf('Unable to handle key `%s`', $key)); throw new \RuntimeException(sprintf('Unable to handle key `%s`', $key));
break; break;
} }
} }
if ($sort_by) { if ($sort_by) {
@@ -552,4 +597,5 @@ class SearchEngineOptions
return $options; return $options;
} }
} }

View File

@@ -33,8 +33,8 @@ class SearchEngineResult
$this->query = $query; $this->query = $query;
$this->duration = (float) $duration; $this->duration = (float) $duration;
$this->offsetStart = (int) $offsetStart; $this->offsetStart = (int) $offsetStart;
$this->available = (int)$available; $this->available = (int) $available;
$this->total = (int)$total; $this->total = (int) $total;
$this->error = $error; $this->error = $error;
$this->warning = $warning; $this->warning = $warning;
$this->suggestions = $suggestions; $this->suggestions = $suggestions;
@@ -44,62 +44,130 @@ class SearchEngineResult
return $this; return $this;
} }
/**
* An collection of results
*
* @return ArrayCollection
*/
public function results() public function results()
{ {
return $this->results; return $this->results;
} }
/**
* The query related to these results
*
* @return string
*/
public function query() public function query()
{ {
return $this->query; return $this->query;
} }
/**
* The duration of the query
*
* @return float
*/
public function duration() public function duration()
{ {
return $this->duration; return $this->duration;
} }
/**
* Return the number of page depending on the amount displayed on each page
*
* @param integer $amountPerPage
* @return integer
*/
public function totalPages($amountPerPage) public function totalPages($amountPerPage)
{ {
return ceil($this->available / $amountPerPage); return ceil($this->available / $amountPerPage);
} }
/**
* Return the number of the current page depending on the amount displayed
* on each page
*
* @param integer $amountPerPage
* @return integer
*/
public function currentPage($amountPerPage) public function currentPage($amountPerPage)
{ {
return ceil($this->offsetStart / $amountPerPage); return ceil($this->offsetStart / $amountPerPage);
} }
/**
* Return the number of results that can be returned by the search engine
*
* The difference with 'total' is that this method return the actual number
* of results that can be fetched whereas 'total' returns the number of
* results that matches the query (can be greater than available quantity)
*
* @return int
*/
public function available() public function available()
{ {
return $this->available; return $this->available;
} }
/**
* Return the number of items that match the query. Some items may be not
* retrievable. To get the number of results that can be retrieved, use
* the 'available' method
*
* @return int
*/
public function total() public function total()
{ {
return $this->total; return $this->total;
} }
/**
* Return an error message returned by the search engine
*
* @return string
*/
public function error() public function error()
{ {
return $this->error; return $this->error;
} }
/**
* Return a warning message returned by the search engine
*
* @return string
*/
public function warning() public function warning()
{ {
return $this->warning; return $this->warning;
} }
/**
* Return a collection of SearchEngineSuggestion
*
* @return ArrayCollection
*/
public function suggestions() public function suggestions()
{ {
return $this->suggestions; return $this->suggestions;
} }
/**
* Return HTML proposals
*
* @return string
*/
public function proposals() public function proposals()
{ {
return $this->propositions; return $this->propositions;
} }
/**
* Return the index name where the query happened
*
* @return string
*/
public function indexes() public function indexes()
{ {
return $this->indexes; return $this->indexes;

View File

@@ -13,8 +13,20 @@ namespace Alchemy\Phrasea\SearchEngine;
class SearchEngineSuggestion class SearchEngineSuggestion
{ {
/**
* @var string
*/
private $query; private $query;
/**
* @var string
*/
private $suggestion; private $suggestion;
/**
* @var int
*/
private $hits; private $hits;
public function __construct($query, $suggestion, $hits) public function __construct($query, $suggestion, $hits)
@@ -24,18 +36,34 @@ class SearchEngineSuggestion
$this->hits = (int) $hits; $this->hits = (int) $hits;
} }
/**
* The query related to the suggestion
*
* @return string
*/
public function query() public function query()
{ {
return $this->query; return $this->query;
} }
/**
* The actual suggestion
*
* @return string
*/
public function suggestion() public function suggestion()
{ {
return $this->suggestion; return $this->suggestion;
} }
/**
* The number of hits
*
* @return int
*/
public function hits() public function hits()
{ {
return $this->hits; return $this->hits;
} }
} }

View File

@@ -11,11 +11,6 @@
namespace Alchemy\Phrasea\SearchEngine\SphinxSearch; namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class AbstractCharset abstract class AbstractCharset
{ {
protected $table; protected $table;

View File

@@ -1,5 +1,14 @@
<?php <?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; namespace Alchemy\Phrasea\SearchEngine\SphinxSearch;
use Alchemy\Phrasea\SearchEngine\AbstractConfigurationPanel; use Alchemy\Phrasea\SearchEngine\AbstractConfigurationPanel;
@@ -19,11 +28,17 @@ class ConfigurationPanel extends AbstractConfigurationPanel
$this->searchEngine = $engine; $this->searchEngine = $engine;
} }
/**
* {@inheritdoc}
*/
public function getName() public function getName()
{ {
return 'sphinx-search'; return 'sphinx-search';
} }
/**
* {@inheritdoc}
*/
public function get(Application $app, Request $request) public function get(Application $app, Request $request)
{ {
$configuration = $this->getConfiguration(); $configuration = $this->getConfiguration();
@@ -38,6 +53,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $app['twig']->render('admin/search-engine/sphinx-search.html.twig', $params); return $app['twig']->render('admin/search-engine/sphinx-search.html.twig', $params);
} }
/**
* {@inheritdoc}
*/
public function post(Application $app, Request $request) public function post(Application $app, Request $request)
{ {
$configuration = $this->getConfiguration(); $configuration = $this->getConfiguration();
@@ -61,6 +79,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $app->redirect($app['url_generator']->generate('admin_searchengine_get')); return $app->redirect($app['url_generator']->generate('admin_searchengine_get'));
} }
/**
* {@inheritdoc}
*/
public function getConfiguration() public function getConfiguration()
{ {
$configuration = @json_decode(file_get_contents($this->getConfigPathFile()), true); $configuration = @json_decode(file_get_contents($this->getConfigPathFile()), true);
@@ -96,6 +117,9 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $configuration; return $configuration;
} }
/**
* {@inheritdoc}
*/
public function saveConfiguration(array $configuration) public function saveConfiguration(array $configuration)
{ {
file_put_contents($this->getConfigPathFile(), json_encode($configuration)); file_put_contents($this->getConfigPathFile(), json_encode($configuration));
@@ -103,6 +127,11 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $this; return $this;
} }
/**
* Returns all the charset Sphinx Search supports
*
* @return array An array of charsets
*/
public function getAvailableCharsets() public function getAvailableCharsets()
{ {
if (null !== $this->charsets) { if (null !== $this->charsets) {
@@ -127,6 +156,13 @@ class ConfigurationPanel extends AbstractConfigurationPanel
return $this->charsets; 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) public function generateSphinxConf(array $databoxes, array $configuration)
{ {
$defaults = array( $defaults = array(

View File

@@ -71,6 +71,9 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this; return $this;
} }
/**
* {@inheritdoc}
*/
public function getAvailableDateFields() public function getAvailableDateFields()
{ {
if (!$this->dateFields) { if (!$this->dateFields) {
@@ -90,11 +93,17 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this->dateFields; return $this->dateFields;
} }
/**
* {@inheritdoc}
*/
public function getDefaultSort() public function getDefaultSort()
{ {
return 'relevance'; return 'relevance';
} }
/**
* {@inheritdoc}
*/
public function getAvailableSort() public function getAvailableSort()
{ {
return array( return array(
@@ -104,6 +113,9 @@ class SphinxSearchEngine implements SearchEngineInterface
); );
} }
/**
* {@inheritdoc}
*/
public function getAvailableOrder() public function getAvailableOrder()
{ {
return array( return array(
@@ -112,11 +124,17 @@ class SphinxSearchEngine implements SearchEngineInterface
); );
} }
/**
* {@inheritdoc}
*/
public function hasStemming() public function hasStemming()
{ {
return true; return true;
} }
/**
* {@inheritdoc}
*/
public function status() public function status()
{ {
if (false === $this->sphinx->Status()) { if (false === $this->sphinx->Status()) {
@@ -135,8 +153,7 @@ class SphinxSearchEngine implements SearchEngineInterface
} }
/** /**
* * {@inheritdoc}
* @return ConfigurationPanel
*/ */
public function configurationPanel() public function configurationPanel()
{ {
@@ -156,11 +173,17 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this->configuration; return $this->configuration;
} }
/**
* {@inheritdoc}
*/
public function availableTypes() public function availableTypes()
{ {
return array(self::GEM_TYPE_RECORD, self::GEM_TYPE_STORY); return array(self::GEM_TYPE_RECORD, self::GEM_TYPE_STORY);
} }
/**
* {@inheritdoc}
*/
public function addRecord(\record_adapter $record) public function addRecord(\record_adapter $record)
{ {
if (!$this->rt_conn) { if (!$this->rt_conn) {
@@ -235,31 +258,9 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this; return $this;
} }
private function getSqlDateFields(\record_adapter $record) /**
{ * {@inheritdoc}
$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);
}
public function removeRecord(\record_adapter $record) public function removeRecord(\record_adapter $record)
{ {
if (!$this->rt_conn) { if (!$this->rt_conn) {
@@ -300,48 +301,75 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this; return $this;
} }
/**
* {@inheritdoc}
*/
public function updateRecord(\record_adapter $record) public function updateRecord(\record_adapter $record)
{ {
$this->removeRecord($record); $this->removeRecord($record);
$this->addRecord($record); $this->addRecord($record);
} }
/**
* {@inheritdoc}
*/
public function addStory(\record_adapter $record) public function addStory(\record_adapter $record)
{ {
return $this->addRecord($record); return $this->addRecord($record);
} }
/**
* {@inheritdoc}
*/
public function removeStory(\record_adapter $record) public function removeStory(\record_adapter $record)
{ {
return $this->removeRecord($record); return $this->removeRecord($record);
} }
/**
* {@inheritdoc}
*/
public function updateStory(\record_adapter $record) public function updateStory(\record_adapter $record)
{ {
return $this->updateRecord($record); return $this->updateRecord($record);
} }
/**
* {@inheritdoc}
*/
public function addFeedEntry(\Feed_Entry_Adapter $entry) public function addFeedEntry(\Feed_Entry_Adapter $entry)
{ {
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine'); throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
} }
/**
* {@inheritdoc}
*/
public function removeFeedEntry(\Feed_Entry_Adapter $entry) public function removeFeedEntry(\Feed_Entry_Adapter $entry)
{ {
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine'); throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
} }
/**
* {@inheritdoc}
*/
public function updateFeedEntry(\Feed_Entry_Adapter $entry) public function updateFeedEntry(\Feed_Entry_Adapter $entry)
{ {
throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine'); throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine');
} }
/**
* {@inheritdoc}
*/
public function setOptions(SearchEngineOptions $options) public function setOptions(SearchEngineOptions $options)
{ {
$this->options = $options; $this->options = $options;
$this->applyOptions($options); $this->applyOptions($options);
} }
/**
* {@inheritdoc}
*/
public function resetOptions() public function resetOptions()
{ {
$this->options = new SearchEngineOptions(); $this->options = new SearchEngineOptions();
@@ -354,6 +382,9 @@ class SphinxSearchEngine implements SearchEngineInterface
$this->sphinx->ResetFilters(); $this->sphinx->ResetFilters();
} }
/**
* {@inheritdoc}
*/
public function query($query, $offset, $perPage) public function query($query, $offset, $perPage)
{ {
assert(is_int($offset)); 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); return new SearchEngineResult($results, $query, $duration, $offset, $available, $total, $error, $warning, $suggestions, $propositions, $index);
} }
/**
* {@inheritdoc}
*/
public function autocomplete($query) public function autocomplete($query)
{ {
$words = explode(" ", $this->cleanupQuery($query)); $words = explode(" ", $this->cleanupQuery($query));
@@ -430,6 +464,9 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this->getSuggestions(array_pop($words)); return $this->getSuggestions(array_pop($words));
} }
/**
* {@inheritdoc}
*/
public function excerpt($query, $fields, \record_adapter $record) public function excerpt($query, $fields, \record_adapter $record)
{ {
$index = ''; $index = '';
@@ -462,6 +499,9 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this->sphinx->BuildExcerpts($fields_to_send, $index, $query, $opts); return $this->sphinx->BuildExcerpts($fields_to_send, $index, $query, $opts);
} }
/**
* {@inheritdoc}
*/
public function resetCache() public function resetCache()
{ {
return $this; return $this;
@@ -608,6 +648,31 @@ class SphinxSearchEngine implements SearchEngineInterface
return $this; 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 * Remove all keywords, operators, quotes from a query string
* *