<?php function search_lecture($dbconn,$keywords,$since_utc,$upto_utc,$minutes,$offset=0,$pagesize,$addon_condmap_eq=array()) { $chars=utf8_str_to_words($keywords); $words=chars_to_words_for_search($chars); if ($words) $unique_words=array_keys(array_combine($words,$words)); else $unique_words=array(); $CPID=compere_id_requested(); if ($CPID) $addon_condmap_eq['`c`.`mb_id_owner`']=$CPID; return db_compute_search_result($dbconn,$unique_words,$since_utc,$upto_utc,$minutes,$offset,$pagesize,$addon_condmap_eq); } function search_course($dbconn,$keywords,$since_utc,$upto_utc,$minutes,$offset=0,$pagesize,$addon_condmap_eq=array()) { $chars=utf8_str_to_words($keywords); $words=chars_to_words_for_search($chars); if ($words) $unique_words=array_keys(array_combine($words,$words)); else $unique_words=array(); $CPID=compere_id_requested(); if ($CPID) $addon_condmap_eq['`c`.`mb_id_owner`']=$CPID; return db_compute_search_result( $dbconn, $unique_words, $since_utc, $upto_utc, $minutes, $offset, $pagesize, $addon_condmap_eq, array('TAKE-CS','OWNER-INIT-ALSO','SUPPRESS-NA-CS','SORT-BY-LR') ); } function utf8_str_to_words($str) { $array=array(); if (strlen($str)==0) return $array; $idx=0; do { $piece=mb_strcut($str,$idx,4,'UTF-8'); $char=mb_substr($piece,0,1,'UTF-8'); $idx+=$clen=strlen($char); if ($clen) array_push($array,$char); } while ($clen); return $array; } function chars_to_words_for_search($chars,$wordlen_chars_nonascii=2,$wordlen_chars_min=1,$wordlen_chars_max=20) { $words=array(); $ccount=sizeof($chars); $last_ci=-1; for ($ci=0;$ci<$ccount && $last_ci<$ci;) { $last_ci=$ci; $word=''; $wordlen=0; $lastclen=0; while ($ci<$ccount && $wordlen<$wordlen_chars_max) { $c=$chars[$ci]; $clen=strlen($c); if (ctype_space($c) || $c==' ') { $ci++; break; } else if ($clen>1 && $lastclen==1) break; else if ($clen==1 && $lastclen>1) break; $word.=$c; $wordlen++; if ($clen>1 && $lastclen>1 && $wordlen>=$wordlen_chars_nonascii) break; $ci++; $lastclen=$clen; } if ($lastclen>1 && $wordlen>=$wordlen_chars_nonascii || $lastclen==1 && $wordlen>=$wordlen_chars_min) array_push($words,$word); } return $words; } function set_course_keywords($dbconn,$cs_id,$course_text,$num_word_limit=999) { $chars=utf8_str_to_words($course_text); $words=chars_to_words_for_search($chars); $wordcounts=array(); foreach ($words as $w) $wordcounts[$w]++; asort($wordcounts); db_set_course_keywords($dbconn,$cs_id,$wordcounts,$num_word_limit); } ?>