[Groonga-commit] groonga/groonga at 99886d9 [master] Add grn_expr_get_keywords()

Back to archive index

naoa null+****@clear*****
Sun Aug 10 06:45:26 JST 2014


naoa	2014-08-10 06:45:26 +0900 (Sun, 10 Aug 2014)

  New Revision: 99886d9ff8c7899db4161d91addf8f4758af381c
  https://github.com/groonga/groonga/commit/99886d9ff8c7899db4161d91addf8f4758af381c

  Merged c514768: Merge pull request #185 from naoa/add-highlight_html-function

  Message:
    Add grn_expr_get_keywords()
    
    It gets keywords from expression.
    
    TODO: Document it.

  Modified files:
    include/groonga.h
    lib/expr.c

  Modified: include/groonga.h (+2 -0)
===================================================================
--- include/groonga.h    2014-08-10 03:41:10 +0900 (4460f1b)
+++ include/groonga.h    2014-08-10 06:45:26 +0900 (32a7870)
@@ -1748,6 +1748,8 @@ GRN_API grn_rc grn_expr_snip_add_conditions(grn_ctx *ctx,
                                             const char **closetags,
                                             unsigned int *closetag_lens);
 
+GRN_API grn_rc grn_expr_get_keywords(grn_ctx *ctx, grn_obj *expr, grn_obj *got_keywords);
+
 GRN_API grn_table_sort_key *grn_table_sort_key_from_str(grn_ctx *ctx,
                                                         const char *str, unsigned int str_size,
                                                         grn_obj *table, unsigned int *nkeys);

  Modified: lib/expr.c (+41 -0)
===================================================================
--- lib/expr.c    2014-08-10 03:41:10 +0900 (702af5a)
+++ lib/expr.c    2014-08-10 06:45:26 +0900 (4569923)
@@ -7000,3 +7000,44 @@ grn_expr_syntax_escape_query(grn_ctx *ctx, const char *query, int query_size,
                                 target_characters, GRN_QUERY_ESCAPE,
                                 escaped_query);
 }
+
+grn_rc
+grn_expr_get_keywords(grn_ctx *ctx, grn_obj *expr, grn_obj *got_keywords)
+{
+  int i, n;
+  scan_info **sis, *si;
+  GRN_API_ENTER;
+  if ((sis = scan_info_build(ctx, expr, &n, GRN_OP_OR, 0))) {
+    int butp = 0, nparens = 0, npbut = 0;
+    grn_obj but_stack;
+    GRN_UINT32_INIT(&but_stack, GRN_OBJ_VECTOR);
+    for (i = n; i--;) {
+      si = sis[i];
+      if (si->flags & SCAN_POP) {
+        nparens++;
+        if (si->logical_op == GRN_OP_AND_NOT) {
+          GRN_UINT32_PUT(ctx, &but_stack, npbut);
+          npbut = nparens;
+          butp = 1 - butp;
+        }
+      } else {
+        if (si->op == GRN_OP_MATCH && si->query) {
+          if (butp == (si->logical_op == GRN_OP_AND_NOT)) {
+            GRN_PTR_PUT(ctx, got_keywords, si->query);
+          }
+        }
+        if (si->flags & SCAN_PUSH) {
+          if (nparens == npbut) {
+            butp = 1 - butp;
+            GRN_UINT32_POP(&but_stack, npbut);
+          }
+          nparens--;
+        }
+      }
+    }
+    GRN_OBJ_FIN(ctx, &but_stack);
+    for (i = n; i--;) { SI_FREE(sis[i]); }
+    GRN_FREE(sis);
+  }
+  GRN_API_RETURN(GRN_SUCCESS);
+}
-------------- next part --------------
HTML����������������������������...
다운로드 



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