[Groonga-commit] droonga/fluent-plugin-droonga at 1b72099 [master] Add a test case for search with reference to array

アーカイブの一覧に戻る

Yoji Shidara null+****@clear*****
Thu Nov 28 11:38:59 JST 2013


Yoji Shidara	2013-11-28 11:38:59 +0900 (Thu, 28 Nov 2013)

  New Revision: 1b7209978f9155004d88c4ec862051dac25d3617
  https://github.com/droonga/fluent-plugin-droonga/commit/1b7209978f9155004d88c4ec862051dac25d3617

  Merged 4e131bb: Merge pull request #33 from droonga/add-test-for-search-with-reference-to-array-revised

  Message:
    Add a test case for search with reference to array
    
    This is a test case for 9d6be9fccf1c7283a3fcd6b735a9b100af705a12

  Added files:
    test/unit/fixtures/reference.grn
  Modified files:
    test/unit/plugin/handler/test_search.rb

  Added: test/unit/fixtures/reference.grn (+38 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/fixtures/reference.grn    2013-11-28 11:38:59 +0900 (f3d5490)
@@ -0,0 +1,38 @@
+table_create DocumentsHash TABLE_HASH_KEY ShortText
+column_create DocumentsHash title COLUMN_SCALAR ShortText
+
+load --table DocumentsHash
+[
+{"_key": "Groonga", "title": "Groonga"}
+]
+
+
+table_create SectionsForHash TABLE_HASH_KEY ShortText
+column_create SectionsForHash title COLUMN_SCALAR ShortText
+column_create SectionsForHash document COLUMN_SCALAR DocumentsHash
+load --table SectionsForHash
+[
+{"_key": "1.1", "title": "Groonga overview", "document": "Groonga"},
+{"_key": "1.2", "title": "Full text search and Instant update", "document": "Groonga"},
+{"_key": "1.3", "title": "Column store and aggregate query", "document": "Groonga"}
+]
+
+
+table_create DocumentsArray TABLE_NO_KEY
+column_create DocumentsArray title COLUMN_SCALAR ShortText
+
+load --table DocumentsArray
+[
+{"title": "Groonga"}
+]
+
+
+table_create SectionsForArray TABLE_HASH_KEY ShortText
+column_create SectionsForArray title COLUMN_SCALAR ShortText
+column_create SectionsForArray document COLUMN_SCALAR DocumentsArray
+load --table SectionsForArray
+[
+{"_key": "1.1", "title": "Groonga overview", "document": 1},
+{"_key": "1.2", "title": "Full text search and Instant update", "document": 1},
+{"_key": "1.3", "title": "Column store and aggregate query", "document": 1}
+]

  Modified: test/unit/plugin/handler/test_search.rb (+460 -409)
===================================================================
--- test/unit/plugin/handler/test_search.rb    2013-11-28 15:05:51 +0900 (a6c711c)
+++ test/unit/plugin/handler/test_search.rb    2013-11-28 11:38:59 +0900 (9aafa77)
@@ -20,8 +20,6 @@ class SearchHandlerTest < Test::Unit::TestCase
 
   def setup
     setup_database
-    restore(fixture_data("document.grn"))
-    setup_plugin(Droonga::SearchHandler)
   end
 
   def teardown
@@ -62,162 +60,60 @@ class SearchHandlerTest < Test::Unit::TestCase
     assert_equal(expected, search(request))
   end
 
-  class NoParameterTest < self
-    def test_empty
-      assert_search({}, {})
+  class GeneralTest < self
+    def setup
+      super
+      restore(fixture_data("document.grn"))
+      setup_plugin(Droonga::SearchHandler)
     end
-  end
-
-  class QueriesTest < self
-    def test_empty
-      assert_search({}, {"queries" => {}})
-    end
-  end
-
-  class HashQueryTest < self
-    def test_string_matchTo
-      request = base_request
-      request["queries"]["sections-result"]["condition"] = {
-        "query" => "Groonga",
-        "matchTo" => "title"
-      }
-      assert_search({
-                      "sections-result" => {
-                        "records" => [
-                          { "title" => "Groonga overview" },
-                        ],
-                      },
-                    },
-                    request)
-    end
-
-    def test_array_matchTo
-      request = base_request
-      request["queries"]["sections-result"]["condition"] = {
-        "query" => "Groonga",
-        "matchTo" => ["title"]
-      }
-      assert_search({
-                      "sections-result" => {
-                        "records" => [
-                          { "title" => "Groonga overview" },
-                        ],
-                      },
-                    },
-                    request)
-    end
-
-    def base_request
-      {
-        "queries" => {
-          "sections-result" => {
-            "source" => "Sections",
-            "output" => {
-              "elements" => [
-                "records",
-              ],
-              "format" => "complex",
-              "limit" => 1,
-              "attributes" => ["title"],
-            },
-          },
-        },
-      }
-    end
-  end
 
-  class SourceTest < self
-    def test_non_existent
-      assert_raise(Droonga::Searcher::UndefinedSourceError) do
-        search({
-                 "queries" => {
-                   "non-existent-result" => {
-                     "source" => "non-existent",
-                   },
-                 },
-               })
+    class NoParameterTest < self
+      def test_empty
+        assert_search({}, {})
       end
     end
 
-    def test_existent
-      assert_search({
-                      "sections-result" => {},
-                    },
-                    {
-                      "queries" => {
-                        "sections-result" => {
-                          "source" => "Sections",
-                          "output" => {},
-                        },
-                      },
-                    })
+    class QueriesTest < self
+      def test_empty
+        assert_search({}, {"queries" => {}})
+      end
     end
-  end
 
-  class OutputTest < self
-    def test_count
-      assert_search({
-                      "sections-result" => {
-                        "count" => 9,
-                      },
-                    },
-                    {
-                      "queries" => {
+    class HashQueryTest < self
+      def test_string_matchTo
+        request = base_request
+        request["queries"]["sections-result"]["condition"] = {
+          "query" => "Groonga",
+          "matchTo" => "title"
+        }
+        assert_search({
                         "sections-result" => {
-                          "source" => "Sections",
-                          "output" => {
-                            "elements" => [
-                              "count",
-                            ],
-                          },
+                          "records" => [
+                            { "title" => "Groonga overview" },
+                          ],
                         },
                       },
-                    })
-    end
+                      request)
+      end
 
-    def test_elapsed_time
-      assert_search({
-                      "sections-result" => {
-                        "startTime" => start_time,
-                        "elapsedTime" => elapsed_time,
-                      },
-                    },
-                    {
-                      "queries" => {
+      def test_array_matchTo
+        request = base_request
+        request["queries"]["sections-result"]["condition"] = {
+          "query" => "Groonga",
+          "matchTo" => ["title"]
+        }
+        assert_search({
                         "sections-result" => {
-                          "source" => "Sections",
-                          "output" => {
-                            "elements" => [
-                              "startTime",
-                              "elapsedTime",
-                            ],
-                          },
+                          "records" => [
+                            { "title" => "Groonga overview" },
+                          ],
                         },
                       },
-                    })
-    end
+                      request)
+      end
 
-    class AttributesTest < self
-      def test_source_only
-        expected = {
-          "sections-result" => {
-            "records" => [
-              {
-                "_key" => "1.1",
-                "title" => "Groonga overview",
-              },
-              {
-                "_key" => "1.2",
-                "title" => "Full text search and Instant update",
-              },
-              {
-                "_key" => "1.3",
-                "title" => "Column store and aggregate query",
-              },
-            ],
-          },
-        }
-        request = {
+      def base_request
+        {
           "queries" => {
             "sections-result" => {
               "source" => "Sections",
@@ -226,315 +122,470 @@ class SearchHandlerTest < Test::Unit::TestCase
                   "records",
                 ],
                 "format" => "complex",
-                "limit" => 3,
-                "attributes" => ["_key", "title"],
+                "limit" => 1,
+                "attributes" => ["title"],
               },
             },
           },
         }
-        assert_search(expected, request)
       end
+    end
 
-      def test_source_only_for_reference_column
-        expected = {
-          "sections-result" => {
-            "records" => [
-              {
-                "_key" => "1.1",
-                "document" => "Groonga",
-              },
-              {
-                "_key" => "1.2",
-                "document" => "Groonga",
-              },
-              {
-                "_key" => "1.3",
-                "document" => "Groonga",
-              },
-            ],
-          },
-        }
-        request = {
-          "queries" => {
+    class SourceTest < self
+      def test_non_existent
+        assert_raise(Droonga::Searcher::UndefinedSourceError) do
+          search({
+                   "queries" => {
+                     "non-existent-result" => {
+                       "source" => "non-existent",
+                     },
+                   },
+                 })
+        end
+      end
+
+      def test_existent
+        assert_search({
+                        "sections-result" => {},
+                      },
+                      {
+                        "queries" => {
+                          "sections-result" => {
+                            "source" => "Sections",
+                            "output" => {},
+                          },
+                        },
+                      })
+      end
+    end
+
+    class OutputTest < self
+      def test_count
+        assert_search({
+                        "sections-result" => {
+                          "count" => 9,
+                        },
+                      },
+                      {
+                        "queries" => {
+                          "sections-result" => {
+                            "source" => "Sections",
+                            "output" => {
+                              "elements" => [
+                                "count",
+                              ],
+                            },
+                          },
+                        },
+                      })
+      end
+
+      def test_elapsed_time
+        assert_search({
+                        "sections-result" => {
+                          "startTime" => start_time,
+                          "elapsedTime" => elapsed_time,
+                        },
+                      },
+                      {
+                        "queries" => {
+                          "sections-result" => {
+                            "source" => "Sections",
+                            "output" => {
+                              "elements" => [
+                                "startTime",
+                                "elapsedTime",
+                              ],
+                            },
+                          },
+                        },
+                      })
+      end
+
+      class AttributesTest < self
+        def test_source_only
+          expected = {
             "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "complex",
-                "limit" => 3,
-                "attributes" => ["_key", "document"],
+              "records" => [
+                {
+                  "_key" => "1.1",
+                  "title" => "Groonga overview",
+                },
+                {
+                  "_key" => "1.2",
+                  "title" => "Full text search and Instant update",
+                },
+                {
+                  "_key" => "1.3",
+                  "title" => "Column store and aggregate query",
+                },
+              ],
+            },
+          }
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "complex",
+                  "limit" => 3,
+                  "attributes" => ["_key", "title"],
+                },
               },
             },
