[Groonga-commit] groonga/groonga at 032b77d [master] Support near search by '*N"A Z"' syntax

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Aug 14 21:30:36 JST 2014


Kouhei Sutou	2014-08-14 21:30:36 +0900 (Thu, 14 Aug 2014)

  New Revision: 032b77d707ff4ff64354128f2e5b7c2d69b791d2
  https://github.com/groonga/groonga/commit/032b77d707ff4ff64354128f2e5b7c2d69b791d2

  Message:
    Support near search by '*N"A Z"' syntax
    
    The max interval between each term is always 10.

  Added files:
    test/command/suite/select/query/near_search/default_interval/match.expected
    test/command/suite/select/query/near_search/default_interval/match.test
    test/command/suite/select/query/near_search/default_interval/not_match.expected
    test/command/suite/select/query/near_search/default_interval/not_match.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+11 -3)
===================================================================
--- lib/expr.c    2014-08-14 20:28:13 +0900 (6801087)
+++ lib/expr.c    2014-08-14 21:30:36 +0900 (fbd32df)
@@ -5609,9 +5609,10 @@ get_word(grn_ctx *ctx, efs_info *q, grn_obj *column, int mode, int option)
   return GRN_SUCCESS;
 }
 
-static void
+static grn_bool
 get_op(efs_info *q, efs_op *op, grn_operator *mode, int *option)
 {
+  grn_bool found = GRN_TRUE;
   const char *start, *end = q->cur;
   switch (*end) {
   case 'S' :
@@ -5650,8 +5651,10 @@ get_op(efs_info *q, efs_op *op, grn_operator *mode, int *option)
     q->cur = end;
     break;
   default :
+    found = GRN_FALSE;
     break;
   }
+  return found;
 }
 
 static grn_rc
@@ -6057,9 +6060,14 @@ parse_query(grn_ctx *ctx, efs_info *q)
 
       break;
     case GRN_QUERY_PREFIX :
-      PARSE(GRN_EXPR_TOKEN_MATCH);
       q->cur++;
-      get_op(q, op, &mode, &option);
+      if (get_op(q, op, &mode, &option)) {
+        GRN_INT32_PUT(ctx, &q->mode_stack, mode);
+        PARSE(GRN_EXPR_TOKEN_RELATIVE_OP);
+      } else {
+        q->cur--;
+        get_word_(ctx, q);
+      }
       break;
     case GRN_QUERY_AND :
       if (!first_token) {

  Added: test/command/suite/select/query/near_search/default_interval/match.expected (+47 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/query/near_search/default_interval/match.expected    2014-08-14 21:30:36 +0900 (72258e8)
@@ -0,0 +1,47 @@
+table_create Memos TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR ShortText
+[[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 memos_content COLUMN_INDEX|WITH_POSITION Memos content
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key":"alphabets", "content": "a b c d e f g h i j k l m"}
+]
+[[0,0.0,0.0],1]
+select --table Memos --match_columns content --query '*N"a l"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "content",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        "alphabets",
+        "a b c d e f g h i j k l m"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/query/near_search/default_interval/match.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/query/near_search/default_interval/match.test    2014-08-14 21:30:36 +0900 (6e7e38e)
@@ -0,0 +1,14 @@
+table_create Memos TABLE_PAT_KEY ShortText
+column_create Memos content COLUMN_SCALAR ShortText
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
+
+load --table Memos
+[
+{"_key":"alphabets", "content": "a b c d e f g h i j k l m"}
+]
+
+select --table Memos --match_columns content --query '*N"a l"'

  Added: test/command/suite/select/query/near_search/default_interval/not_match.expected (+42 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/query/near_search/default_interval/not_match.expected    2014-08-14 21:30:36 +0900 (9a9c6e2)
@@ -0,0 +1,42 @@
+table_create Memos TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR ShortText
+[[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 memos_content COLUMN_INDEX|WITH_POSITION Memos content
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key":"alphabets", "content": "a b c d e f g h i j k l m"}
+]
+[[0,0.0,0.0],1]
+select --table Memos --match_columns content --query '*N"a m"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        0
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "content",
+          "ShortText"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/query/near_search/default_interval/not_match.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/query/near_search/default_interval/not_match.test    2014-08-14 21:30:36 +0900 (4e5252e)
@@ -0,0 +1,14 @@
+table_create Memos TABLE_PAT_KEY ShortText
+column_create Memos content COLUMN_SCALAR ShortText
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
+
+load --table Memos
+[
+{"_key":"alphabets", "content": "a b c d e f g h i j k l m"}
+]
+
+select --table Memos --match_columns content --query '*N"a m"'
-------------- next part --------------
HTML����������������������������...
다운로드 



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