aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorFlorian Eula <eula.florian@gmail.com>2014-12-22 16:43:37 +0100
committerFlorian Eula <eula.florian@gmail.com>2014-12-22 16:43:37 +0100
commit2e45fdd8ff84678215ac838133f89c57580b59af (patch)
treeaf9b2cd7519794d43d77473b31a71828c6546b37 /index.php
parenta58240ce8d0e1bdb814e24ae4dc9584dda2dd6f7 (diff)
downloadShaarli-2e45fdd8ff84678215ac838133f89c57580b59af.tar.gz
Shaarli-2e45fdd8ff84678215ac838133f89c57580b59af.tar.zst
Shaarli-2e45fdd8ff84678215ac838133f89c57580b59af.zip
Made tag/title search unicode aware, fixes #75
Diffstat (limited to 'index.php')
-rw-r--r--index.php18
1 files changed, 11 insertions, 7 deletions
diff --git a/index.php b/index.php
index 35e83eb5..e2c68869 100644
--- a/index.php
+++ b/index.php
@@ -794,14 +794,16 @@ class linkdb implements Iterator, Countable, ArrayAccess
794 { 794 {
795 // FIXME: explode(' ',$searchterms) and perform a AND search. 795 // FIXME: explode(' ',$searchterms) and perform a AND search.
796 // FIXME: accept double-quotes to search for a string "as is"? 796 // FIXME: accept double-quotes to search for a string "as is"?
797 // Using mb_convert_case($val, MB_CASE_LOWER, 'UTF-8') allows us to perform searches on
798 // Unicode text. See https://github.com/shaarli/Shaarli/issues/75 for examples.
797 $filtered=array(); 799 $filtered=array();
798 $s = strtolower($searchterms); 800 $s = mb_convert_case($searchterms, MB_CASE_LOWER, 'UTF-8');
799 foreach($this->links as $l) 801 foreach($this->links as $l)
800 { 802 {
801 $found= (strpos(strtolower($l['title']),$s)!==false) 803 $found= (strpos(mb_convert_case($l['title'], MB_CASE_LOWER, 'UTF-8'),$s) !== false)
802 || (strpos(strtolower($l['description']),$s)!==false) 804 || (strpos(mb_convert_case($l['description'], MB_CASE_LOWER, 'UTF-8'),$s) !== false)
803 || (strpos(strtolower($l['url']),$s)!==false) 805 || (strpos(mb_convert_case($l['url'], MB_CASE_LOWER, 'UTF-8'),$s) !== false)
804 || (strpos(strtolower($l['tags']),$s)!==false); 806 || (strpos(mb_convert_case($l['tags'], MB_CASE_LOWER, 'UTF-8'),$s) !== false);
805 if ($found) $filtered[$l['linkdate']] = $l; 807 if ($found) $filtered[$l['linkdate']] = $l;
806 } 808 }
807 krsort($filtered); 809 krsort($filtered);
@@ -813,12 +815,14 @@ class linkdb implements Iterator, Countable, ArrayAccess
813 // e.g. print_r($mydb->filterTags('linux programming')); 815 // e.g. print_r($mydb->filterTags('linux programming'));
814 public function filterTags($tags,$casesensitive=false) 816 public function filterTags($tags,$casesensitive=false)
815 { 817 {
816 $t = str_replace(',',' ',($casesensitive?$tags:strtolower($tags))); 818 // Same as above, we use UTF-8 conversion to handle various graphemes (i.e. cyrillic, or greek)
819 // TODO: is $casesensitive ever true ?
820 $t = str_replace(',',' ',($casesensitive?$tags:mb_convert_case($tags, MB_CASE_LOWER, 'UTF-8')));
817 $searchtags=explode(' ',$t); 821 $searchtags=explode(' ',$t);
818 $filtered=array(); 822 $filtered=array();
819 foreach($this->links as $l) 823 foreach($this->links as $l)
820 { 824 {
821 $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags']))); 825 $linktags = explode(' ',($casesensitive?$l['tags']:mb_convert_case($l['tags'], MB_CASE_LOWER, 'UTF-8')));
822 if (count(array_intersect($linktags,$searchtags)) == count($searchtags)) 826 if (count(array_intersect($linktags,$searchtags)) == count($searchtags))
823 $filtered[$l['linkdate']] = $l; 827 $filtered[$l['linkdate']] = $l;
824 } 828 }