-          },
-        }
-        assert_search(expected, request)
-      end
+          }
+          assert_search(expected, request)
+        end
 
-      def test_label
-        expected = {
-          "sections-result" => {
-            "records" => [
-              {
-                "key" => "1.1",
-                "title" => "Groonga overview",
-              },
-              {
-                "key" => "1.2",
-                "title" => "Full text search and Instant update",
-              },
-              {
-                "key" => "1.3",
-                "title" => "Column store and aggregate query",
-              },
-            ],
-          },
-        }
-        request = {
-          "queries" => {
+        def test_label
+          expected = {
             "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "complex",
-                "limit" => 3,
-                "attributes" => [
-                  {
-                    "label" => "key",
-                    "source" => "_key",
-                  },
-                  "title",
-                ],
+              "records" => [
+                {
+                  "key" => "1.1",
+                  "title" => "Groonga overview",
+                },
+                {
+                  "key" => "1.2",
+                  "title" => "Full text search and Instant update",
+                },
+                {
+                  "key" => "1.3",
+                  "title" => "Column store and aggregate query",
+                },
+              ],
+            },
+          }
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "complex",
+                  "limit" => 3,
+                  "attributes" => [
+                    {
+                      "label" => "key",
+                      "source" => "_key",
+                    },
+                    "title",
+                  ],
+                },
               },
             },
