aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-02-28 14:26:46 +0100
committerArthur <arthur@hoa.ro>2016-02-28 14:26:46 +0100
commitc6744a9e89b62ba94563c43ab33f964ec0b11a17 (patch)
tree30e6274a05636d06b10a5749d4786d5d95ccedf0 /application
parent10269bc8c9dfe87eb213c09a44308ce64ae0c12d (diff)
parentc51fae92dc7d3080def81a2797e0d683b3e6d82a (diff)
downloadShaarli-c6744a9e89b62ba94563c43ab33f964ec0b11a17.tar.gz
Shaarli-c6744a9e89b62ba94563c43ab33f964ec0b11a17.tar.zst
Shaarli-c6744a9e89b62ba94563c43ab33f964ec0b11a17.zip
Merge pull request #496 from ArthurHoaro/cross-search
Allow crossed search between terms and tags
Diffstat (limited to 'application')
-rw-r--r--application/LinkDB.php3
-rw-r--r--application/LinkFilter.php27
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)) {