[Groonga-commit] groonga/groonga at d6a7541 [master] grn_ts: apply a scorer and a sorter if there are a certain amount of records

Back to archive index

susumu.yata null+****@clear*****
Mon Nov 30 13:40:26 JST 2015


susumu.yata	2015-11-30 13:40:26 +0900 (Mon, 30 Nov 2015)

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

  Message:
    grn_ts: apply a scorer and a sorter if there are a certain amount of records

  Modified files:
    lib/ts.c

  Modified: lib/ts.c (+26 -10)
===================================================================
--- lib/ts.c    2015-11-30 11:46:07 +0900 (c7e2e72)
+++ lib/ts.c    2015-11-30 13:40:26 +0900 (4dde714)
@@ -731,6 +731,7 @@ grn_ts_select_with_sortby(grn_ctx *ctx, grn_obj *table,
     }
   }
   if (rc == GRN_SUCCESS) {
+    size_t n_pending_recs = 0;
     for ( ; ; ) {
       size_t batch_size;
       grn_ts_record *batch;
@@ -761,10 +762,16 @@ grn_ts_select_with_sortby(grn_ctx *ctx, grn_obj *table,
         break;
       } else if (!batch_size) {
         /* Complete sorting. */
+        if (n_pending_recs) {
+          rc = grn_ts_sorter_progress(ctx, sorter, recs, n_recs, &n_recs);
+          if (rc != GRN_SUCCESS) {
+            break;
+          }
+        }
         rc = grn_ts_sorter_complete(ctx, sorter, recs, n_recs, &n_recs);
         break;
       }
-      /* Apply a filter and a scorer. */
+      /* Apply a filter. */
       if (filter_expr) {
         rc = grn_ts_expr_filter(ctx, filter_expr, batch, batch_size,
                                 batch, &batch_size);
@@ -772,18 +779,27 @@ grn_ts_select_with_sortby(grn_ctx *ctx, grn_obj *table,
           break;
         }
       }
-      if (scorer_expr) {
-        rc = grn_ts_expr_adjust(ctx, scorer_expr, batch, batch_size);
+      n_hits += batch_size;
+      n_recs += batch_size;
+      n_pending_recs += batch_size;
+      /*
+       * Apply a scorer and progress sorting if there are enough pending
+       * records.
+       */
+      if (n_pending_recs >= GRN_TS_BATCH_SIZE) {
+        if (scorer_expr) {
+          rc = grn_ts_expr_adjust(ctx, scorer_expr,
+                                  recs + n_recs - n_pending_recs,
+                                  n_pending_recs);
+          if (rc != GRN_SUCCESS) {
+            break;
+          }
+        }
+        rc = grn_ts_sorter_progress(ctx, sorter, recs, n_recs, &n_recs);
         if (rc != GRN_SUCCESS) {
           break;
         }
-      }
-      n_hits += batch_size;
-      n_recs += batch_size;
-      /* Progress sorting. */
-      rc = grn_ts_sorter_progress(ctx, sorter, recs, n_recs, &n_recs);
-      if (rc != GRN_SUCCESS) {
-        break;
+        n_pending_recs = 0;
       }
     }
   }
-------------- next part --------------
HTML����������������������������...
다운로드 



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