diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-02-23 19:21:14 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-02-28 14:17:40 +0100 |
commit | c51fae92dc7d3080def81a2797e0d683b3e6d82a (patch) | |
tree | 394f9419589c1983d9be9834b89c8be2e8ef237c /application | |
parent | 6c3d6a31f413862941fe514e7167c04fe71ba1a7 (diff) | |
download | Shaarli-c51fae92dc7d3080def81a2797e0d683b3e6d82a.tar.gz Shaarli-c51fae92dc7d3080def81a2797e0d683b3e6d82a.tar.zst Shaarli-c51fae92dc7d3080def81a2797e0d683b3e6d82a.zip |
Allow crossed search between terms and tags
* Partial fix of #449
* Current use case: search term + click on tag.
* LinkFilter now returns all links if no filter is given.
* Unit tests.
Diffstat (limited to 'application')
-rw-r--r-- | application/LinkDB.php | 3 | ||||
-rw-r--r-- | application/LinkFilter.php | 27 |
2 files changed, 24 insertions, 6 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index 9488ac45..1b505620 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -353,8 +353,7 @@ You use the community supported version of the original Shaarli project, by Seba | |||
353 | public function filter($type = '', $request = '', $casesensitive = false, $privateonly = false) | 353 | public function filter($type = '', $request = '', $casesensitive = false, $privateonly = false) |
354 | { | 354 | { |
355 | $linkFilter = new LinkFilter($this->_links); | 355 | $linkFilter = new LinkFilter($this->_links); |
356 | $requestFilter = is_array($request) ? implode(' ', $request) : $request; | 356 | return $linkFilter->filter($type, $request, $casesensitive, $privateonly); |
357 | return $linkFilter->filter($type, trim($requestFilter), $casesensitive, $privateonly); | ||
358 | } | 357 | } |
359 | 358 | ||
360 | /** | 359 | /** |
diff --git a/application/LinkFilter.php b/application/LinkFilter.php index 17594e8f..3fd803cb 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php | |||
@@ -55,16 +55,25 @@ class LinkFilter | |||
55 | switch($type) { | 55 | switch($type) { |
56 | case self::$FILTER_HASH: | 56 | case self::$FILTER_HASH: |
57 | return $this->filterSmallHash($request); | 57 | return $this->filterSmallHash($request); |
58 | break; | 58 | case self::$FILTER_TAG | self::$FILTER_TEXT: |
59 | if (!empty($request)) { | ||
60 | $filtered = $this->links; | ||
61 | if (isset($request[0])) { | ||
62 | $filtered = $this->filterTags($request[0], $casesensitive, $privateonly); | ||
63 | } | ||
64 | if (isset($request[1])) { | ||
65 | $lf = new LinkFilter($filtered); | ||
66 | $filtered = $lf->filterFulltext($request[1], $privateonly); | ||
67 | } | ||
68 | return $filtered; | ||
69 | } | ||
70 | return $this->noFilter($privateonly); | ||
59 | case self::$FILTER_TEXT: | 71 | case self::$FILTER_TEXT: |
60 | return $this->filterFulltext($request, $privateonly); | 72 | return $this->filterFulltext($request, $privateonly); |
61 | break; | ||
62 | case self::$FILTER_TAG: | 73 | case self::$FILTER_TAG: |
63 | return $this->filterTags($request, $casesensitive, $privateonly); | 74 | return $this->filterTags($request, $casesensitive, $privateonly); |
64 | break; | ||
65 | case self::$FILTER_DAY: | 75 | case self::$FILTER_DAY: |
66 | return $this->filterDay($request); | 76 | return $this->filterDay($request); |
67 | break; | ||
68 | default: | 77 | default: |
69 | return $this->noFilter($privateonly); | 78 | return $this->noFilter($privateonly); |
70 | } | 79 | } |
@@ -138,6 +147,10 @@ class LinkFilter | |||
138 | */ | 147 | */ |
139 | private function filterFulltext($searchterms, $privateonly = false) | 148 | private function filterFulltext($searchterms, $privateonly = false) |
140 | { | 149 | { |
150 | if (empty($searchterms)) { | ||
151 | return $this->links; | ||
152 | } | ||
153 | |||
141 | $filtered = array(); | 154 | $filtered = array(); |
142 | $search = mb_convert_case(html_entity_decode($searchterms), MB_CASE_LOWER, 'UTF-8'); | 155 | $search = mb_convert_case(html_entity_decode($searchterms), MB_CASE_LOWER, 'UTF-8'); |
143 | $exactRegex = '/"([^"]+)"/'; | 156 | $exactRegex = '/"([^"]+)"/'; |
@@ -219,6 +232,12 @@ class LinkFilter | |||
219 | */ | 232 | */ |
220 | public function filterTags($tags, $casesensitive = false, $privateonly = false) | 233 | public function filterTags($tags, $casesensitive = false, $privateonly = false) |
221 | { | 234 | { |
235 | // Implode if array for clean up. | ||
236 | $tags = is_array($tags) ? trim(implode(' ', $tags)) : $tags; | ||
237 | if (empty($tags)) { | ||
238 | return $this->links; | ||
239 | } | ||
240 | |||
222 | $searchtags = self::tagsStrToArray($tags, $casesensitive); | 241 | $searchtags = self::tagsStrToArray($tags, $casesensitive); |
223 | $filtered = array(); | 242 | $filtered = array(); |
224 | if (empty($searchtags)) { | 243 | if (empty($searchtags)) { |