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/Model
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-05-30 20:08:44 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-05-30 20:08:44 +0300
commit230d8c96791b12cb4430adcabe28b16e665c006e (patch)
tree3278503e951289ce4da107dc0e2793579193ffbe /lib/Model
parent09cec3e1d64aaef97bea6d30d37f95279065af1b (diff)
get options from search query string
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/IndexDocument.php37
-rw-r--r--lib/Model/SearchRequest.php50
2 files changed, 86 insertions, 1 deletions
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