Prepares database for job terms.
[platal.git] / include / profil.func.inc.php
index 61b0356..e8ecb59 100644 (file)
@@ -352,5 +352,28 @@ function format_display_number($tel, &$error, $format = array('format'=>'','phon
     return $ret;
 }
 
+/**
+ * Extract search token from term
+ * @param $term a utf-8 string that can contain any char
+ * @param an array of elementary tokens
+ */
+function tokenize_job_term($term)
+{
+    $term = mb_strtoupper(replace_accent($term));
+    $term = str_replace(array('/', ',', '(', ')', '"', '&', '»', '«'), ' ', $term);
+    $tokens = explode(' ', $term);
+    static $not_tokens = array('ET','AND','DE','DES','DU','D\'','OU','L\'','LA','LE','LES','PAR','AU','AUX','EN','SUR','UN','UNE','IN');
+    foreach ($tokens as &$t) {
+        if (substr($t, 1, 1) == '\'' && in_array(substr($t, 0, 2), $not_tokens)) {
+            $t = substr($t, 2);
+        }
+        if (strlen($t) == 1 || in_array($t, $not_tokens)) {
+            $t = false;
+            continue;
+        }
+    }
+    return array_filter($tokens);
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>