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>2019-07-18 02:48:38 +0300
committerMaxence Lange <maxence@artificial-owl.com>2019-07-18 02:48:38 +0300
commit1c25fcab5c000501b4f600c7d767497c2f0868cf (patch)
tree6e6fa6821c6181cbbb588d33983cbb9461e7a228 /lib
parent167f4c4b9399fc61987c86e8c1a8d184a806420e (diff)
./occ fulltextsearch:document:index
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/DocumentIndex.php160
1 files changed, 160 insertions, 0 deletions
diff --git a/lib/Command/DocumentIndex.php b/lib/Command/DocumentIndex.php
new file mode 100644
index 0000000..b2d8e85
--- /dev/null
+++ b/lib/Command/DocumentIndex.php
@@ -0,0 +1,160 @@
+<?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/>.
+ *
+ */
+
+declare(strict_types=1);
+
+
+/**
+ * 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\Command;
+
+
+use Exception;
+use OC\Core\Command\Base;
+use OCA\FullTextSearch\Model\Index;
+use OCA\FullTextSearch\Service\MiscService;
+use OCA\FullTextSearch\Service\PlatformService;
+use OCA\FullTextSearch\Service\ProviderService;
+use OCP\FullTextSearch\Model\IIndexDocument;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+
+/**
+ * Class DocumentProvider
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class DocumentIndex extends Base {
+
+
+ /** @var ProviderService */
+ private $providerService;
+
+ /** @var PlatformService */
+ private $platformService;
+
+ /** @var MiscService */
+ private $miscService;
+
+
+ /**
+ * Index constructor.
+ *
+ * @param ProviderService $providerService
+ * @param PlatformService $platformService
+ * @param MiscService $miscService
+ */
+ public function __construct(
+ ProviderService $providerService, PlatformService $platformService, MiscService $miscService
+ ) {
+ parent::__construct();
+
+ $this->providerService = $providerService;
+ $this->platformService = $platformService;
+ $this->miscService = $miscService;
+ }
+
+
+ /**
+ *
+ */
+ protected function configure() {
+ parent::configure();
+ $this->setName('fulltextsearch:document:index')
+ ->setDescription('index one specific document')
+ ->addArgument('userId', InputArgument::REQUIRED, 'userId')
+ ->addArgument('providerId', InputArgument::REQUIRED, 'providerId')
+ ->addArgument('documentId', InputArgument::REQUIRED, 'documentId');
+ }
+
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @throws Exception
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $providerId = $input->getArgument('providerId');
+ $documentId = $input->getArgument('documentId');
+ $userId = $input->getArgument('userId');
+
+ $providerWrapper = $this->providerService->getProvider($providerId);
+ $provider = $providerWrapper->getProvider();
+
+ $index = new Index($providerId, $documentId);
+ $index->setOwnerId($userId);
+ $index->setStatus(Index::INDEX_FULL);
+ $indexDocument = $provider->updateDocument($index);
+ if (!$indexDocument->hasIndex()) {
+ $indexDocument->setIndex($index);
+ }
+
+ if ($indexDocument->getIndex()
+ ->isStatus(Index::INDEX_REMOVE)) {
+ throw new Exception('Unknown document');
+ }
+
+ $platformWrapper = $this->platformService->getPlatform();
+ $platform = $platformWrapper->getPlatform();
+
+ $indexDocument->getIndex()
+ ->setStatus(Index::INDEX_FULL);
+ $platform->indexDocument($indexDocument);
+ }
+
+
+}
+
+
+