-          },
-        }
-        assert_search(expected, request)
-      end
+          }
+          assert_search(expected, request)
+        end
 
-      def test_static_value
-        expected = {
-          "sections-result" => {
-            "records" => [
-              {
-                "single_quote_string" => "string value",
-                "double_quote_string" => "string value",
-                "integer" => 29,
-                "complex_negative_number" => -29.29,
-              },
-              {
-                "single_quote_string" => "string value",
-                "double_quote_string" => "string value",
-                "integer" => 29,
-                "complex_negative_number" => -29.29,
-              },
-            ],
-          },
-        }
-        request = {
-          "queries" => {
+        def test_static_value
+          expected = {
             "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "complex",
-                "limit" => 2,
-                "attributes" => [
-                  {
-                    "label" => "single_quote_string",
-                    "source" => "'string value'",
-                  },
-                  {
-                    "label" => "double_quote_string",
-                    "source" => '"string value"',
-                  },
-                  {
-                    "label" => "integer",
-                    "source" => "29",
-                  },
-                  {
-                    "label" => "complex_negative_number",
-                    "source" => "-29.29",
-                  },
-                ],
+              "records" => [
+                {
+                  "single_quote_string" => "string value",
+                  "double_quote_string" => "string value",
+                  "integer" => 29,
+                  "complex_negative_number" => -29.29,
+                },
+                {
+                  "single_quote_string" => "string value",
+                  "double_quote_string" => "string value",
+                  "integer" => 29,
+                  "complex_negative_number" => -29.29,
+                },
+              ],
+            },
+          }
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "complex",
+                  "limit" => 2,
+                  "attributes" => [
+                    {
+                      "label" => "single_quote_string",
+                      "source" => "'string value'",
+                    },
+                    {
+                      "label" => "double_quote_string",
+                      "source" => '"string value"',
+                    },
+                    {
+                      "label" => "integer",
+                      "source" => "29",
+                    },
+                    {
+                      "label" => "complex_negative_number",
+                      "source" => "-29.29",
+                    },
+                  ],
+                },
               },
             },
