[Groonga-commit] groonga/groonga at 10fe595 [master] mrb: support near search

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Aug 20 22:46:13 JST 2014


Kouhei Sutou	2014-08-20 22:46:13 +0900 (Wed, 20 Aug 2014)

  New Revision: 10fe5959609b4aef114d6f0216c77de0c19f086b
  https://github.com/groonga/groonga/commit/10fe5959609b4aef114d6f0216c77de0c19f086b

  Message:
    mrb: support near search

  Modified files:
    lib/mrb/scripts/scan_info.rb
    lib/mrb/scripts/scan_info_data.rb

  Modified: lib/mrb/scripts/scan_info.rb (+3 -0)
===================================================================
--- lib/mrb/scripts/scan_info.rb    2014-08-20 22:44:49 +0900 (80c9267)
+++ lib/mrb/scripts/scan_info.rb    2014-08-20 22:46:13 +0900 (9977d9b)
@@ -13,6 +13,9 @@ module Groonga
       self.end = data.end
       self.query = data.query
       self.flags = data.flags
+      if data.max_interval
+        self.max_interval = data.max_interval
+      end
       data.args.each do |arg|
         push_arg(arg)
       end

  Modified: lib/mrb/scripts/scan_info_data.rb (+41 -8)
===================================================================
--- lib/mrb/scripts/scan_info_data.rb    2014-08-20 22:44:49 +0900 (119824e)
+++ lib/mrb/scripts/scan_info_data.rb    2014-08-20 22:46:13 +0900 (87eb9ed)
@@ -8,6 +8,7 @@ module Groonga
     attr_accessor :args
     attr_accessor :indexes
     attr_accessor :flags
+    attr_accessor :max_interval
     def initialize(start)
       @start = start
       @end = 0
@@ -17,9 +18,49 @@ module Groonga
       @args = []
       @indexes = []
       @flags = ScanInfo::Flags::PUSH
+      @max_interval = nil
     end
 
     def match_resolve_index
+      if near_search?
+        match_near_resolve_index
+      else
+        match_generic_resolve_index
+      end
+    end
+
+    def call_relational_resolve_indexes
+      # better index resolving framework for functions should be implemented
+      @args.each do |arg|
+        call_relational_resolve_index(arg)
+      end
+    end
+
+    private
+    def near_search?
+      (@op == Operator::NEAR or @op == Operator::NEAR2) and****@args***** == 3
+    end
+
+    def match_near_resolve_index
+      arg = @args[0]
+      case arg
+      when Expression
+        match_resolve_index_expression(arg)
+      when Accessor
+        match_resolve_index_accessor(arg)
+      when Object
+        match_resolve_index_db_obj(arg)
+      else
+        message =
+          "The first argument of NEAR/NEAR2 must be Expression, Accessor or Object: #{arg.class}"
+        raise message
+      end
+
+      self.query = @args[1]
+      self.max_interval = @args[2].value
+    end
+
+    def match_generic_resolve_index
       @args.each do |arg|
         case arg
         when Expression
@@ -34,14 +75,6 @@ module Groonga
       end
     end
 
-    def call_relational_resolve_indexes
-      # better index resolving framework for functions should be implemented
-      @args.each do |arg|
-        call_relational_resolve_index(arg)
-      end
-    end
-
-    private
     def match_resolve_index_expression(expression)
       codes = expression.codes
       n_codes = codes.size
-------------- next part --------------
HTML����������������������������...
下載 



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