[Groonga-commit] ranguba/rroonga at 51350ef [master] Add Groonga::Expression#estimate_size

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Feb 18 17:58:38 JST 2015


Kouhei Sutou	2015-02-18 17:58:38 +0900 (Wed, 18 Feb 2015)

  New Revision: 51350ef85630a5e045e07ada3b19e5ff9586fa00
  https://github.com/ranguba/rroonga/commit/51350ef85630a5e045e07ada3b19e5ff9586fa00

  Message:
    Add Groonga::Expression#estimate_size
    
    It's for testing Groonga.
    
    `grn_expr_estimate_size()` availability check should be removed after
    Groonga 5.0.1 is released.

  Modified files:
    ext/groonga/extconf.rb
    ext/groonga/rb-grn-expression.c

  Modified: ext/groonga/extconf.rb (+4 -1)
===================================================================
--- ext/groonga/extconf.rb    2015-02-16 18:56:46 +0900 (1eb4e54)
+++ ext/groonga/extconf.rb    2015-02-18 17:58:38 +0900 (2a680c4)
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 #
-# Copyright (C) 2009-2014  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2009-2015  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -284,6 +284,9 @@ have_func("rb_sym2str", "ruby.h")
 have_func("rb_to_symbol", "ruby.h")
 have_type("enum ruby_value_type", "ruby.h")
 
+# TODO: Remove me when Groonga 5.0.1 is released.
+have_func("grn_expr_estimate_size", "groonga.h")
+
 checking_for(checking_message("--enable-debug-log option")) do
   enable_debug_log = enable_config("debug-log", false)
   if enable_debug_log

  Modified: ext/groonga/rb-grn-expression.c (+42 -1)
===================================================================
--- ext/groonga/rb-grn-expression.c    2015-02-16 18:56:46 +0900 (8bb8b64)
+++ ext/groonga/rb-grn-expression.c    2015-02-18 17:58:38 +0900 (b6cf222)
@@ -1,6 +1,6 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
-  Copyright (C) 2009-2014  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2009-2015  Kouhei Sutou <kou �� clear-code.com>
   Copyright (C) 2014  Masafumi Yokoyama <myokoym �� gmail.com>
 
   This library is free software; you can redistribute it and/or
@@ -785,6 +785,42 @@ rb_grn_expression_get_keywords (VALUE self)
     return rb_keywords;
 }
 
+/* TODO: Remove the ifdef when Groonga 5.0.1 is released. */
+#ifdef HAVE_GRN_EXPR_ESTIMATE_SIZE
+/*
+ * Estimates the number of matched records when `expression` is
+ * executed.
+ *
+ * Note that the estimated size isn't correct value. It's just
+ * estimated size.
+ *
+ * @example
+ *   expression.parse("Ruby OR Groonga")
+ *   expression.estimate_size # => 10
+ *
+ * @overload estimate_size
+ *   @return [Integer] the estimated number of matched records when
+ *     `expression` is executed.
+ *
+ * @since 5.0.1
+ */
+static VALUE
+rb_grn_expression_estimate_size (VALUE self)
+{
+    grn_ctx *context = NULL;
+    grn_obj *expression;
+    unsigned int size;
+
+    rb_grn_expression_deconstruct(SELF(self), &expression, &context,
+                                  NULL, NULL,
+                                  NULL, NULL, NULL);
+
+    size = grn_expr_estimate_size(context, expression);
+
+    return UINT2NUM(size);
+}
+#endif
+
 void
 rb_grn_init_expression (VALUE mGrn)
 {
@@ -821,6 +857,11 @@ rb_grn_init_expression (VALUE mGrn)
     rb_define_method(rb_cGrnExpression, "keywords",
                      rb_grn_expression_get_keywords, 0);
 
+#ifdef HAVE_GRN_EXPR_ESTIMATE_SIZE
+    rb_define_method(rb_cGrnExpression, "estimate_size",
+                     rb_grn_expression_estimate_size, 0);
+#endif
+
     rb_define_method(rb_cGrnExpression, "inspect",
                      rb_grn_expression_inspect, 0);
 }
-------------- next part --------------
HTML����������������������������...
Download 



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