[Groonga-commit] groonga/groonga [master] Support sorting not indexed entries

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Mon Feb 18 23:33:51 JST 2013


Kouhei Sutou	2013-02-18 23:33:51 +0900 (Mon, 18 Feb 2013)

  New Revision: 9d6d7b32983cef2d3cee07e172d2740299b401a0
  https://github.com/groonga/groonga/commit/9d6d7b32983cef2d3cee07e172d2740299b401a0

  Log:
    Support sorting not indexed entries
    
    Without this change, --sortby geo_distance(...) drops not indexed
    entries.

  Modified files:
    lib/geo.c
    test/command/suite/select/sort/geo/distance/not_indexed.expected

  Modified: lib/geo.c (+34 -1)
===================================================================
--- lib/geo.c    2013-02-18 11:56:41 +0900 (9588ad6)
+++ lib/geo.c    2013-02-18 23:33:51 +0900 (8748811)
@@ -637,6 +637,8 @@ grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
           grn_id *v;
           grn_geo_point *base_point;
           geo_entry *ep;
+          grn_bool need_non_indexed_entries;
+          grn_hash *indexed_entries = NULL;
 
           base_point = (grn_geo_point *)GRN_BULK_HEAD(arg);
           n = grn_geo_table_sort_detect_far_point(ctx, table, index, pat,
@@ -649,11 +651,42 @@ grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
                                                   entries, n, e, accessorp,
                                                   base_point, d_far, diff_bit);
           }
+          need_non_indexed_entries = offset + limit > n;
+          if (need_non_indexed_entries) {
+            indexed_entries = grn_hash_create(ctx, NULL, sizeof(grn_id), 0,
+                                              GRN_OBJ_TABLE_HASH_KEY|GRN_HASH_TINY);
+          }
           for (i = 0, ep = entries + offset; i < limit && ep < entries + n; i++, ep++) {
-            if (!grn_array_add(ctx, (grn_array *)result, (void **)&v)) { break; }
+            if (!grn_array_add(ctx, (grn_array *)result, (void **)&v)) {
+              if (indexed_entries) {
+                grn_hash_close(ctx, indexed_entries);
+                indexed_entries = NULL;
+              }
+              need_non_indexed_entries = GRN_FALSE;
+              break;
+            }
             *v = ep->id;
+            if (indexed_entries) {
+              grn_hash_add(ctx, indexed_entries, &(ep->id), sizeof(grn_id),
+                           NULL, NULL);
+            }
           }
           GRN_FREE(entries);
+          if (indexed_entries) {
+            GRN_TABLE_EACH(ctx, table, GRN_ID_NIL, GRN_ID_MAX, id, NULL, NULL, NULL, {
+              if (!grn_hash_get(ctx, indexed_entries, &id, sizeof(grn_id), NULL)) {
+                grn_id *sorted_id;
+                if (grn_array_add(ctx, (grn_array *)result, (void **)&sorted_id)) {
+                  *sorted_id = id;
+                }
+                i++;
+                if (i == limit) {
+                  break;
+                }
+              };
+            });
+            grn_hash_close(ctx, indexed_entries);
+          }
         }
       }
     }

  Modified: test/command/suite/select/sort/geo/distance/not_indexed.expected (+5 -0)
===================================================================
--- test/command/suite/select/sort/geo/distance/not_indexed.expected    2013-02-18 11:56:41 +0900 (c9dcbe5)
+++ test/command/suite/select/sort/geo/distance/not_indexed.expected    2013-02-18 23:33:51 +0900 (63a4505)
@@ -44,6 +44,11 @@ select Shops   --sortby 'geo_distance(location, "35.67487x139.76352")'   --outpu
         1,
         "根津のたいやき",
         "128592911x503145263"
+      ],
+      [
+        2,
+        "たい焼 カタオカ",
+        "0x0"
       ]
     ]
   ]
-------------- next part --------------
HTML����������������������������...
ダウンロード 



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