Skip to content

Commit

Permalink
Merge cfe71f1 into d524789
Browse files Browse the repository at this point in the history
  • Loading branch information
spoxies committed Jan 18, 2019
2 parents d524789 + cfe71f1 commit 2317135
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/GeoQuery.ts
Expand Up @@ -14,6 +14,7 @@ export class GeoQuery {
private _limit: number;
private _radius: number;
private _isWeb: boolean;
private _ineq = false;

/**
* @param _query The `Query` instance.
Expand Down Expand Up @@ -92,7 +93,7 @@ export class GeoQuery {
* Creates and returns a new GeoQuery that's additionally limited to only return up to the specified number of documents.
*
* This function returns a new (immutable) instance of the GeoQuery (rather than modify the existing instance) to impose the limit.
*
*
* Note: Limits on geoqueries are applied based on the distance from the center. Geoqueries require an aggregation of queries.
* When performing a geoquery the library applies the limit on the client. This may mean you are loading to the client more documents
* then you intended. Use with this performance limitation in mind.
Expand Down Expand Up @@ -139,6 +140,9 @@ export class GeoQuery {
opStr: GeoFirestoreTypes.WhereFilterOp,
value: any
): GeoQuery {
// True if inequality filter is used
this._ineq = (opStr !== '==' && opStr !== 'array-contains') ? true : this._ineq;
// Return GeoQuery
return new GeoQuery(this._query.where((fieldPath ? ('d.' + fieldPath) : fieldPath), opStr, value), this._queryCriteria);
}

Expand All @@ -157,7 +161,10 @@ export class GeoQuery {
// decode the geohash query string
const query: string[] = this._stringToQuery(toQueryStr);
// Create the Firebase query
return this._query.where('g', '>=', query[0]).where('g', '<=', query[1]) as GeoFirestoreTypes.web.Query;
if(!this._ineq){
return this._query.where('g', '>=', query[0]).where('g', '<=', query[1]) as GeoFirestoreTypes.web.Query;
}
return this._query.orderBy('g').startAt(query[0]).endAt(query[1]) as GeoFirestoreTypes.web.Query;
});
}

Expand Down
15 changes: 15 additions & 0 deletions test/GeoQuery.test.ts
Expand Up @@ -443,6 +443,21 @@ describe('GeoQuery Tests:', () => {
});
});

describe('near().where():', () => {
it('near().where() does not throw an error with valid arguments', () => {
const query = new GeoQuery(collection);
expect(() => query.near({ center: new firebase.firestore.GeoPoint(0, 0), radius: 100 })
.where('count', '==', 0)).not.to.throw();
expect(() => query.near({ center: new firebase.firestore.GeoPoint(1, 1) })
.where('count', '>', 0)).not.to.throw();
expect(() => query.near({ radius: 500 })
.where('count', '<=', 0)).not.to.throw();
expect(() => query.near({ radius: 500 })
.where('array', 'array-contains', 'one')).not.to.throw();
});
});


describe('_stringToQuery():', () => {
it('_stringToQuery() returns an array of two string elements', () => {
const query = new GeoQuery(collection);
Expand Down

0 comments on commit 2317135

Please sign in to comment.