[Groonga-commit] groonga/groonga [master] [suggest] Added limit parameter for httpd. refs #899

Back to archive index

null+****@clear***** null+****@clear*****
2011年 4月 5日 (火) 14:56:09 JST


Tasuku SUENAGA a.k.a. gunyarakun	2011-04-05 05:56:09 +0000 (Tue, 05 Apr 2011)

  New Revision: 9d8c33f5b147b24e1f6847d02a8ce1ed9ebf434b

  Log:
    [suggest] Added limit parameter for httpd. refs #899

  Modified files:
    src/suggest/groonga_suggest_httpd.c
    src/suggest/groonga_suggest_learner.c
    src/suggest/util.c
    src/suggest/util.h

  Modified: src/suggest/groonga_suggest_httpd.c (+11 -5)
===================================================================
--- src/suggest/groonga_suggest_httpd.c    2011-04-04 09:51:30 +0000 (588e101)
+++ src/suggest/groonga_suggest_httpd.c    2011-04-05 05:56:09 +0000 (7a7a300)
@@ -80,7 +80,9 @@ static volatile sig_atomic_t loop = 1;
 static grn_obj *db;
 
 static int
-suggest_result(struct evbuffer *res_buf, const char *types, const char *query, const char *target_name, int threshold, grn_obj *cmd_buf, grn_ctx *ctx)
+suggest_result(struct evbuffer *res_buf, const char *types, const char *query,
+               const char *target_name, int threshold, int limit,
+               grn_obj *cmd_buf, grn_ctx *ctx)
 {
   if (target_name && types && query) {
     GRN_BULK_REWIND(cmd_buf);
@@ -92,6 +94,8 @@ suggest_result(struct evbuffer *res_buf, const char *types, const char *query, c
     grn_text_urlenc(ctx, cmd_buf, query, strlen(query));
     GRN_TEXT_PUTS(ctx, cmd_buf, "&threshold=");
     grn_text_itoa(ctx, cmd_buf, threshold);
+    GRN_TEXT_PUTS(ctx, cmd_buf, "&limit=");
+    grn_text_itoa(ctx, cmd_buf, limit);
     {
       char *res;
       int flags;
@@ -112,13 +116,13 @@ suggest_result(struct evbuffer *res_buf, const char *types, const char *query, c
 static int
 log_send(struct evbuffer *res_buf, thd_data *thd, struct evkeyvalq *get_args)
 {
-  int threshold;
   uint64_t millisec;
+  int threshold, limit;
   const char *callback, *types, *query, *client_id, *target_name,
              *learn_target_name;
 
   parse_keyval(get_args, &query, &types, &client_id, &target_name,
-               &learn_target_name, &callback, &millisec, &threshold);
+               &learn_target_name, &callback, &millisec, &threshold, &limit);
 
   /* send data to learn client */
   if (thd->zmq_sock && millisec && client_id && query && learn_target_name) {
@@ -190,10 +194,12 @@ log_send(struct evbuffer *res_buf, thd_data *thd, struct evkeyvalq *get_args)
       content_length = strlen(callback);
       evbuffer_add(res_buf, callback, content_length);
       evbuffer_add(res_buf, "(", 1);
-      content_length += suggest_result(res_buf, types, query, target_name, threshold, &(thd->cmd_buf), thd->ctx) + 3;
+      content_length += suggest_result(res_buf, types, query, target_name,
+        threshold, limit, &(thd->cmd_buf), thd->ctx) + 3;
       evbuffer_add(res_buf, ");", 2);
     } else {
-      content_length = suggest_result(res_buf, types, query, target_name, threshold, &(thd->cmd_buf), thd->ctx);
+      content_length = suggest_result(res_buf, types, query, target_name,
+        threshold, limit, &(thd->cmd_buf), thd->ctx);
     }
     return content_length;
   }

  Modified: src/suggest/groonga_suggest_learner.c (+1 -1)
===================================================================
--- src/suggest/groonga_suggest_learner.c    2011-04-04 09:51:30 +0000 (3f1af23)
+++ src/suggest/groonga_suggest_learner.c    2011-04-05 05:56:09 +0000 (2c7952b)
@@ -543,7 +543,7 @@ read_log_line(suggest_log_file **list)
         *eol = '\0';
         evhttp_parse_query(line_buf, &get_args);
         parse_keyval(&get_args, &query, &types, &client_id, NULL,
-                     &learn_target_name, NULL, &(t->millisec), NULL);
+                     &learn_target_name, NULL, &(t->millisec), NULL, NULL);
         if (query && client_id && learn_target_name && t->millisec) {
           t->query = evhttp_decode_uri(query);
           t->submit = (types && !strcmp(types, "submit"));

  Modified: src/suggest/util.c (+8 -1)
===================================================================
--- src/suggest/util.c    2011-04-04 09:51:30 +0000 (6cd2087)
+++ src/suggest/util.c    2011-04-05 05:56:09 +0000 (ce36e7b)
@@ -99,7 +99,8 @@ parse_keyval(struct evkeyvalq *get_args,
              const char **learn_target_name,
              const char **callback,
              uint64_t *millisec,
-             int *threshold)
+             int *threshold,
+             int *limit)
 {
   struct evkeyval *get;
 
@@ -111,6 +112,7 @@ parse_keyval(struct evkeyvalq *get_args,
   if (callback) { *callback = NULL; }
   if (millisec) { *millisec = 0; }
   if (threshold) { *threshold = DEFAULT_THRESHOLD; }
+  if (limit) { *limit = -1; }
 
   TAILQ_FOREACH(get, get_args, next) {
     switch(get->key[0]) {
@@ -156,6 +158,11 @@ parse_keyval(struct evkeyvalq *get_args,
         *threshold = atoi(get->value);
       }
       break;
+    case 'm':
+      if (limit) {
+        *limit = atoi(get->value);
+      }
+      break;
     default:
       break;
     }

  Modified: src/suggest/util.h (+2 -1)
===================================================================
--- src/suggest/util.h    2011-04-04 09:51:30 +0000 (455147c)
+++ src/suggest/util.h    2011-04-05 05:56:09 +0000 (dafc8eb)
@@ -29,6 +29,7 @@ void parse_keyval(struct evkeyvalq *get_args,
                   const char **learn_target_name,
                   const char **callback,
                   uint64_t *millisec,
-                  int *threshold);
+                  int *threshold,
+                  int *limit);
 
 #endif /* GRN_SUGGEST_UTIL_H */




Groonga-commit メーリングリストの案内
Back to archive index