-          },
-        }
-        assert_search(expected, request)
-      end
+          }
+          assert_search(expected, request)
+        end
 
-      def test_expression
-        expected = {
-          "sections-result" => {
-            "records" => [
-              {
-                "formatted title" => "<Groonga overview>",
-                "title" => "Groonga overview",
+        def test_expression
+          expected = {
+            "sections-result" => {
+              "records" => [
+                {
+                  "formatted title" => "<Groonga overview>",
+                  "title" => "Groonga overview",
+                },
+              ],
+            },
+          }
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "complex",
+                  "limit" => 1,
+                  "attributes" => [
+                    "title",
+                    {
+                      "label" => "formatted title",
+                      "source" => "'<' + title + '>'",
+                    },
+                  ],
+                },
               },
-            ],
-          },
-        }
-        request = {
-          "queries" => {
+            },
+          }
+          assert_search(expected, request)
+        end
+
+        def test_snippet_html
+          expected = {
             "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "complex",
-                "limit" => 1,
-                "attributes" => [
-                  "title",
-                  {
-                    "label" => "formatted title",
-                    "source" => "'<' + title + '>'",
-                  },
-                ],
+              "records" => [
+                {
+                  "title" => "Groonga overview",
+                  "snippet" => [
+                    "<span class=\"keyword\">Groonga</span> overview",
+                  ],
+                },
+              ],
+            },
+          }
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "condition" => {
+                  "query" => "Groonga",
+                  "matchTo" => ["title"],
+                },
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "complex",
+                  "limit" => 1,
+                  "attributes" => [
+                    "title",
+                    {
+                      "label" => "snippet",
+                      "source" => "snippet_html(title)",
+                    },
+                  ],
+                },
               },
             },
-          },
-        }
-        assert_search(expected, request)
+          }
+          assert_search(expected, request)
+        end
       end
 
-      def test_snippet_html
-        expected = {
-          "sections-result" => {
-            "records" => [
-              {
-                "title" => "Groonga overview",
-                "snippet" => [
-                  "<span class=\"keyword\">Groonga</span> overview",
-                ],
+      class FormatTest < self
+        def test_complex
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "complex",
+                  "limit" => 3,
+                  "attributes" => ["_key", "title"],
+                },
               },
-            ],
-          },
-        }
-        request = {
-          "queries" => {
-            "sections-result" => {
-              "source" => "Sections",
-              "condition" => {
-                "query" => "Groonga",
-                "matchTo" => ["title"],
-              },
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "complex",
-                "limit" => 1,
-                "attributes" => [
-                  "title",
-                  {
-                    "label" => "snippet",
-                    "source" => "snippet_html(title)",
-                  },
-                ],
+            },
+          }
+          assert_search(complex_result, request)
+        end
+
+        def test_simple
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "format" => "simple",
+                  "limit" => 3,
+                  "attributes" => ["_key", "title"],
+                },
               },
             },
