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
diff options
context:
space:
mode:
-rw-r--r--css/fulltextsearch.css3
-rw-r--r--js/fulltextsearch.v1.navigation.js10
-rw-r--r--js/fulltextsearch.v1.result.js1
-rw-r--r--js/fulltextsearch.v1.settings.js1
-rw-r--r--lib/Model/IndexDocument.php37
-rw-r--r--lib/Model/SearchRequest.php50
6 files changed, 98 insertions, 4 deletions
diff --git a/css/fulltextsearch.css b/css/fulltextsearch.css
index f4b6b75..5f7f81f 100644
--- a/css/fulltextsearch.css
+++ b/css/fulltextsearch.css
@@ -136,6 +136,9 @@ input.options_small {
/*font-weight: bold;*/
}
+#source {
+ color: #a5a5a5;
+}
.result_entry_default #info {
font-weight: bold;
}
diff --git a/js/fulltextsearch.v1.navigation.js b/js/fulltextsearch.v1.navigation.js
index 8c7ebe1..600c43c 100644
--- a/js/fulltextsearch.v1.navigation.js
+++ b/js/fulltextsearch.v1.navigation.js
@@ -107,6 +107,7 @@ var nav = {
var entry = newResult[i];
if (result.getResultIndex(entry.id, oldResult) > -1) {
precItem = nav.getDivResult(entry.id, divProviderResult);
+ nav.fillDivResult(precItem, entry);
continue;
}
@@ -210,11 +211,16 @@ var nav = {
fillDivResult: function (divResult, entry) {
divResult.find('#title').text(entry.title);
- // divResult.find('#score').text(entry.score);
+
+ divResult.find('#source').html(' ');
if (entry.info.source !== '') {
divResult.find('#source').text(entry.info.source);
}
+ if (settings.options.show_hash === '1') {
+ divResult.find('#source').text(entry.hash);
+ }
+
nav.fillDivResultExcepts(divResult, entry);
if (entry.link !== '') {
@@ -318,7 +324,6 @@ var nav = {
generateDivResult: function (entry, divResultContent) {
var divResult = $('<div>', {class: 'result_entry'});
- console.log('!!! ' + JSON.stringify(entry.info));
divResult.hide();
divResult.attr('data-id', entry.id);
divResult.attr('data-link', entry.link);
@@ -328,7 +333,6 @@ var nav = {
divResult.append(divResultContent);
nav.fillDivResult(divResult, entry);
- nav.onEntryGenerated(divResult);
return divResult;
},
diff --git a/js/fulltextsearch.v1.result.js b/js/fulltextsearch.v1.result.js
index a054f7e..f107f56 100644
--- a/js/fulltextsearch.v1.result.js
+++ b/js/fulltextsearch.v1.result.js
@@ -45,6 +45,7 @@ var result = {
return;
}
+ settings.options = res.request.options;
for (var i = 0; i < searchResult.length; i++) {
result.displayProviderResult(res.request, searchResult[i]);
}
diff --git a/js/fulltextsearch.v1.settings.js b/js/fulltextsearch.v1.settings.js
index 835217c..5915d86 100644
--- a/js/fulltextsearch.v1.settings.js
+++ b/js/fulltextsearch.v1.settings.js
@@ -40,6 +40,7 @@ var settings = {
entryTemplate: null,
entryTemplateDefault: null,
divNoResult: null,
+ options: [],
/**
* generate the default template to dsplay search result entries
diff --git a/lib/Model/IndexDocument.php b/lib/Model/IndexDocument.php
index 0d2bb4c..c3d4bb9 100644
--- a/lib/Model/IndexDocument.php
+++ b/lib/Model/IndexDocument.php
@@ -59,6 +59,9 @@ class IndexDocument implements \JsonSerializable {
/** @var string */
public $content = null;
+ /** @var string */
+ public $hash = '';
+
/** @var array */
public $parts = [];
@@ -276,6 +279,38 @@ class IndexDocument implements \JsonSerializable {
/**
+ * @return $this
+ */
+ public function initHash() {
+ if ($this->getContent() === '' || is_null($this->getContent())) {
+ return $this;
+ }
+
+ $this->hash = hash("md5", $this->getContent());
+
+ return $this;
+ }
+
+ /**
+ * @param $hash
+ *
+ * @return $this
+ */
+ public function setHash($hash) {
+ $this->hash = $hash;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getHash() {
+ return $this->hash;
+ }
+
+
+ /**
* @param string $part
* @param string $content
*
@@ -468,6 +503,7 @@ class IndexDocument implements \JsonSerializable {
unset($this->modifiedTime);
unset($this->title);
unset($this->content);
+ unset($this->hash);
unset($this->link);
unset($this->source);
unset($this->tags);
@@ -491,6 +527,7 @@ class IndexDocument implements \JsonSerializable {
'link' => $this->getLink(),
'source' => $this->getSource(),
'info' => $this->getInfoAll(),
+ 'hash' => $this->getHash(),
'tags' => $this->getTags(),
'more' => $this->getMore(),
'excerpts' => $this->getExcerpts(),
diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php
index 35d1bbb..2a9013a 100644
--- a/lib/Model/SearchRequest.php
+++ b/lib/Model/SearchRequest.php
@@ -122,8 +122,44 @@ class SearchRequest implements \JsonSerializable {
$this->search = $search;
}
+
public function cleanSearch() {
- $this->search = trim(str_replace(' ', ' ', $this->search));
+ $search = trim(str_replace(' ', ' ', $this->getSearch()));
+
+ preg_match_all('/[^?]"(?:\\\\.|[^\\\\"])*"|\S+/', " $search ", $words);
+ $searchItems = [];
+ foreach ($words[0] as $word) {
+ if ($this->searchQueryOptions($word)) {
+ continue;
+ }
+
+ $searchItems[] = $word;
+ }
+
+ $this->setSearch(implode(" ", $searchItems));
+ }
+
+
+ /**
+ * @param $word
+ *
+ * @return bool
+ */
+ private function searchQueryOptions($word) {
+ if (($pos = strpos($word, ':')) === false) {
+ return false;
+ }
+
+ list($kw, $value) = explode(':', $word, 2);
+ $options = ['is', 'show'];
+
+ if (in_array($kw, $options)) {
+ $this->addOption($kw . '_' . $value, '1');
+
+ return true;
+ }
+
+ return false;
}
@@ -176,6 +212,18 @@ class SearchRequest implements \JsonSerializable {
}
/**
+ * @param $key
+ * @param $value
+ *
+ * @return $this
+ */
+ public function addOption($key, $value) {
+ $this->options[$key] = $value;
+
+ return $this;
+ }
+
+ /**
* @param string $option
*
* @return mixed|string