Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-07-23 13:52:39 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-07-23 13:52:39 +0300
commite5ee263a741b4ec5fd63b6894df5ed088ee4a2b8 (patch)
tree1ddb567d68a5cf2cf7e544217d65c86a382759e8 /lib
parentd927618296d740104c2439667c245e3f8a8efa98 (diff)
add IndexOption
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Index.php82
-rw-r--r--lib/IFullTextSearchProvider.php7
-rw-r--r--lib/Model/IndexOptions.php79
-rw-r--r--lib/Service/IndexService.php14
4 files changed, 172 insertions, 10 deletions
diff --git a/lib/Command/Index.php b/lib/Command/Index.php
index 1f4e7e4..8f360b9 100644
--- a/lib/Command/Index.php
+++ b/lib/Command/Index.php
@@ -29,6 +29,7 @@ namespace OCA\FullTextSearch\Command;
use Exception;
use OCA\FullTextSearch\IFullTextSearchProvider;
use OCA\FullTextSearch\Model\ExtendedBase;
+use OCA\FullTextSearch\Model\IndexOptions;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Service\IndexService;
use OCA\FullTextSearch\Service\MiscService;
@@ -36,6 +37,7 @@ use OCA\FullTextSearch\Service\PlatformService;
use OCA\FullTextSearch\Service\ProviderService;
use OCA\FullTextSearch\Service\RunningService;
use OCP\IUserManager;
+use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -95,7 +97,8 @@ class Index extends ExtendedBase {
protected function configure() {
parent::configure();
$this->setName('fulltextsearch:index')
- ->setDescription('Index files');
+ ->setDescription('Index files')
+ ->addArgument('options', InputArgument::OPTIONAL, 'options');
}
@@ -107,6 +110,7 @@ class Index extends ExtendedBase {
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
+ $options = $this->generateIndexOptions($input);
try {
$this->runner->sourceIsCommandLine($this, $output);
@@ -114,9 +118,15 @@ class Index extends ExtendedBase {
$providers = $this->providerService->getProviders();
foreach ($providers as $provider) {
+
+ if (!$this->isIncludedProvider($options, $provider->getId())) {
+ continue;
+ }
+
$this->runner->output('indexing ' . $provider->getName() . '.');
$provider->setRunner($this->runner);
- $this->indexProvider($provider);
+ $provider->setIndexOptions($options);
+ $this->indexProvider($provider, $options);
}
} catch (Exception $e) {
@@ -130,22 +140,26 @@ class Index extends ExtendedBase {
/**
* @param IFullTextSearchProvider $provider
+ * @param IndexOptions $options
*
* @throws Exception
*/
- private function indexProvider(IFullTextSearchProvider $provider) {
+ private function indexProvider(IFullTextSearchProvider $provider, IndexOptions $options) {
$platform = $this->platformService->getPlatform();
$platform->initializeIndex();
$provider->onInitializingIndex($platform);
$platform->setRunner($this->runner);
- $users = $this->userManager->search('');
-
+ $users = $this->generateUserList($options);
foreach ($users as $user) {
+ if ($user === null) {
+ continue;
+ }
+
$this->runner->output(' USER: ' . $user->getUID());
$this->indexService->indexProviderContentFromUser(
- $platform, $provider, $user->getUID()
+ $platform, $provider, $user->getUID(), $options
);
}
@@ -153,6 +167,62 @@ class Index extends ExtendedBase {
}
+
+ /**
+ * @param InputInterface $input
+ *
+ * @return IndexOptions
+ */
+ private function generateIndexOptions(InputInterface $input) {
+ $jsonOptions = $input->getArgument('options');
+ $options = json_decode($jsonOptions, true);
+
+ if (!is_array($options)) {
+ $options = [];
+ }
+
+ return new IndexOptions($options);
+ }
+
+
+ /**
+ * @param IndexOptions $options
+ * @param string $providerId
+ *
+ * @return bool
+ */
+ private function isIncludedProvider(IndexOptions $options, $providerId) {
+ if ($options->getOption('provider', '') !== ''
+ && $options->getOption('provider') !== $providerId) {
+ return false;
+ }
+
+ if ($options->getOption('providers', null) !== null
+ && is_array($options->getOption('providers'))) {
+ return (in_array($providerId, $options->getOption('providers')));
+ }
+
+ return true;
+ }
+
+
+ /**
+ * @param IndexOptions $options
+ *
+ * @return array
+ */
+ private function generateUserList(IndexOptions $options) {
+ if ($options->getOption('user', '') !== '') {
+ return [$this->userManager->get($options->getOption('user'))];
+ }
+
+ if ($options->getOption('users', null) !== null
+ && is_array($options->getOption('users'))) {
+ return array_map([$this->userManager, 'get'], $options->getOption('users'));
+ }
+
+ return $this->userManager->search('');
+ }
}
diff --git a/lib/IFullTextSearchProvider.php b/lib/IFullTextSearchProvider.php
index 7522683..6ff76ea 100644
--- a/lib/IFullTextSearchProvider.php
+++ b/lib/IFullTextSearchProvider.php
@@ -29,6 +29,7 @@ namespace OCA\FullTextSearch;
use OC\User\NoUserException;
use OCA\FullTextSearch\Model\Index;
use OCA\FullTextSearch\Model\IndexDocument;
+use OCA\FullTextSearch\Model\IndexOptions;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Model\SearchRequest;
use OCA\FullTextSearch\Model\SearchResult;
@@ -92,6 +93,12 @@ interface IFullTextSearchProvider {
public function setRunner(Runner $runner);
+// /**
+// * @param IndexOptions $options
+// */
+// public function setIndexOptions($options);
+
+
/**
* returns all indexable document for a user.
* There is no need to fill the document with content at this point.
diff --git a/lib/Model/IndexOptions.php b/lib/Model/IndexOptions.php
new file mode 100644
index 0000000..6f8e9bc
--- /dev/null
+++ b/lib/Model/IndexOptions.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * FullTextSearch - Full text search framework for Nextcloud
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\FullTextSearch\Model;
+
+
+class IndexOptions {
+
+ /**
+ * @var array
+ */
+ private $options = [];
+
+
+ public function __construct($options = []) {
+ $this->options = $options;
+ }
+
+ /**
+ * @return array
+ */
+ public function getOptions() {
+ return $this->options;
+ }
+
+ /**
+ * @param array $options
+ */
+ public function setOptions($options) {
+ $this->options = $options;
+ }
+
+ /**
+ * @param string $k
+ * @param string $v
+ */
+ public function addOption($k, $v) {
+ $this->options[$k] = $v;
+ }
+
+
+ /**
+ * @param string $k
+ * @param string $default
+ *
+ * @return array|string
+ */
+ public function getOption($k, $default = '') {
+ if (array_key_exists($k, $this->options)) {
+ return $this->options[$k];
+ }
+
+ return $default;
+ }
+
+} \ No newline at end of file
diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php
index 912c922..0bc9751 100644
--- a/lib/Service/IndexService.php
+++ b/lib/Service/IndexService.php
@@ -38,6 +38,7 @@ use OCA\FullTextSearch\IFullTextSearchProvider;
use OCA\FullTextSearch\Model\ExtendedIndex;
use OCA\FullTextSearch\Model\Index;
use OCA\FullTextSearch\Model\IndexDocument;
+use OCA\FullTextSearch\Model\IndexOptions;
use OCA\FullTextSearch\Model\ProviderIndexes;
use OCA\FullTextSearch\Model\Runner;
@@ -111,18 +112,21 @@ class IndexService {
* @param IFullTextSearchPlatform $platform
* @param IFullTextSearchProvider $provider
* @param string $userId
+ * @param IndexOptions $options
*
+ * @throws InterruptException
+ * @throws TickDoesNotExistException
* @throws Exception
*/
public function indexProviderContentFromUser(
- IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $userId
+ IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $userId, $options
) {
$this->updateRunner('generateIndex' . $provider->getName());
$documents = $provider->generateIndexableDocuments($userId);
//$maxSize = sizeof($documents);
- $toIndex = $this->updateDocumentsWithCurrIndex($provider, $documents);
+ $toIndex = $this->updateDocumentsWithCurrIndex($provider, $documents, $options);
$this->indexChunks($platform, $provider, $toIndex);
}
@@ -130,13 +134,14 @@ class IndexService {
/**
* @param IFullTextSearchProvider $provider
* @param IndexDocument[] $documents
+ * @param IndexOptions $options
*
* @return IndexDocument[]
* @throws InterruptException
* @throws TickDoesNotExistException
*/
private function updateDocumentsWithCurrIndex(
- IFullTextSearchProvider $provider, array $documents
+ IFullTextSearchProvider $provider, array $documents, $options
) {
$currIndex = $this->getProviderIndexFromProvider($provider);
@@ -152,7 +157,8 @@ class IndexService {
}
$document->setIndex($index);
- if (!$this->isDocumentUpToDate($provider, $document)) {
+ if ($options->getOption('force', false) === true
+ || !$this->isDocumentUpToDate($provider, $document)) {
$result[] = $document;
}