[Groonga-commit] groonga/groonga at 35451c0 [master] grn_ts: support operators "/" and "%" for score adjustment

Zurück zum Archiv-Index

susumu.yata null+****@clear*****
Tue Sep 15 13:37:21 JST 2015


susumu.yata	2015-09-15 13:37:21 +0900 (Tue, 15 Sep 2015)

  New Revision: 35451c069540f0fdbea03864278871669c432074
  https://github.com/groonga/groonga/commit/35451c069540f0fdbea03864278871669c432074

  Message:
    grn_ts: support operators "/" and "%" for score adjustment
    
    GitHub: #387

  Modified files:
    lib/ts.c

  Modified: lib/ts.c (+56 -0)
===================================================================
--- lib/ts.c    2015-09-15 13:09:43 +0900 (8b60bd9)
+++ lib/ts.c    2015-09-15 13:37:21 +0900 (a6c586e)
@@ -1084,6 +1084,42 @@ grn_ts_op_multiplication_float(grn_ts_float lhs, grn_ts_float rhs) {
 
 /* TODO: Division and modulus (Note for division by zero). */
 
+/*
+ * grn_ts_op_division_int() returns lhs / rhs.
+ *
+ * This function causes a critical error in the following cases:
+ * - rhs == 0
+ * - (lhs == INT64_MIN) && (rhs == -1)
+ */
+inline static grn_ts_int
+grn_ts_op_division_int(grn_ts_int lhs, grn_ts_int rhs) {
+  return lhs / rhs;
+}
+
+/* grn_ts_op_division_float() returns lhs / rhs. */
+inline static grn_ts_float
+grn_ts_op_division_float(grn_ts_float lhs, grn_ts_float rhs) {
+  return lhs / rhs;
+}
+
+/*
+ * grn_ts_op_modulus_int() returns lhs % rhs.
+ *
+ * This function causes a critical error in the following cases:
+ * - rhs == 0
+ * - (lhs == INT64_MIN) && (rhs == -1)
+ */
+inline static grn_ts_int
+grn_ts_op_modulus_int(grn_ts_int lhs, grn_ts_int rhs) {
+  return lhs % rhs;
+}
+
+/* grn_ts_op_modulus_float() returns lhs % rhs. */
+inline static grn_ts_float
+grn_ts_op_modulus_float(grn_ts_float lhs, grn_ts_float rhs) {
+  return fmod(lhs, rhs);
+}
+
 /*-------------------------------------------------------------
  * Groonga objects.
  */
@@ -3266,6 +3302,20 @@ grn_ts_op_multiplication_adjust(grn_ctx *ctx, grn_ts_expr_op_node *node,
                                 grn_ts_record *io, size_t n_io) {
   GRN_TS_OP_ARITH_FILTER(multiplication)
 }
+
+/* grn_ts_op_division_adjust() updates scores. */
+static grn_rc
+grn_ts_op_division_adjust(grn_ctx *ctx, grn_ts_expr_op_node *node,
+                          grn_ts_record *io, size_t n_io) {
+  GRN_TS_OP_ARITH_FILTER(division)
+}
+
+/* grn_ts_op_modulus_adjust() updates scores. */
+static grn_rc
+grn_ts_op_modulus_adjust(grn_ctx *ctx, grn_ts_expr_op_node *node,
+                         grn_ts_record *io, size_t n_io) {
+  GRN_TS_OP_ARITH_FILTER(modulus)
+}
 #undef GRN_TS_OP_ARITH_FILTER
 
 /* grn_ts_expr_op_node_adjust() updates scores. */
@@ -3282,6 +3332,12 @@ grn_ts_expr_op_node_adjust(grn_ctx *ctx, grn_ts_expr_op_node *node,
     case GRN_TS_OP_MULTIPLICATION: {
       return grn_ts_op_multiplication_adjust(ctx, node, io, n_io);
     }
+    case GRN_TS_OP_DIVISION: {
+      return grn_ts_op_division_adjust(ctx, node, io, n_io);
+    }
+    case GRN_TS_OP_MODULUS: {
+      return grn_ts_op_modulus_adjust(ctx, node, io, n_io);
+    }
     // TODO: Add operators.
     default: {
       return GRN_OPERATION_NOT_SUPPORTED;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index