Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 2 additions & 89 deletions src/geo_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,45 +100,6 @@ void LegacyGeoFilter_Free(LegacyGeoFilter *gf) {
GeoFilter_Free(&gf->base);
}

static t_docId *geoRangeLoad(const GeoIndex *gi, const GeoFilter *gf, size_t *num) {
*num = 0;
t_docId *docIds = NULL;
RedisModuleString *s = IndexSpec_GetFormattedKey(gi->ctx->spec, gi->sp, INDEXFLD_T_GEO);
RS_LOG_ASSERT(s, "failed to retrieve key");
/*GEORADIUS key longitude latitude radius m|km|ft|mi */
RedisModuleCtx *ctx = gi->ctx->redisCtx;
RedisModuleString *slon = RedisModule_CreateStringPrintf(ctx, "%f", gf->lon);
RedisModuleString *slat = RedisModule_CreateStringPrintf(ctx, "%f", gf->lat);
RedisModuleString *srad = RedisModule_CreateStringPrintf(ctx, "%f", gf->radius);
const char *unitstr = GeoDistance_ToString(gf->unitType);
RedisModuleCallReply *rep =
RedisModule_Call(ctx, "GEORADIUS", "ssssc", s, slon, slat, srad, unitstr);
if (rep == NULL || RedisModule_CallReplyType(rep) != REDISMODULE_REPLY_ARRAY) {
goto done;
}

size_t sz = RedisModule_CallReplyLength(rep);
docIds = rm_calloc(sz, sizeof(t_docId));
for (size_t i = 0; i < sz; i++) {
const char *s = RedisModule_CallReplyStringPtr(RedisModule_CallReplyArrayElement(rep, i), NULL);
if (!s) continue;

docIds[i] = (t_docId)atol(s);
}

*num = sz;

done:
RedisModule_FreeString(ctx, slon);
RedisModule_FreeString(ctx, slat);
RedisModule_FreeString(ctx, srad);
if (rep) {
RedisModule_FreeCallReply(rep);
}

return docIds;
}

