[Groonga-commit] groonga/groonga [master] Support weight in query() in sub_filter()

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 12 07:24:53 JST 2013


Kouhei Sutou	2013-03-12 07:24:53 +0900 (Tue, 12 Mar 2013)

  New Revision: 928950f3a0642552eed36790bfe3fcaa239c6419
  https://github.com/groonga/groonga/commit/928950f3a0642552eed36790bfe3fcaa239c6419

  Message:
    Support weight in query() in sub_filter()
    
    The following sub_filter() and query() works with this change:
    
      select Users \
        --filter 'sub_filter(a.b, "query(\\"T1.index * 20 || T2.index * 5\\", \\"KEYWORD\\")")'

  Added files:
    test/command/suite/select/filter/query/nested_index.expected
    test/command/suite/select/filter/query/nested_index.test
  Modified files:
    lib/db.c

  Modified: lib/db.c (+8 -3)
===================================================================
--- lib/db.c    2013-03-09 12:56:24 +0900 (2dab15a)
+++ lib/db.c    2013-03-12 07:24:53 +0900 (0fb5d5b)
@@ -2479,9 +2479,12 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
       grn_obj *next_res;
       grn_operator next_op;
       grn_search_optarg next_optarg;
+      grn_rset_recinfo *recinfo;
       if (optarg) {
         next_optarg = *optarg;
         next_optarg.mode = GRN_OP_EXACT;
+      } else {
+        memset(&next_optarg, 0, sizeof(grn_search_optarg));
       }
       if (i == 1) {
         next_res = res;
@@ -2502,12 +2505,14 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
         next_op = GRN_OP_OR;
       }
       domain = grn_ctx_at(ctx, index->header.domain);
