summaryrefslogtreecommitdiffstats
path: root/service/itemservice.php
diff options
context:
space:
mode:
Diffstat (limited to 'service/itemservice.php')
-rw-r--r--service/itemservice.php52
1 files changed, 41 insertions, 11 deletions
diff --git a/service/itemservice.php b/service/itemservice.php
index 900da3fb3..6f454dbf5 100644
--- a/service/itemservice.php
+++ b/service/itemservice.php
@@ -13,13 +13,14 @@
namespace OCA\News\Service;
-use \OCP\AppFramework\Db\DoesNotExistException;
-use \OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IConfig;
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Utility\ITimeFactory;
-use \OCA\News\Db\ItemMapper;
-use \OCA\News\Db\StatusFlag;
-use \OCA\News\Db\FeedType;
-use \OCA\News\Config\Config;
+use OCA\News\Db\ItemMapper;
+use OCA\News\Db\StatusFlag;
+use OCA\News\Db\FeedType;
+use OCA\News\Config\Config;
class ItemService extends Service {
@@ -28,16 +29,19 @@ class ItemService extends Service {
private $config;
private $timeFactory;
private $itemMapper;
+ private $systemConfig;
public function __construct(ItemMapper $itemMapper,
StatusFlag $statusFlag,
ITimeFactory $timeFactory,
- Config $config){
+ Config $config,
+ IConfig $systemConfig){
parent::__construct($itemMapper);
$this->statusFlag = $statusFlag;
$this->config = $config;
$this->timeFactory = $timeFactory;
$this->itemMapper = $itemMapper;
+ $this->systemConfig = $systemConfig;
}
@@ -80,24 +84,28 @@ class ItemService extends Service {
* @param boolean $showAll if unread items should also be returned
* @param boolean $oldestFirst if it should be ordered by oldest first
* @param string $userId the name of the user
+ * @param string[] $search an array of keywords that the result should
+ * contain in either the author, title, link or body
* @return array of items
*/
public function findAll($id, $type, $limit, $offset, $showAll, $oldestFirst,
- $userId){
+ $userId, $search=[]){
$status = $this->statusFlag->typeToStatus($type, $showAll);
switch($type){
case FeedType::FEED:
return $this->itemMapper->findAllFeed(
- $id, $limit, $offset, $status, $oldestFirst, $userId
+ $id, $limit, $offset, $status, $oldestFirst, $userId,
+ $search
);
case FeedType::FOLDER:
return $this->itemMapper->findAllFolder(
- $id, $limit, $offset, $status, $oldestFirst, $userId
+ $id, $limit, $offset, $status, $oldestFirst, $userId,
+ $search
);
default:
return $this->itemMapper->findAll(
- $limit, $offset, $status, $oldestFirst, $userId
+ $limit, $offset, $status, $oldestFirst, $userId, $search
);
}
}
@@ -248,4 +256,26 @@ class ItemService extends Service {
}
+ /**
+ * Regenerates the search index for all items
+ */
+ public function generateSearchIndicies($progressbar) {
+ $this->systemConfig->setSystemValue('maintenance', true);
+
+ $rows = $this->itemMapper->findAllItemIdsAndUsers();
+ $progressbar = $progressbar(count($rows));
+ $progressbar->setFormat('verbose');
+
+ foreach ($rows as $row) {
+ $item = $this->find($row['id'], $row['user_id']);
+ $item->generateSearchIndex();
+ $this->itemMapper->update($item);
+ $progressbar->advance();
+ }
+
+ $progressbar->finish();
+
+ $this->systemConfig->setSystemValue('maintenance', false);
+ }
+
}