Create Search model

This commit is contained in:
Frederic Guillot 2016-08-18 22:20:49 -04:00
parent 309ccf0a32
commit 7e20a3fdc3
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
6 changed files with 49 additions and 41 deletions

View File

@ -9,8 +9,8 @@ Router\get_action('search', function() {
$items = array(); $items = array();
$nb_items = 0; $nb_items = 0;
if ($text) { if ($text) {
$items = Model\Item\search_all($text, $offset, Model\Config\get('items_per_page')); $items = Model\Search\get_all_items($text, $offset, Model\Config\get('items_per_page'));
$nb_items = Model\Item\count_by_search($text); $nb_items = Model\Search\count_items($text);
} }
Response\html(Template\layout('search', array( Response\html(Template\layout('search', array(

View File

@ -64,45 +64,6 @@ function get_all_since($timestamp)
->findAll(); ->findAll();
} }
function search_all($text, $offset = null, $limit = null)
{
return Database::getInstance('db')
->table('items')
->columns(
'items.id',
'items.title',
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.bookmark',
'items.feed_id',
'items.status',
'items.content',
'items.language',
'items.author',
'feeds.site_url',
'feeds.title AS feed_title',
'feeds.rtl'
)
->join('feeds', 'id', 'feed_id')
->neq('status', 'removed')
->ilike('items.title', '%' . $text . '%')
->orderBy('updated', 'desc')
->offset($offset)
->limit($limit)
->findAll();
}
function count_by_search($text)
{
return Database::getInstance('db')
->table('items')
->neq('status', 'removed')
->ilike('title', '%' . $text . '%')
->count();
}
function get_latest_feeds_items() function get_latest_feeds_items()
{ {
return Database::getInstance('db') return Database::getInstance('db')

44
app/models/search.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace Model\Search;
use PicoDb\Database;
function count_items($text)
{
return Database::getInstance('db')
->table('items')
->neq('status', 'removed')
->ilike('title', '%' . $text . '%')
->count();
}
function get_all_items($text, $offset = null, $limit = null)
{
return Database::getInstance('db')
->table('items')
->columns(
'items.id',
'items.title',
'items.updated',
'items.url',
'items.enclosure',
'items.enclosure_type',
'items.bookmark',
'items.feed_id',
'items.status',
'items.content',
'items.language',
'items.author',
'feeds.site_url',
'feeds.title AS feed_title',
'feeds.rtl'
)
->join('feeds', 'id', 'feed_id')
->neq('status', 'removed')
->ilike('items.title', '%' . $text . '%')
->orderBy('updated', 'desc')
->offset($offset)
->limit($limit)
->findAll();
}

View File

@ -40,6 +40,7 @@
"app/core/template.php", "app/core/template.php",
"app/models/config.php", "app/models/config.php",
"app/models/service.php", "app/models/service.php",
"app/models/search.php",
"app/models/user.php", "app/models/user.php",
"app/models/feed.php", "app/models/feed.php",
"app/models/item.php", "app/models/item.php",

View File

@ -21,6 +21,7 @@ return array(
'93228d441890e5962b0566344884332c' => $baseDir . '/app/core/template.php', '93228d441890e5962b0566344884332c' => $baseDir . '/app/core/template.php',
'bc98222aedc910930f5b76b8c84f334e' => $baseDir . '/app/models/config.php', 'bc98222aedc910930f5b76b8c84f334e' => $baseDir . '/app/models/config.php',
'c3080c7edf4a590ce36fc4f3561968dc' => $baseDir . '/app/models/service.php', 'c3080c7edf4a590ce36fc4f3561968dc' => $baseDir . '/app/models/service.php',
'b59348c9973f21f2c58eb493d9fea5be' => $baseDir . '/app/models/search.php',
'73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php', '73671a34a21e27508f85cea36a9837de' => $baseDir . '/app/models/user.php',
'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php', 'e8bcd5701df9db676003b87e27b091c9' => $baseDir . '/app/models/feed.php',
'7318478c1ab18cc398507355a29a93c3' => $baseDir . '/app/models/item.php', '7318478c1ab18cc398507355a29a93c3' => $baseDir . '/app/models/item.php',

View File

@ -22,6 +22,7 @@ class ComposerStaticInitfd7e8d436e1dc450edc3153ac8bc31b4
'93228d441890e5962b0566344884332c' => __DIR__ . '/../..' . '/app/core/template.php', '93228d441890e5962b0566344884332c' => __DIR__ . '/../..' . '/app/core/template.php',
'bc98222aedc910930f5b76b8c84f334e' => __DIR__ . '/../..' . '/app/models/config.php', 'bc98222aedc910930f5b76b8c84f334e' => __DIR__ . '/../..' . '/app/models/config.php',
'c3080c7edf4a590ce36fc4f3561968dc' => __DIR__ . '/../..' . '/app/models/service.php', 'c3080c7edf4a590ce36fc4f3561968dc' => __DIR__ . '/../..' . '/app/models/service.php',
'b59348c9973f21f2c58eb493d9fea5be' => __DIR__ . '/../..' . '/app/models/search.php',
'73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php', '73671a34a21e27508f85cea36a9837de' => __DIR__ . '/../..' . '/app/models/user.php',
'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php', 'e8bcd5701df9db676003b87e27b091c9' => __DIR__ . '/../..' . '/app/models/feed.php',
'7318478c1ab18cc398507355a29a93c3' => __DIR__ . '/../..' . '/app/models/item.php', '7318478c1ab18cc398507355a29a93c3' => __DIR__ . '/../..' . '/app/models/item.php',