[Groonga-commit] groonga/groonga at 0248342 [master] grn_ts: implement grn_ts_op_logical_or_filter()

Back to archive index

susumu.yata null+****@clear*****
Wed Sep 9 14:53:13 JST 2015


susumu.yata	2015-09-09 14:53:13 +0900 (Wed, 09 Sep 2015)

  New Revision: 0248342a5151013c22263aa504968b04f49c33a8
  https://github.com/groonga/groonga/commit/0248342a5151013c22263aa504968b04f49c33a8

  Message:
    grn_ts: implement grn_ts_op_logical_or_filter()
    
    GitHub: #385

  Modified files:
    lib/ts.c

  Modified: lib/ts.c (+42 -2)
===================================================================
--- lib/ts.c    2015-09-09 14:06:23 +0900 (a3d8505)
+++ lib/ts.c    2015-09-09 14:53:13 +0900 (183188a)
@@ -2128,8 +2128,48 @@ static grn_rc
 grn_ts_op_logical_or_filter(grn_ctx *ctx, grn_ts_expr_op_node *node,
                             grn_ts_record *in, size_t n_in,
                             grn_ts_record *out, size_t *n_out) {
-  // TODO
-  return GRN_FUNCTION_NOT_IMPLEMENTED;
+  size_t i, j, count;
+  grn_rc rc;
+  grn_ts_buf *arg1_buf = &node->bufs[0], *arg2_buf = &node->bufs[1];
+  grn_ts_bool *arg1_ptr, *arg2_ptr;
+  grn_ts_buf *tmp_in_buf = &node->bufs[2];
+  grn_ts_record *tmp_in;
+
+  /* Evaluate the 1st argument. */
+  rc = grn_ts_expr_node_evaluate_to_buf(ctx, node->args[0], in, n_in,
+                                        arg1_buf);
+  if (rc != GRN_SUCCESS) {
+    return rc;
+  }
+  arg1_ptr = (grn_ts_bool *)arg1_buf->ptr;
+
+  /* Create a list of false records. */
+  rc = grn_ts_buf_reserve(ctx, tmp_in_buf, sizeof(grn_ts_record) * n_in);
+  if (rc != GRN_SUCCESS) {
+    return rc;
+  }
+  tmp_in = (grn_ts_record *)tmp_in_buf->ptr;
+  count = 0;
+  for (i = 0; i < n_in; i++) {
+    if (!arg1_ptr[i]) {
+      tmp_in[count++] = in[i];
+    }
+  }
+
+  /* Evaluate the 2nd argument. */
+  rc = grn_ts_expr_node_evaluate_to_buf(ctx, node->args[1],
+                                        tmp_in, count, arg2_buf);
+  arg2_ptr = (grn_ts_bool *)arg2_buf->ptr;
+
+  /* Merge the results. */
+  count = 0;
+  for (i = 0, j = 0; i < n_in; i++) {
+    if (arg1_ptr[i] || arg2_ptr[j++]) {
+      out[count++] = in[i];
+    }
+  }
+  *n_out = count;
+  return GRN_SUCCESS;
 }
 
 /* grn_ts_expr_op_node_filter() filters records. */
-------------- next part --------------
HTML����������������������������...
Download 



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