Navigation Menu

Skip to content

Commit

Permalink
Export grn_geo_table_sort()
Browse files Browse the repository at this point in the history
It's for Rroonga.
  • Loading branch information
kou committed Oct 6, 2015
1 parent 6fb1e1e commit f27fa66
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/groonga.h
Expand Up @@ -22,6 +22,7 @@
#include "groonga/groonga.h"
#include "groonga/obj.h"
#include "groonga/ii.h"
#include "groonga/geo.h"
#include "groonga/expr.h"
#include "groonga/output.h"
#include "groonga/util.h"
Expand Down
39 changes: 39 additions & 0 deletions include/groonga/geo.h
@@ -0,0 +1,39 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2015 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef GROONGA_GEO_H
#define GROONGA_GEO_H

#ifdef __cplusplus
extern "C" {
#endif

GRN_API int grn_geo_table_sort(grn_ctx *ctx,
grn_obj *table,
int offset,
int limit,
grn_obj *result,
grn_obj *column,
grn_obj *geo_point);

#ifdef __cplusplus
}
#endif

#endif /* GROONGA_GEO_H */
7 changes: 6 additions & 1 deletion lib/db.c
Expand Up @@ -11008,7 +11008,12 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
e = offset + limit;
}
if (keys->flags & GRN_TABLE_SORT_GEO) {
i = grn_geo_table_sort(ctx, table, offset, limit, result, keys, n_keys);
if (n_keys == 2) {
i = grn_geo_table_sort(ctx, table, offset, limit, result,
keys[0].key, keys[1].key);
} else {
i = 0;
}
goto exit;
}
if (n_keys == 1 && !GRN_ACCESSORP(keys->key) &&
Expand Down
12 changes: 6 additions & 6 deletions lib/geo.c
Expand Up @@ -686,18 +686,18 @@ grn_geo_table_sort_by_distance(grn_ctx *ctx,

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 *result, grn_obj *column, grn_obj *geo_point)
{
grn_obj *index;
int i = 0, e = offset + limit;
grn_bool accessorp = GRN_ACCESSORP(keys->key);
if (n_keys == 2 && (index = find_geo_sort_index(ctx, keys->key))) {
grn_bool accessorp = GRN_ACCESSORP(column);
if ((index = find_geo_sort_index(ctx, column))) {
grn_id tid;
grn_obj *arg = keys[1].key;
grn_pat *pat = (grn_pat *)grn_ctx_at(ctx, index->header.domain);
grn_id domain = pat->obj.header.domain;
grn_pat_cursor *pc = grn_pat_cursor_open(ctx, pat, NULL, 0,
GRN_BULK_HEAD(arg), GRN_BULK_VSIZE(arg),
GRN_BULK_HEAD(geo_point),
GRN_BULK_VSIZE(geo_point),
0, -1, GRN_CURSOR_PREFIX);
if (pc) {
if (domain != GRN_DB_TOKYO_GEO_POINT && domain != GRN_DB_WGS84_GEO_POINT) {
Expand All @@ -717,7 +717,7 @@ grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
}
}
} else {
grn_geo_point *base_point = (grn_geo_point *)GRN_BULK_HEAD(arg);
grn_geo_point *base_point = (grn_geo_point *)GRN_BULK_HEAD(geo_point);
i = grn_geo_table_sort_by_distance(ctx, table, index, pat,
pc, accessorp, base_point,
offset, limit, result);
Expand Down
3 changes: 0 additions & 3 deletions lib/grn_geo.h
Expand Up @@ -125,9 +125,6 @@ typedef struct {
grn_rc grn_geo_cursor_close(grn_ctx *ctx, grn_obj *geo_cursor);


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_rc grn_geo_resolve_approximate_type(grn_ctx *ctx, grn_obj *type_name,
grn_geo_approximate_type *type);

Expand Down

0 comments on commit f27fa66

Please sign in to comment.