-          },
-        }
-        assert_search(expected, request)
-      end
-    end
+          }
+          assert_search(simple_result, request)
+        end
 
-    class FormatTest < self
-      def test_complex
-        request = {
-          "queries" => {
-            "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "complex",
-                "limit" => 3,
-                "attributes" => ["_key", "title"],
+        def test_default
+          request = {
+            "queries" => {
+              "sections-result" => {
+                "source" => "Sections",
+                "output" => {
+                  "elements" => [
+                    "records",
+                  ],
+                  "limit" => 3,
+                  "attributes" => ["_key", "title"],
+                },
               },
             },
-          },
-        }
-        assert_search(complex_result, request)
-      end
+          }
+          assert_search(simple_result, request)
+        end
 
-      def test_simple
-        request = {
-          "queries" => {
+        def complex_result
+          {
             "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "format" => "simple",
-                "limit" => 3,
-                "attributes" => ["_key", "title"],
-              },
+              "records" => [
+                {
+                  "_key" => "1.1",
+                  "title" => "Groonga overview",
+                },
+                {
+                  "_key" => "1.2",
+                  "title" => "Full text search and Instant update",
+                },
+                {
+                  "_key" => "1.3",
+                  "title" => "Column store and aggregate query",
+                },
+              ],
             },
-          },
-        }
-        assert_search(simple_result, request)
-      end
+          }
+        end
 
-      def test_default
-        request = {
-          "queries" => {
+        def simple_result
+          {
             "sections-result" => {
-              "source" => "Sections",
-              "output" => {
-                "elements" => [
-                  "records",
-                ],
-                "limit" => 3,
-                "attributes" => ["_key", "title"],
-              },
+              "records" => [
+                ["1.1", "Groonga overview"],
+                ["1.2", "Full text search and Instant update"],
+                ["1.3", "Column store and aggregate query"],
+              ],
             },
-          },
-        }
-        assert_search(simple_result, request)
+          }
+        end
       end
+    end
+  end
 
-      def complex_result
-        {
+  class ReferenceTest < self
+    def setup
+      super
+      restore(fixture_data("reference.grn"))
+      setup_plugin(Droonga::SearchHandler)
+    end
+
+    def test_reference_to_hash
+      expected = {
+        "sections-result" => {
+          "records" => [
+            {
+              "_key" => "1.1",
+              "document" => "Groonga",
+            },
+            {
+              "_key" => "1.2",
+              "document" => "Groonga",
+            },
+            {
+              "_key" => "1.3",
+              "document" => "Groonga",
+            },
+          ],
+        },
+      }
+      request = {
+        "queries" => {
           "sections-result" => {
-            "records" => [
-              {
-                "_key" => "1.1",
-                "title" => "Groonga overview",
-              },
-              {
-                "_key" => "1.2",
-                "title" => "Full text search and Instant update",
-              },
-              {
-                "_key" => "1.3",
-                "title" => "Column store and aggregate query",
-              },
-            ],
+            "source" => "SectionsForHash",
+            "output" => {
+              "elements" => [
+                "records",
+              ],
+              "format" => "complex",
+              "limit" => 3,
+              "attributes" => ["_key", "document"],
+            },
           },
-        }
-      end
+        },
+      }
+      assert_search(expected, request)
+    end
 
-      def simple_result
-        {
+    def test_reference_to_array
+      expected = {
+        "sections-result" => {
+          "records" => [
+            {
+              "_key" => "1.1",
+              "document" => 1,
+            },
+            {
+              "_key" => "1.2",
+              "document" => 1,
+            },
+            {
+              "_key" => "1.3",
+              "document" => 1,
+            },
+          ],
+        },
+      }
+      request = {
+        "queries" => {
           "sections-result" => {
-            "records" => [
-              ["1.1", "Groonga overview"],
-              ["1.2", "Full text search and Instant update"],
-              ["1.3", "Column store and aggregate query"],
-            ],
+            "source" => "SectionsForArray",
+            "output" => {
+              "elements" => [
+                "records",
+              ],
+              "format" => "complex",
+              "limit" => 3,
+              "attributes" => ["_key", "document"],
+            },
           },
-        }
-      end
+        },
+      }
+      assert_search(expected, request)
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る