Merge branch 'aledeg-change-filter' into dev

pull/800/head
Marien Fressinaud 10 years ago
commit cdd653ce53
  1. 2
      app/Controllers/indexController.php
  2. 2
      app/Models/Context.php
  3. 84
      app/Models/EntryDAO.php
  4. 8
      app/Models/Search.php
  5. 2
      tests/app/Models/SearchTest.php

@ -173,7 +173,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ; FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ;
} }
FreshRSS_Context::$search = Minz_Request::param('search', ''); FreshRSS_Context::$search = new FreshRSS_Search(Minz_Request::param('search', ''));
FreshRSS_Context::$order = Minz_Request::param( FreshRSS_Context::$order = Minz_Request::param(
'order', FreshRSS_Context::$user_conf->sort_order 'order', FreshRSS_Context::$user_conf->sort_order
); );

@ -30,7 +30,7 @@ class FreshRSS_Context {
public static $state = 0; public static $state = 0;
public static $order = 'DESC'; public static $order = 'DESC';
public static $number = 0; public static $number = 0;
public static $search = ''; public static $search;
public static $first_id = ''; public static $first_id = '';
public static $next_id = ''; public static $next_id = '';
public static $id_max = ''; public static $id_max = '';

@ -441,54 +441,46 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
$where .= 'AND e1.id >= ' . $date_min . '000000 '; $where .= 'AND e1.id >= ' . $date_min . '000000 ';
} }
$search = ''; $search = '';
if ($filter !== '') { if ($filter !== null) {
require_once(LIB_PATH . '/lib_date.php'); if ($filter->getIntitle()) {
$filter = trim($filter); $search .= 'AND e1.title LIKE ? ';
$filter = addcslashes($filter, '\\%_'); $values[] = "%{$filter->getIntitle()}%";
$terms = array_unique(explode(' ', $filter)); }
//sort($terms); //Put #tags first //TODO: Put the cheapest filters first if ($filter->getInurl()) {
foreach ($terms as $word) { $search .= 'AND CONCAT(e1.link, e1.guid) LIKE ? ';
$word = trim($word); $values[] = "%{$filter->getInurl()}%";
if (stripos($word, 'intitle:') === 0) { }
$word = substr($word, strlen('intitle:')); if ($filter->getAuthor()) {
$search .= 'AND e1.title LIKE ? '; $search .= 'AND e1.author LIKE ? ';
$values[] = '%' . $word .'%'; $values[] = "%{$filter->getAuthor()}%";
} elseif (stripos($word, 'inurl:') === 0) { }
$word = substr($word, strlen('inurl:')); if ($filter->getMinDate()) {
$search .= 'AND CONCAT(e1.link, e1.guid) LIKE ? '; $search .= 'AND e1.id >= ? ';
$values[] = '%' . $word .'%'; $values[] = "{$filter->getMinDate()}000000";
} elseif (stripos($word, 'author:') === 0) { }
$word = substr($word, strlen('author:')); if ($filter->getMaxDate()) {
$search .= 'AND e1.author LIKE ? '; $search .= 'AND e1.id <= ?';
$values[] = '%' . $word .'%'; $values[] = "{$filter->getMaxDate()}000000";
} elseif (stripos($word, 'date:') === 0) { }
$word = substr($word, strlen('date:')); if ($filter->getMinPubdate()) {
list($minDate, $maxDate) = parseDateInterval($word); $search .= 'AND e1.date >= ? ';
if ($minDate) { $values[] = $filter->getMinPubdate();
$search .= 'AND e1.id >= ' . $minDate . '000000 '; }
} if ($filter->getMaxPubdate()) {
if ($maxDate) { $search .= 'AND e1.date <= ? ';
$search .= 'AND e1.id <= ' . $maxDate . '000000 '; $values[] = $filter->getMaxPubdate();
} }
} elseif (stripos($word, 'pubdate:') === 0) { if ($filter->getTags()) {
$word = substr($word, strlen('pubdate:')); $tags = $filter->getTags();
list($minDate, $maxDate) = parseDateInterval($word); foreach ($tags as $tag) {
if ($minDate) { $search .= 'AND e1.tags LIKE ? ';
$search .= 'AND e1.date >= ' . $minDate . ' '; $values[] = "%{$tag}%";
}
if ($maxDate) {
$search .= 'AND e1.date <= ' . $maxDate . ' ';
}
} else {
if ($word[0] === '#' && isset($word[1])) {
$search .= 'AND e1.tags LIKE ? ';
$values[] = '%' . $word .'%';
} else {
$search .= 'AND ' . $this->sqlconcat('e1.title', $this->isCompressed() ? 'UNCOMPRESS(content_bin)' : 'content') . ' LIKE ? ';
$values[] = '%' . $word .'%';
}
} }
} }
if ($filter->getSearch()) {
$search .= 'AND ' . $this->sqlconcat('e1.title', $this->isCompressed() ? 'UNCOMPRESS(content_bin)' : 'content') . ' LIKE ? ';
$values[] = "%{$filter->getSearch()}%";
}
} }
return array($values, return array($values,

@ -1,5 +1,7 @@
<?php <?php
require_once(LIB_PATH . '/lib_date.php');
/** /**
* Contains a search from the search form. * Contains a search from the search form.
* *
@ -9,7 +11,7 @@
class FreshRSS_Search { class FreshRSS_Search {
// This contains the user input string // This contains the user input string
private $raw_input; private $raw_input = '';
// The following properties are extracted from the raw input // The following properties are extracted from the raw input
private $intitle; private $intitle;
private $min_date; private $min_date;
@ -34,6 +36,10 @@ class FreshRSS_Search {
$input = $this->parseTagsSeach($input); $input = $this->parseTagsSeach($input);
$this->search = $this->cleanSearch($input); $this->search = $this->cleanSearch($input);
} }
public function __toString() {
return $this->getRawInput();
}
public function getRawInput() { public function getRawInput() {
return $this->raw_input; return $this->raw_input;

@ -10,7 +10,7 @@ class SearchTest extends \PHPUnit_Framework_TestCase {
*/ */
public function test__construct_whenInputIsEmpty_getsOnlyNullValues($input) { public function test__construct_whenInputIsEmpty_getsOnlyNullValues($input) {
$search = new FreshRSS_Search($input); $search = new FreshRSS_Search($input);
$this->assertNull($search->getRawInput()); $this->assertEquals('', $search->getRawInput());
$this->assertNull($search->getIntitle()); $this->assertNull($search->getIntitle());
$this->assertNull($search->getMinDate()); $this->assertNull($search->getMinDate());
$this->assertNull($search->getMaxDate()); $this->assertNull($search->getMaxDate());

Loading…
Cancel
Save