I have my site full of lirycs written in Polish. (http://staremelodie.pl/) So I created a FTS4 table to make all the texts searchable. Everything works fine, but... The polish letter Ł/ł! It's ok to look for "zeby" and find "zęby", "żeby" but searching for a word "laska" doesn't return "laska" or/and "łaska". Only: laska = laska, łaska = łaska. In my search goes through title, alt_tile, text. The only workaround I've made is to query db with oryginal string and than again with replaced l to ł or ł to l:
$q = $_REQUEST["q"];// the query
//
$ql = str_replace("l","ł",strtolower($q));
$snipety = "snippet($tekst) AS liryc,snippet($title) AS title,snippet($alt_title) AS alt_title, rankit(offsets($table)) AS rank";
$snipety .= ", offsets($table) AS offs ";
//rankit() is defined as a function counting results - not working since there are more results than one, bit senseless...
$sql = "SELECT id,tytul,gatunek, $snipety FROM $table WHERE $table MATCH 'tytul:$q*'";
$sql .= " UNION ";
$sql .= "SELECT id,tytul,gatunek, $snipety FROM $table WHERE $table MATCH 'tytul:$ql*'";
$sql .= " UNION ";
$sql .= "SELECT id,tytul,gatunek, $snipety FROM $table WHERE $table MATCH 'alt_tytul:$q*'";
$sql .= " UNION ";
$sql .= "SELECT id,tytul,gatunek, $snipety FROM $table WHERE $table MATCH 'alt_tytul:$ql*'";
$sql .= " UNION ";
$sql .= "SELECT id,tytul,gatunek, $snipety FROM $table WHERE $table MATCH 'tekst:$q*'";
$sql .= " UNION ";
$sql .= "SELECT id,tytul,gatunek, $snipety FROM $table WHERE $table MATCH 'tekst:$ql*'";
$sql .= " ORDER BY rank DESC LIMIT 16";
All the UNION syntax is the only way I found to make result not disapear, when there are more than two words in query with one containing ł or l. The problem is, that there can be more results per one song (success in title, byt not alt_title and success in alt_title byt not in title) just because of (łon) one letter ł. Any polish/sqlite/php experiences?
Aucun commentaire:
Enregistrer un commentaire