QueryIterator *NewGeoRangeIterator(const RedisSearchCtx *ctx, const GeoFilter *gf, IteratorsConfig *config) {
// check input parameters are valid
if (gf->radius <= 0 ||
Expand All @@ -153,30 +114,18 @@ QueryIterator *NewGeoRangeIterator(const RedisSearchCtx *ctx, const GeoFilter *g

QueryIterator **iters = rm_calloc(GEO_RANGE_COUNT, sizeof(*iters));
((GeoFilter *)gf)->numericFilters = rm_calloc(GEO_RANGE_COUNT, sizeof(*gf->numericFilters));
size_t itersCount = 0;
FieldFilterContext filterCtx = {.field = {.isFieldMask = false, .value = {.index = gf->fieldSpec->index}}, .predicate = FIELD_EXPIRATION_DEFAULT};
for (size_t ii = 0; ii < GEO_RANGE_COUNT; ++ii) {
if (ranges[ii].min != ranges[ii].max) {
NumericFilter *filt = gf->numericFilters[ii] =
NewNumericFilter(ranges[ii].min, ranges[ii].max, 1, 1, true, NULL);
filt->fieldSpec = gf->fieldSpec;
filt->geoFilter = gf;
QueryIterator *numIter = NewNumericFilterIterator(ctx, filt, INDEXFLD_T_GEO, config, &filterCtx);
if (numIter != NULL) {
iters[itersCount++] = numIter;
}
iters[ii] = NewNumericFilterIterator(ctx, filt, INDEXFLD_T_GEO, config, &filterCtx);
}
}

if (itersCount == 0) {
rm_free(iters);
return NULL;
} else if (itersCount == 1) {
QueryIterator *it = iters[0];
rm_free(iters);
return it;
}
return NewUnionIterator(iters, itersCount, true, 1, QN_GEO, NULL, config);
return NewUnionIterator(iters, GEO_RANGE_COUNT, true, 1, QN_GEO, NULL, config);
}

GeoDistance GeoDistance_Parse(const char *s) {
Expand Down Expand Up @@ -286,21 +235,6 @@ static double extractUnitFactor(GeoDistance unit) {
return rv;
}

/**
* Populates the numeric range to search for within a given square direction
* specified by `dir`
*/
static int populateRange(const GeoFilter *gf, GeoHashRange *ranges) {
double xy[2] = {gf->lon, gf->lat};

double radius_meters = gf->radius * extractUnitFactor(gf->unitType);
if (radius_meters < 0) {
return -1;
}
calcRanges(gf->lon, gf->lat, radius_meters, ranges);
return 0;
}

/**
* Checks if the given coordinate d is within the radius gf
*/
Expand All @@ -311,24 +245,3 @@ int isWithinRadius(const GeoFilter *gf, double d, double *distance) {
int rv = isWithinRadiusLonLat(gf->lon, gf->lat, xy[0], xy[1], radius_meters, distance);
return rv;
}

static int checkResult(const GeoFilter *gf, const RSIndexResult *cur) {
double distance;
if (cur->type == RSResultType_Numeric) {
return isWithinRadius(gf, cur->data.num.value, &distance);
}

RSAggregateResultIter *iter = AggregateResult_Iter(&cur->data.agg);
RSIndexResult *child = NULL;

while (AggregateResultIter_Next(iter, &child)) {
if (checkResult(gf, child)) {
AggregateResultIter_Free(iter);
return 1;
}
}

AggregateResultIter_Free(iter);

return 0;
}
4 changes: 2 additions & 2 deletions src/iterators/union_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static void UI_Free(QueryIterator *base) {
* 2. If in quick exit mode and any of the iterators is a wildcard iterator, return it and free the rest
* 3. Otherwise, return NULL and let the caller create the union iterator
*/
static QueryIterator *UnionIteratorReducer(QueryIterator **its, int *num, bool quickExit, double weight, QueryNodeType type, const char *q_str, IteratorsConfig *config) {
static QueryIterator *UnionIteratorReducer(QueryIterator **its, int *num, bool quickExit) {
QueryIterator *ret = NULL;
// Let's remove all the empty iterators from the list
size_t current_size = *num;
Expand Down Expand Up @@ -488,7 +488,7 @@ static ValidateStatus UI_Revalidate(QueryIterator *base) {
QueryIterator *NewUnionIterator(QueryIterator **its, int num, bool quickExit,
double weight, QueryNodeType type, const char *q_str, IteratorsConfig *config) {

QueryIterator* ret = UnionIteratorReducer(its, &num, quickExit, weight, type, q_str, config);
QueryIterator* ret = UnionIteratorReducer(its, &num, quickExit);
if (ret != NULL) {
return ret;
}
Expand Down
7 changes: 1 addition & 6 deletions src/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ PRINT_PROFILE_FUNC(printUnionIt) {
char *unionTypeStr;
switch (ui->type) {
case QN_GEO : unionTypeStr = "GEO"; break;
case QN_GEOMETRY : unionTypeStr = "GEOSHAPE"; break;
case QN_TAG : unionTypeStr = "TAG"; break;
case QN_UNION : unionTypeStr = "UNION"; break;
case QN_FUZZY : unionTypeStr = "FUZZY"; break;
Expand Down Expand Up @@ -373,11 +372,7 @@ PRINT_PROFILE_FUNC(printIntersectIt) {

RedisModule_ReplyKV_Array(reply, "Child iterators");
for (int i = 0; i < ii->num_its; i++) {
if (ii->its[i]) {
printIteratorProfile(reply, ii->its[i], 0, 0, depth + 1, limited, config);
} else {
RedisModule_Reply_Null(reply);
}
printIteratorProfile(reply, ii->its[i], 0, 0, depth + 1, limited, config);
}
RedisModule_Reply_ArrayEnd(reply);

Expand Down
Loading