Max F 5 år sedan
förälder
incheckning
ce54b6478a
2 ändrade filer med 23 tillägg och 3 borttagningar
  1. 3 3
      src/Database/Sql/SqlTools.php
  2. 20 0
      src/helpers/helpers_default.php

+ 3 - 3
src/Database/Sql/SqlTools.php

@@ -233,7 +233,7 @@ class SqlTools
             $words = explode(" ", $q);
 
             foreach ($words as $word_idx => $word) {
-                $word_idx_score = 100 * max(1, 10 - $word_idx); // au dela de 10 mots, on compte comme le 10e mot
+                $word_idx_score = max(1, 10 - $word_idx) * max(1, 10 - $word_idx); // au dela de 10 mots, on compte comme le 10e mot
 
                 $w = $db->escape($word);
                 $w2 = $db->escape("%" . $word . "%");
@@ -243,8 +243,8 @@ class SqlTools
                 foreach ($search_fields as $term_idx => $field) {
                     $conditions_or[] = $field . " like " . $w2;
 
-                    $term_idx_score = 10 * max(1, 10 - $term_idx); // au dela de 10 fields, on compte comme le 10e field
-                    $select_sums[] = "( if( locate(" . $w . ", ifnull(" . $field . ",'') ) > 0, 1, 0 ) * " . $word_idx_score . " * " . $term_idx_score . " * greatest( 100 - locate(" . $w . ", ifnull(" . $field . ", '')), 1) )";
+                    $term_idx_score = max(1, 10 - $term_idx) * max(1, 10 - $term_idx); // au dela de 10 fields, on compte comme le 10e field
+                    $select_sums[] = "( if( locate(" . $w . ", ifnull(" . $field . ",'') ) > 0, 1, 0 ) * (1 / length(" . $field . ")) * " . $word_idx_score . " * " . $term_idx_score . " * greatest( 100 - locate(" . $w . ", ifnull(" . $field . ", '')), 1) )";
                 }
 
                 $word_condition = "(" . implode(" or ", $conditions_or) . ")";

+ 20 - 0
src/helpers/helpers_default.php

@@ -243,3 +243,23 @@ if (! function_exists('get_url_path')) {
 	}
 }
 
+
+if (! function_exists('rrmdir')) {
+	function rrmdir($src) {
+		// https://www.php.net/manual/fr/function.rmdir.php
+	    $dir = opendir($src);
+	    while(false !== ( $file = readdir($dir)) ) {
+	        if (( $file != '.' ) && ( $file != '..' )) {
+	            $full = $src . '/' . $file;
+	            if ( is_dir($full) ) {
+	                rrmdir($full);
+	            }
+	            else {
+	                unlink($full);
+	            }
+	        }
+	    }
+	    closedir($dir);
+	    rmdir($src);
+	}
+}