diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-08-24 11:55:19 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-08-24 11:55:19 +0300 |
commit | c701bc2440db875e46fd57f2a6a52f37eb8b04d7 (patch) | |
tree | 2b0784e538b96a67c994f9c234108d979bddebc3 /lib | |
parent | affabdb8f762f54339a5e0b22601d9ce5b865a59 (diff) |
metatags/tags/subtags
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Model/IndexDocument.php | 92 | ||||
-rw-r--r-- | lib/Model/SearchRequest.php | 96 |
2 files changed, 182 insertions, 6 deletions
diff --git a/lib/Model/IndexDocument.php b/lib/Model/IndexDocument.php index 92bb7d5..50e33d7 100644 --- a/lib/Model/IndexDocument.php +++ b/lib/Model/IndexDocument.php @@ -46,12 +46,17 @@ class IndexDocument implements \JsonSerializable { /** @var int */ public $modifiedTime = 0; + /** @var string */ + public $source = ''; + /** @var array */ public $tags = []; - // TODO: do we really need it in the base class ? - /** @var string */ - public $source = ''; + /** @var array */ + public $metaTags = []; + + /** @var array */ + public $subTags = []; /** @var string */ public $title = ''; @@ -219,6 +224,83 @@ class IndexDocument implements \JsonSerializable { return $this; } + + /** + * @param array $tags + * + * @return $this + */ + public function setMetaTags($tags) { + $this->metaTags = $tags; + + return $this; + } + + /** + * @return array + */ + public function getMetaTags() { + return $this->metaTags; + } + + /** + * @param $tags + * + * @return $this + */ + public function addMetaTag($tags) { + $this->metaTags[] = $tags; + + return $this; + } + + + /** + * @param array $tags + * + * @return $this + */ + public function setSubTags($tags) { + $this->subTags = $tags; + + return $this; + } + + /** + * @param bool $formatted + * + * @return array + */ + public function getSubTags($formatted = false) { + if ($formatted === false) { + return $this->subTags; + } + + $subTags = []; + $ak = array_keys($this->subTags); + foreach ($ak as $source) { + $tags = $this->subTags[$source]; + foreach ($tags as $tag) { + $subTags[] = $source . '_' . $tag; + } + } + + return $subTags; + } + + /** + * @param string $k + * @param string $tag + * + * @return $this + */ + public function addSubTag($k, $tag) { + $this->subTags[$k] = $tag; + + return $this; + } + + /** * @return string */ @@ -514,6 +596,8 @@ class IndexDocument implements \JsonSerializable { unset($this->link); unset($this->source); unset($this->tags); + unset($this->metaTags); + unset($this->subTags); unset($this->more); unset($this->excerpts); unset($this->score); @@ -538,6 +622,8 @@ class IndexDocument implements \JsonSerializable { 'hash' => $this->getHash(), 'contentSize' => $this->getContentSize(), 'tags' => $this->getTags(), + 'metatags' => $this->getMetaTags(), + 'subtags' => $this->getSubTags(), 'more' => $this->getMore(), 'excerpts' => $this->getExcerpts(), 'score' => $this->getScore() diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php index 8c70a46..189dc10 100644 --- a/lib/Model/SearchRequest.php +++ b/lib/Model/SearchRequest.php @@ -46,7 +46,13 @@ class SearchRequest implements \JsonSerializable { private $author; /** @var array */ - private $tags; + private $tags = []; + + /** @var array */ + public $metaTags = []; + + /** @var array */ + public $subTags = []; /** @var array */ private $options; @@ -63,8 +69,8 @@ class SearchRequest implements \JsonSerializable { /** @var array */ private $wildcardFields = []; - /** @var array */ - private $wildcardQueries = []; +// /** @var array */ +// private $wildcardQueries = []; /** @var array */ private $wildcardFilters = []; @@ -361,6 +367,86 @@ class SearchRequest implements \JsonSerializable { /** + * @param array $tags + * + * @return $this + */ + public function setMetaTags($tags) { + $this->metaTags = $tags; + + return $this; + } + + /** + * @return array + */ + public function getMetaTags() { + return $this->metaTags; + } + + /** + * @param string $tags + * + * @return $this + */ + public function addMetaTag($tags) { + $this->metaTags[] = $tags; + + return $this; + } + + + /** + * @param array $tags + * + * @return $this + */ + public function setSubTags($tags) { + $this->subTags = $tags; + + return $this; + } + + /** + * @param bool $formatted + * + * @return array + */ + public function getSubTags($formatted = false) { + if ($formatted === false) { + return $this->subTags; + } + + $subTags = []; + $ak = array_keys($this->subTags); + foreach ($ak as $source) { + $tags = $this->subTags[$source]; + foreach ($tags as $tag) { + $subTags[] = $source . '_' . $tag; + } + } + + return $subTags; + } + + /** + * @param string $source + * @param string $tag + * + * @return $this + */ + public function addSubTag($source, $tag) { + if (!array_key_exists($source, $this->subTags)) { + $this->subTags[$source] = []; + } + + $this->subTags[$source][] = $tag; + + return $this; + } + + + /** * @param string $field * * @return $this @@ -481,6 +567,8 @@ class SearchRequest implements \JsonSerializable { 'size' => $this->getSize(), 'parts' => $this->getParts(), 'options' => $this->getOptions(), + 'metatags' => $this->getMetaTags(), + 'subtags' => $this->getSubTags(), 'tags' => $this->getTags() ]; } @@ -509,6 +597,8 @@ class SearchRequest implements \JsonSerializable { $request->setParts(MiscService::get('parts', $arr, [])); $request->setSize(MiscService::get('size', $arr, 10)); $request->setOptions(MiscService::get('options', $arr, [])); + $request->setMetaTags(MiscService::get('metatags', $arr, [])); + $request->setSubTags(MiscService::get('subtags', $arr, [])); $request->setTags(MiscService::get('tags', $arr, [])); return $request; |