diff options
| author | 2013-11-30 17:21:26 +0100 | |
|---|---|---|
| committer | 2013-11-30 17:21:26 +0100 | |
| commit | 37ce14c093c3dd009bcd7b627c5e819ac88dd5b7 (patch) | |
| tree | 0edf7fc2c7505c8b70fd0722fb7abfbf058fd814 /app/models/EntriesGetter.php | |
| parent | e98b7ab13ec414d1c5c3c3d1d6a7c9995ebf4fea (diff) | |
Recherche côté SQL avec LIKE
Premier essai de recherche côté base de données (à améliorer)
https://github.com/marienfressinaud/FreshRSS/issues/204
Pour l'instant fait avec du LIKE et pas d'indexation texte complet.
* Suppression de EntriesGetter car le code est devenu plus simple grâce
au filtrage côté SQL
* Uniformisation de get_c à une lettre ('all' devient 'a','favoris'
devient 's' - pour "starred") pour simplifier le code
* low_to_high par DESC, high_to_low par ASC
* Réduction du nombre de créations de *DAO dans indexController
* Refactorisation de checkAndProcessType()
Pas encore trop testé...
Diffstat (limited to 'app/models/EntriesGetter.php')
| -rw-r--r-- | app/models/EntriesGetter.php | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/app/models/EntriesGetter.php b/app/models/EntriesGetter.php deleted file mode 100644 index ce026f252..000000000 --- a/app/models/EntriesGetter.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -class EntriesGetter { - private $type = array ( - 'type' => 'all', - 'id' => 'all' - ); - private $state = 'all'; - private $filter = array ( - 'words' => array (), - 'tags' => array (), - ); - private $order = 'high_to_low'; - private $entries = array (); - - private $nb = 1; - private $first = ''; - private $next = ''; - - public function __construct ($type, $state, $filter, $order, $nb, $first = '') { - $this->_type ($type); - $this->_state ($state); - $this->_filter ($filter); - $this->_order ($order); - $this->nb = $nb; - $this->first = $first; - } - - public function type () { - return $this->type; - } - public function state () { - return $this->state; - } - public function filter () { - return $this->filter; - } - public function order () { - return $this->order; - } - public function entries () { - return $this->entries; - } - - public function _type ($value) { - if (!is_array ($value) || - !isset ($value['type']) || - !isset ($value['id'])) { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - $type = $value['type']; - $id = $value['id']; - - if ($type != 'all' && $type != 'favoris' && $type != 'public' && $type != 'c' && $type != 'f') { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - if (($type == 'all' || $type == 'favoris' || $type == 'public') && - ($type != $id)) { - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->type = $value; - } - public function _state ($value) { - if ($value != 'all' && $value != 'not_read' && $value != 'read') { - throw new EntriesGetterException ('Bad state line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->state = $value; - } - public function _filter ($value) { - $value = trim ($value); - $terms = explode (' ', $value); - - foreach ($terms as $word) { - if (!empty ($word) && $word[0] == '#' && isset ($word[1])) { - $tag = substr ($word, 1); - $this->filter['tags'][$tag] = $tag; - } elseif (!empty ($word)) { - $this->filter['words'][$word] = $word; - } - } - } - public function _order ($value) { - if ($value != 'high_to_low' && $value != 'low_to_high') { - throw new EntriesGetterException ('Bad order line ' . __LINE__ . ' in file ' . __FILE__); - } - - $this->order = $value; - } - - public function execute () { - $entryDAO = new EntryDAO (); - - HelperEntry::$nb = $this->nb; //TODO: Update: Now done in SQL - HelperEntry::$first = $this->first; //TODO: Update: Now done in SQL - HelperEntry::$filter = $this->filter; - - $sqlLimit = (empty ($this->filter['words']) && empty ($this->filter['tags'])) ? $this->nb : ''; //Disable SQL LIMIT optimisation during search //TODO: Do better! - - switch ($this->type['type']) { - case 'all': - list ($this->entries, $this->next) = $entryDAO->listEntries ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'favoris': - list ($this->entries, $this->next) = $entryDAO->listFavorites ( - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'c': - list ($this->entries, $this->next) = $entryDAO->listByCategory ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - case 'f': - list ($this->entries, $this->next) = $entryDAO->listByFeed ( - $this->type['id'], - $this->state, - $this->order, - $this->first, - $sqlLimit - ); - break; - default: - throw new EntriesGetterException ('Bad type line ' . __LINE__ . ' in file ' . __FILE__); - } - } - - public function getPaginator () { - $paginator = new RSSPaginator ($this->entries, $this->next); - - return $paginator; - } -} |
