[Groonga-commit] groonga/groonga [master] suggest: move key_prefix to learner

Back to archive index

null+****@clear***** null+****@clear*****
2012年 3月 12日 (月) 14:19:14 JST


Kouhei Sutou	2012-03-12 14:19:14 +0900 (Mon, 12 Mar 2012)

  New Revision: 07b32da13f6793724a2d8ca544670298407ff185

  Log:
    suggest: move key_prefix to learner

  Modified files:
    plugins/suggest/suggest.c

  Modified: plugins/suggest/suggest.c (+8 -7)
===================================================================
--- plugins/suggest/suggest.c    2012-03-12 13:27:06 +0900 (9e870d8)
+++ plugins/suggest/suggest.c    2012-03-12 14:19:14 +0900 (7967914)
@@ -73,6 +73,7 @@ typedef struct {
   grn_obj v1;
   grn_obj pre_events;
 
+  uint64_t key_prefix;
   grn_obj pre_item;
 } grn_suggest_learner;
 
@@ -675,6 +676,8 @@ learner_init_submit_learn(grn_ctx *ctx, grn_suggest_learner *learner)
 {
   grn_id items_id;
 
+  learner->key_prefix = ((uint64_t)learner->post_item_id) << 32;
+
   items_id = grn_obj_get_range(ctx, learner->events_item);
   GRN_RECORD_INIT(&(learner->pre_item), 0, items_id);
 
@@ -713,7 +716,6 @@ static void
 learn_for_complete_and_correcnt(grn_ctx *ctx, grn_suggest_learner *learner,
                                 grn_obj *post_item,
                                 grn_obj *pre_events, grn_obj *pre_item,
-                                uint64_t key_prefix,
                                 int64_t post_time_value)
 {
   grn_obj pre_type, pre_time;
@@ -741,7 +743,7 @@ learn_for_complete_and_correcnt(grn_ctx *ctx, grn_suggest_learner *learner,
         (int)(learn_distance_in_msec / GRN_TIME_USEC_PER_SEC);
       break;
     }
-    key = key_prefix + GRN_RECORD_VALUE(pre_item);
+    key = learner->key_prefix + GRN_RECORD_VALUE(pre_item);
     pair_id = grn_table_add(ctx, learner->pairs, &key, sizeof(uint64_t),
                             &added);
     if (added) {
@@ -764,7 +766,7 @@ learn_for_complete_and_correcnt(grn_ctx *ctx, grn_suggest_learner *learner,
 static void
 learn_for_suggest(grn_ctx *ctx, grn_suggest_learner *learner,
                   grn_id post_item_id,
-                  uint64_t key_prefix, grn_obj *pre_item,
+                  grn_obj *pre_item,
                   grn_obj *post_item)
 {
   char keybuf[GRN_TABLE_MAX_KEY_SIZE];
@@ -777,7 +779,7 @@ learn_for_suggest(grn_ctx *ctx, grn_suggest_learner *learner,
       uint64_t key;
       int added;
       grn_id pair_id;
-      key = key_prefix + tid;
+      key = learner->key_prefix + tid;
       pair_id = grn_table_add(ctx, learner->pairs, &key, sizeof(uint64_t),
                               &added);
       if (added) {
@@ -814,7 +816,6 @@ learner_learn(grn_ctx *ctx, grn_suggest_learner *learner)
     learner_increment(ctx, learner, learner->items_freq, post_item_id);
     learner_set_last_post_time(ctx, learner);
     if (post_type_id) {
-      uint64_t key_prefix = ((uint64_t)post_item_id) << 32;
       grn_obj *pre_item;
 
       learner_init_submit_learn(ctx, learner);
@@ -824,9 +825,9 @@ learner_learn(grn_ctx *ctx, grn_suggest_learner *learner)
       learn_for_complete_and_correcnt(ctx, learner,
                                       post_item, &(learner->pre_events),
                                       pre_item,
-                                      key_prefix, post_time_value);
+                                      post_time_value);
       learn_for_suggest(ctx, learner,
-                        post_item_id, key_prefix, pre_item, post_item);
+                        post_item_id, pre_item, post_item);
 
       learner_fin_submit_learn(ctx, learner);
     }




Groonga-commit メーリングリストの案内
Back to archive index