[Groonga-commit] groonga/groonga [master] Fix broken geo sort

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jan 22 15:22:31 JST 2013


Kouhei Sutou	2013-01-22 15:22:31 +0900 (Tue, 22 Jan 2013)

  New Revision: 96af9c36cc42280dd17f9a6f344eeba5f977ea34
  https://github.com/groonga/groonga/commit/96af9c36cc42280dd17f9a6f344eeba5f977ea34

  Log:
    Fix broken geo sort

  Added files:
    test/command/suite/select/sort/geo/distance/with_condition.expected
    test/command/suite/select/sort/geo/distance/with_condition.test
    test/command/suite/select/sort/geo/distance/without_condition.expected
    test/command/suite/select/sort/geo/distance/without_condition.test
  Modified files:
    lib/geo.c

  Modified: lib/geo.c (+29 -2)
===================================================================
--- lib/geo.c    2013-01-22 15:19:37 +0900 (ba18e75)
+++ lib/geo.c    2013-01-22 15:22:31 +0900 (2828c76)
@@ -567,13 +567,40 @@ grn_geo_table_sort_collect_points(grn_ctx *ctx, grn_obj *table, grn_obj *index,
   return n_entries;
 }
 
+static inline grn_obj *
+find_geo_sort_index(grn_ctx *ctx, grn_obj *key)
+{
+  grn_obj *index = NULL;
+
+  if (GRN_ACCESSORP(key)) {
+    grn_accessor *accessor = (grn_accessor *)key;
+    if (accessor->action != GRN_ACCESSOR_GET_KEY) {
+      return NULL;
+    }
+    if (!(DB_OBJ(accessor->obj)->id & GRN_OBJ_TMP_OBJECT)) {
+      return NULL;
+    }
+    if (accessor->obj->header.type != GRN_TABLE_HASH_KEY) {
+      return NULL;
+    }
+    if (!accessor->next) {
+      return NULL;
+    }
+    grn_column_index(ctx, accessor->next->obj, GRN_OP_LESS, &index, 1, NULL);
+  } else {
+    grn_column_index(ctx, key, GRN_OP_LESS, &index, 1, NULL);
+  }
+
+  return index;
+}
+
 int
 grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
                    grn_obj *result, grn_table_sort_key *keys, int n_keys)
 {
   grn_obj *index;
-  int i = 0, e = offset + limit, sid, accessorp = GRN_ACCESSORP(keys->key);
-  if (n_keys == 2 && grn_column_index(ctx, keys->key, GRN_OP_LESS, &index, 1, &sid)) {
+  int i = 0, e = offset + limit, accessorp = GRN_ACCESSORP(keys->key);
+  if (n_keys == 2 && (index = find_geo_sort_index(ctx, keys->key))) {
     grn_id tid;
     grn_obj *arg = keys[1].key;
     grn_pat *pat = (grn_pat *)grn_ctx_at(ctx, index->header.domain);

  Added: test/command/suite/select/sort/geo/distance/with_condition.expected (+53 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/sort/geo/distance/with_condition.expected    2013-01-22 15:22:31 +0900 (33e374c)
@@ -0,0 +1,53 @@
+select Shops   --sortby 'geo_distance(location, "35.67487x139.76352")'   --output_columns 'name, _score'   --filter 'geo_in_circle(location, "35.67487x139.76352", 3000)'   --scorer '_score=geo_distance(location, "35.67487x139.76352")'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        7
+      ],
+      [
+        [
+          "name",
+          "ShortText"
+        ],
+        [
+          "_score",
+          "Int32"
+        ]
+      ],
+      [
+        "銀座 かずや",
+        280
+      ],
+      [
+        "たい焼き鉄次 大丸東京店",
+        810
+      ],
+      [
+        "たいやき神田達磨 八重洲店",
+        970
+      ],
+      [
+        "にしみや 甘味処",
+        1056
+      ],
+      [
+        "築地 さのきや",
+        1186
+      ],
+      [
+        "しげ田",
+        1530
+      ],
+      [
+        "柳屋 たい焼き",
+        2179
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/sort/geo/distance/with_condition.test (+8 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/sort/geo/distance/with_condition.test    2013-01-22 15:22:31 +0900 (f060a3a)
@@ -0,0 +1,8 @@
+#@include fixture/geo/taiyaki/init.grn
+
+select Shops \
+  --sortby 'geo_distance(location, "35.67487x139.76352")' \
+  --output_columns 'name, _score' \
+  --filter 'geo_in_circle(location, "35.67487x139.76352", 3000)' \
+  --scorer '_score=geo_distance(location, "35.67487x139.76352")'
+

  Added: test/command/suite/select/sort/geo/distance/without_condition.expected (+51 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/sort/geo/distance/without_condition.expected    2013-01-22 15:22:31 +0900 (8694e50)
@@ -0,0 +1,51 @@
+select Shops   --sortby 'geo_distance(location, "35.67487x139.76352")'   --output_columns 'name'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        36
+      ],
+      [
+        [
+          "name",
+          "ShortText"
+        ]
+      ],
+      [
+        "銀座 かずや"
+      ],
+      [
+        "たい焼き鉄次 大丸東京店"
+      ],
+      [
+        "たいやき神田達磨 八重洲店"
+      ],
+      [
+        "にしみや 甘味処"
+      ],
+      [
+        "築地 さのきや"
+      ],
+      [
+        "しげ田"
+      ],
+      [
+        "柳屋 たい焼き"
+      ],
+      [
+        "松島屋"
+      ],
+      [
+        "尾長屋 錦糸町店"
+      ],
+      [
+        "根津のたいやき"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/sort/geo/distance/without_condition.test (+6 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/sort/geo/distance/without_condition.test    2013-01-22 15:22:31 +0900 (5b708e1)
@@ -0,0 +1,6 @@
+#@include fixture/geo/taiyaki/init.grn
+
+select Shops \
+  --sortby 'geo_distance(location, "35.67487x139.76352")' \
+  --output_columns 'name'
+
-------------- next part --------------
HTML����������������������������...
Download 



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