-      GRN_HASH_EACH(ctx, (grn_hash *)current_res, id, &tid, NULL, NULL, {
+      GRN_HASH_EACH(ctx, (grn_hash *)current_res, id, &tid, NULL, &recinfo, {
+        next_optarg.weight_vector = NULL;
+        next_optarg.vector_size = recinfo->score;
         if (domain->header.type == GRN_TABLE_NO_KEY) {
           rc = grn_ii_sel(ctx, (grn_ii *)index,
                           (const char *)tid, sizeof(grn_id),
                           (grn_hash *)next_res, next_op,
-                          optarg ? &next_optarg : NULL);
+                          &next_optarg);
         } else {
           char key[GRN_TABLE_MAX_KEY_SIZE];
           int key_len;
@@ -2515,7 +2520,7 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
                                       key, GRN_TABLE_MAX_KEY_SIZE);
           rc = grn_ii_sel(ctx, (grn_ii *)index, key, key_len,
                           (grn_hash *)next_res, next_op,
-                          optarg ? &next_optarg : NULL);
+                          &next_optarg);
         }
         if (rc != GRN_SUCCESS) {
           break;

  Added: test/command/suite/select/filter/query/nested_index.expected (+96 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/query/nested_index.expected    2013-03-12 07:24:53 +0900 (65b498a)
@@ -0,0 +1,96 @@
+table_create Entries TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Entries content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+table_create Blogs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Blogs entries COLUMN_VECTOR Entries
+[[0,0.0,0.0],true]
+table_create Users TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Users blogs COLUMN_VECTOR Blogs
+[[0,0.0,0.0],true]
+column_create Blogs users COLUMN_INDEX Users blogs
+[[0,0.0,0.0],true]
+column_create Entries blogs COLUMN_INDEX Blogs entries
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigram   --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION   Entries content
+[[0,0.0,0.0],true]
+table_create LooseTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText   --default_tokenizer TokenBigramIgnoreBlankSplitSymbolAlphaDigit   --normalizer NormalizerAuto
+[[0,0.0,0.0],true]
+column_create LooseTerms entries_content_index COLUMN_INDEX|WITH_POSITION   Entries content
+[[0,0.0,0.0],true]
+load --table Entries
+[
+{"_key": "alice:2013-03-12",
+ "content": "Welcome! This is my first post!"},
+{"_key": "bob:2013-03-12",
+ "content": "I started to use groonga. It's very fast!"},
+{"_key": "carlos:2013-03-12",
+ "content": "I also started to use mroonga. It's also very fast! Really fast!"},
+{"_key": "alice:2013-03-13",
+ "content": "I also started to use mroonga. It's also very very fast!"},
+{"_key": "bob:2013-03-13",
+ "content": "I migrated all Senna system!"},
+{"_key": "carlos:2013-03-13",
+ "content": "I also migrated all Tritonn system!"}
+]
+[[0,0.0,0.0],6]
+load --table Blogs
+[
+{"_key": "Alice's Adventures in Wonderland",
+ "entries": ["alice:2013-03-12", "alice:2013-03-13"]},
+{"_key": "Bob memo",
+ "entries": ["bob:2013-03-12", "bob:2013-03-13"]},
+{"_key": "Carlog",
+ "entries": ["calros:2013-03-12", "calros:2013-03-13"]}
+]
+[[0,0.0,0.0],3]
+load --table Users
+[
+{"_key": "alice",  "blogs": ["Alice's Adventures in Wonderland"]},
+{"_key": "bob",    "blogs": ["Bob memo"]},
+{"_key": "calros", "blogs": ["Carlog"]}
+]
+[[0,0.0,0.0],3]
+select Users   --filter 'sub_filter(blogs.entries, "query(\\"Terms.entries_content_index * 20 || LooseTerms.entries_content_index * 5\\", \\"groonga\\")")'   --output_columns '_key, blogs.entries.content, _score'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "blogs.entries.content",
+          "Text"
+        ],
+        [
+          "_score",
+          "Int32"
+        ]
+      ],
+      [
+        "bob",
+        [
+          [
+            "I started to use groonga. It's very fast!",
+            "I migrated all Senna system!"
+          ]
+        ],
+        25
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/query/nested_index.test (+60 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/query/nested_index.test    2013-03-12 07:24:53 +0900 (6a6c577)
@@ -0,0 +1,60 @@
+table_create Entries TABLE_HASH_KEY ShortText
+column_create Entries content COLUMN_SCALAR Text
+
+table_create Blogs TABLE_HASH_KEY ShortText
+column_create Blogs entries COLUMN_VECTOR Entries
+
+table_create Users TABLE_HASH_KEY ShortText
+column_create Users blogs COLUMN_VECTOR Blogs
+
+column_create Blogs users COLUMN_INDEX Users blogs
+column_create Entries blogs COLUMN_INDEX Blogs entries
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION \
+  Entries content
+
+table_create LooseTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText \
+  --default_tokenizer TokenBigramIgnoreBlankSplitSymbolAlphaDigit \
+  --normalizer NormalizerAuto
+column_create LooseTerms entries_content_index COLUMN_INDEX|WITH_POSITION \
+  Entries content
+
+load --table Entries
+[
+{"_key": "alice:2013-03-12",
+ "content": "Welcome! This is my first post!"},
+{"_key": "bob:2013-03-12",
+ "content": "I started to use groonga. It's very fast!"},
+{"_key": "carlos:2013-03-12",
+ "content": "I also started to use mroonga. It's also very fast! Really fast!"},
+{"_key": "alice:2013-03-13",
+ "content": "I also started to use mroonga. It's also very very fast!"},
+{"_key": "bob:2013-03-13",
+ "content": "I migrated all Senna system!"},
+{"_key": "carlos:2013-03-13",
+ "content": "I also migrated all Tritonn system!"}
+]
+
+load --table Blogs
+[
+{"_key": "Alice's Adventures in Wonderland",
+ "entries": ["alice:2013-03-12", "alice:2013-03-13"]},
+{"_key": "Bob memo",
+ "entries": ["bob:2013-03-12", "bob:2013-03-13"]},
+{"_key": "Carlog",
+ "entries": ["calros:2013-03-12", "calros:2013-03-13"]}
+]
+
+load --table Users
+[
+{"_key": "alice",  "blogs": ["Alice's Adventures in Wonderland"]},
+{"_key": "bob",    "blogs": ["Bob memo"]},
+{"_key": "calros", "blogs": ["Carlog"]}
+]
+
+select Users \
+  --filter 'sub_filter(blogs.entries, "query(\\"Terms.entries_content_index * 20 || LooseTerms.entries_content_index * 5\\", \\"groonga\\")")' \
+  --output_columns '_key, blogs.entries.content, _score'
-------------- next part --------------
HTML����������������������������...
Download 



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