[Groonga-commit] ranguba/groonga-client at 99b1030 [master] index-check: support target specification by lexicon

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Oct 30 17:22:58 JST 2017


Kouhei Sutou	2017-10-30 17:22:58 +0900 (Mon, 30 Oct 2017)

  New Revision: 99b1030999bb58ca86662d48e4b80630455d31cd
  https://github.com/ranguba/groonga-client/commit/99b1030999bb58ca86662d48e4b80630455d31cd

  Message:
    index-check: support target specification by lexicon

  Modified files:
    lib/groonga/client/command-line/groonga-client-index-check.rb
    test/command-line/test-index-check.rb

  Modified: lib/groonga/client/command-line/groonga-client-index-check.rb (+22 -29)
===================================================================
--- lib/groonga/client/command-line/groonga-client-index-check.rb    2017-10-30 17:10:03 +0900 (a8c44d4)
+++ lib/groonga/client/command-line/groonga-client-index-check.rb    2017-10-30 17:22:58 +0900 (c076c80)
@@ -30,7 +30,7 @@ module Groonga
 
         def run(arguments)
           parser = Parser.new
-          indexe_names = parser.parse(arguments) do |option_parser|
+          target_names = parser.parse(arguments) do |option_parser|
             parse_command_line(option_parser)
           end
 
@@ -39,14 +39,14 @@ module Groonga
           end
 
           parser.open_client do |client|
-            checker = Checker.new(client, @methods, indexe_names)
+            checker = Checker.new(client, @methods, target_names)
             checker.run
           end
         end
 
         private
         def parse_command_line(parser)
-          parser.banner += " [LEXICON1.INDEX1 LEXICON2.INDEX2 ...]"
+          parser.banner += " [LEXICON1.INDEX1 LEXICON2.INDEX2 LEXICON3 ...]"
 
           parser.separator("")
           parser.separator("If no indexes are specified, " +
@@ -69,10 +69,10 @@ module Groonga
         end
 
         class Checker < Runner
-          def initialize(client, methods, index_names)
+          def initialize(client, methods, target_names)
             super(client)
             @methods = methods
-            @index_names = index_names
+            @target_names = target_names
           end
 
           private
@@ -90,43 +90,36 @@ module Groonga
 
           def each_target_index_column
             table_list.each do |table|
-              next unless check_target_table?(table.name)
+              next unless target_table?(table)
               column_list(table.name).each do |column|
-                next unless check_target_column?(column)
                 next unless column.index?
+                next unless target_column?(column)
                 yield(column)
               end
             end
           end
 
-          def check_target_table?(table_name)
-            unless @index_names.count > 0
-              return true
-            end
-            if @index_names.kind_of?(Array)
-              @index_names.each do |name|
-                table_part = name.split(".").first
-                return true if table_name == table_part
+          def target_table?(table)
+            return true if @target_names.empty?
+            @target_names.any? do |name|
+              if name.include?(".")
+                index_table_name = name.split(".").first
+                index_table_name == table.name
+              else
+                name == table.name
               end
             end
-            false
           end
 
-          def check_target_column?(column)
-            unless @index_names.count > 0
-              return column["type"] == "index"
-            else
-              unless column["type"] == "index"
-                return false
-              end
-            end
-            if @index_names.kind_of?(Array)
-              @index_names.each do |name|
-                return true if name == "#{column['domain']}.#{column['name']}" or
-                  name == column["domain"]
+          def target_column?(column)
+            return true if @target_names.empty?
+            @target_names.any? do |name|
+              if name.include?(".")
+                name == column.full_name
+              else
+                name == column["domain"]
               end
             end
-            false
           end
 
           def check_source(column)

  Modified: test/command-line/test-index-check.rb (+61 -7)
===================================================================
--- test/command-line/test-index-check.rb    2017-10-30 17:10:03 +0900 (097da6a)
+++ test/command-line/test-index-check.rb    2017-10-30 17:22:58 +0900 (6062f9e)
@@ -108,8 +108,48 @@ delete --table Terms --key is
                    index_check("--method=content"))
     end
 
+    def test_table
+      restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms1 TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms1 memos_content1 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+column_create Terms1 memos_content2 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+
+table_create Terms2 TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms2 memos_content \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+
+load --table Memos
+[
+["_key", "content"],
+["groonga", "Groonga is fast"]
+]
+
+delete --table Terms1 --key is
+delete --table Terms2 --key is
+      COMMANDS
+
+      assert_equal([
+                     false,
+                     "",
+                     "Broken: Terms1.memos_content1: <is>\n" +
+                     "Broken: Terms1.memos_content2: <is>\n",
+                   ],
+                   index_check("--method=content", "Terms1"))
+    end
 
-    def test_specify
+    def test_index_column
       restore(<<-COMMANDS)
 table_create Memos TABLE_HASH_KEY ShortText
 column_create Memos content COLUMN_SCALAR Text
@@ -141,7 +181,7 @@ delete --table Terms --key is
                    index_check("--method=content", "Terms.memos_content1"))
     end
 
-    def test_broken_single_column
+    def test_index_columns
       restore(<<-COMMANDS)
 table_create Memos TABLE_HASH_KEY ShortText
 column_create Memos content COLUMN_SCALAR Text
@@ -149,20 +189,34 @@ column_create Memos content COLUMN_SCALAR Text
 table_create Terms TABLE_PAT_KEY ShortText \
   --normalizer NormalizerAuto \
   --default_tokenizer TokenBigram
-column_create Terms memos_content \
+column_create Terms memos_content1 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+column_create Terms memos_content2 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+column_create Terms memos_content3 \
   COLUMN_INDEX|WITH_POSITION \
   Memos content
 
 load --table Memos
 [
-{"_key": "groonga", "content": "Groonga is fast"}
+["_key", "content"],
+["groonga", "Groonga is fast"]
 ]
 
-delete Terms --key is
+delete --table Terms --key is
       COMMANDS
 
-      assert_equal([false, "", "Broken: Terms.memos_content: <is>\n"],
-                   index_check("--method=content"))
+      assert_equal([
+                     false,
+                     "",
+                     "Broken: Terms.memos_content1: <is>\n" +
+                     "Broken: Terms.memos_content2: <is>\n",
+                   ],
+                   index_check("--method=content",
+                               "Terms.memos_content1",
+                               "Terms.memos_content2"))
     end
 
     def test_key
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171030/400c9625/attachment-0001.htm 



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