[Groonga-commit] groonga/groonga at a6b1530 [master] ii: normalize estimated size for query

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Nov 13 11:17:00 JST 2015


Kouhei Sutou	2015-11-13 11:17:00 +0900 (Fri, 13 Nov 2015)

  New Revision: a6b1530ff55be7fe6751350b335ee01a4d66303a
  https://github.com/groonga/groonga/commit/a6b1530ff55be7fe6751350b335ee01a4d66303a

  Message:
    ii: normalize estimated size for query
    
    If multiple tokens exist in a query, estimated size will be smaller than
    minimum estimated size of a token.

  Modified files:
    lib/ii.c

  Modified: lib/ii.c (+19 -0)
===================================================================
--- lib/ii.c    2015-11-13 11:04:58 +0900 (a9ed6e2)
+++ lib/ii.c    2015-11-13 11:17:00 +0900 (b581c09)
@@ -73,6 +73,7 @@
 
 static grn_bool grn_ii_cursor_set_min_enable = GRN_FALSE;
 static double grn_ii_select_too_many_index_match_ratio = -1;
+static double grn_ii_estimate_size_for_query_reduce_ratio = 0.9;
 
 void
 grn_ii_init_from_env(void)
@@ -99,6 +100,17 @@ grn_ii_init_from_env(void)
         atof(grn_ii_select_too_many_index_match_ratio_env);
     }
   }
+
+  {
+    char grn_ii_estimate_size_for_query_reduce_ratio_env[GRN_ENV_BUFFER_SIZE];
+    grn_getenv("GRN_II_ESTIMATE_SIZE_FOR_QUERY_REDUCE_RATIO",
+               grn_ii_estimate_size_for_query_reduce_ratio_env,
+               GRN_ENV_BUFFER_SIZE);
+    if (grn_ii_estimate_size_for_query_reduce_ratio_env[0]) {
+      grn_ii_estimate_size_for_query_reduce_ratio =
+        atof(grn_ii_estimate_size_for_query_reduce_ratio_env);
+    }
+  }
 }
 
 /* segment */
@@ -6680,6 +6692,7 @@ grn_ii_estimate_size_for_query(grn_ctx *ctx, grn_ii *ii,
   grn_bool only_skip_token = GRN_FALSE;
   grn_operator mode = GRN_OP_EXACT;
   double estimated_size = 0;
+  double normalized_ratio = 1.0;
 
   if (query_len == 0) {
     return 0;
@@ -6728,9 +6741,15 @@ grn_ii_estimate_size_for_query(grn_ctx *ctx, grn_ii *ii,
       if (term_estimated_size < estimated_size) {
         estimated_size = term_estimated_size;
       }
+      normalized_ratio *= grn_ii_estimate_size_for_query_reduce_ratio;
     }
   }
 
+  estimated_size *= normalized_ratio;
+  if (estimated_size > 0.0 && estimated_size < 1.0) {
+    estimated_size = 1.0;
+  }
+
 exit :
   for (i = 0; i < n_tis; i++) {
     token_info *ti = tis[i];
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index