summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-11-02 08:38:02 +0100
committerGitHub <noreply@github.com>2018-11-02 08:38:02 +0100
commitcd729b696b866e123fcb4a60d74458f1c8d9b0f8 (patch)
tree81ceebc41d4928465a62d71b690c939f547d3456 /lib
parent2cae91904c14f66aae26b0066a0c8cbfbe9a4c38 (diff)
parent70b8c5672b0f4b267f298a5c702a6b82250413dd (diff)
downloadnextcloud-server-cd729b696b866e123fcb4a60d74458f1c8d9b0f8.tar.gz
nextcloud-server-cd729b696b866e123fcb4a60d74458f1c8d9b0f8.zip
Merge pull request #12193 from nextcloud/interface-fulltxtsearch-issue-00002
+infoBool / +infoInt
Diffstat (limited to 'lib')
-rw-r--r--lib/public/FullTextSearch/Model/IndexDocument.php82
1 files changed, 79 insertions, 3 deletions
diff --git a/lib/public/FullTextSearch/Model/IndexDocument.php b/lib/public/FullTextSearch/Model/IndexDocument.php
index a73b702e506..78679ac6225 100644
--- a/lib/public/FullTextSearch/Model/IndexDocument.php
+++ b/lib/public/FullTextSearch/Model/IndexDocument.php
@@ -57,10 +57,10 @@ class IndexDocument implements JsonSerializable {
/** @var string */
- protected $id;
+ protected $id = '';
/** @var string */
- protected $providerId;
+ protected $providerId = '';
/** @var DocumentAccess */
protected $access;
@@ -111,7 +111,7 @@ class IndexDocument implements JsonSerializable {
protected $info = [];
/** @var int */
- protected $contentEncoded;
+ protected $contentEncoded = 0;
/**
@@ -819,6 +819,82 @@ class IndexDocument implements JsonSerializable {
}
/**
+ * Set some information about the original document that will be available
+ * to the front-end when displaying search result. (as int)
+ * Because this information will not be indexed, this method can also be
+ * used to manage some data while filling the IndexDocument before its
+ * indexing.
+ *
+ * @since 15.0.0
+ *
+ * @param string $info
+ * @param int $value
+ *
+ * @return IndexDocument
+ */
+ final public function setInfoInt(string $info, int $value): IndexDocument {
+ $this->info[$info] = $value;
+
+ return $this;
+ }
+
+ /**
+ * Get an information about a document. (int)
+ *
+ * @since 15.0.0
+ *
+ * @param string $info
+ * @param int $default
+ *
+ * @return int
+ */
+ final public function getInfoInt(string $info, int $default = 0): int {
+ if (!key_exists($info, $this->info)) {
+ return $default;
+ }
+
+ return $this->info[$info];
+ }
+
+ /**
+ * Set some information about the original document that will be available
+ * to the front-end when displaying search result. (as bool)
+ * Because this information will not be indexed, this method can also be
+ * used to manage some data while filling the IndexDocument before its
+ * indexing.
+ *
+ * @since 15.0.0
+ *
+ * @param string $info
+ * @param bool $value
+ *
+ * @return IndexDocument
+ */
+ final public function setInfoBool(string $info, bool $value): IndexDocument {
+ $this->info[$info] = $value;
+
+ return $this;
+ }
+
+ /**
+ * Get an information about a document. (bool)
+ *
+ * @since 15.0.0
+ *
+ * @param string $info
+ * @param bool $default
+ *
+ * @return bool
+ */
+ final public function getInfoBool(string $info, bool $default = false): bool {
+ if (!key_exists($info, $this->info)) {
+ return $default;
+ }
+
+ return $this->info[$info];
+ }
+
+ /**
* Get all info.
*
* @since 15.0.0
an> * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library 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 library. If not, see <http://www.gnu.org/licenses/>. * */ require_once __DIR__ . '/../../../lib/base.php'; /** * Class Test_Mount_Config_Dummy_Backend */ class Test_Mount_Config_Dummy_Backend { public static $checkDependencies = true; public static function checkDependencies() { return self::$checkDependencies; } } /** * Class Test_Dynamic_Mount_Config */ class Test_Dynamic_Mount_Config extends \Test\TestCase { private $backup; public function testRegistration() { // second registration shall return false $result = OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Backend', array( 'backend' => 'Test Dummy', 'configuration' => array(), 'has_dependencies' => true)); $this->assertTrue($result); } public function testDependencyGetBackend() { // is the backend listed? Test_Mount_Config_Dummy_Backend::$checkDependencies = true; $backEnds = OC_Mount_Config::getBackends(); $this->assertArrayHasKey('Test_Mount_Config_Dummy_Backend', $backEnds); // backend shall not be listed Test_Mount_Config_Dummy_Backend::$checkDependencies = false; $backEnds = OC_Mount_Config::getBackends(); $this->assertArrayNotHasKey('Test_Mount_Config_Dummy_Backend', $backEnds); } public function testCheckDependencies() { Test_Mount_Config_Dummy_Backend::$checkDependencies = true; $message = OC_Mount_Config::checkDependencies(); $this->assertEmpty($message); // backend shall not be listed Test_Mount_Config_Dummy_Backend::$checkDependencies = array('dummy'); $message = OC_Mount_Config::checkDependencies(); $this->assertEquals('<br /><b>Note:</b> "dummy" is not installed. Mounting of <i>Test Dummy</i> is not possible. Please ask your system administrator to install it.', $message); } protected function setUp() { parent::setUp(); $this->backup = OC_Mount_Config::setUp(); // register dummy backend $result = OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Backend', array( 'backend' => 'Test Dummy', 'configuration' => array(), 'has_dependencies' => true)); $this->assertTrue($result); } protected function tearDown() { OC_Mount_Config::setUp($this->backup); parent::tearDown(); } }