Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested fix(inequality filter) #80

Merged
merged 5 commits into from Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/GeoQuery.ts
Expand Up @@ -92,7 +92,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 +139,7 @@ export class GeoQuery {
opStr: GeoFirestoreTypes.WhereFilterOp,
value: any
): GeoQuery {
// Return GeoQuery
return new GeoQuery(this._query.where((fieldPath ? ('d.' + fieldPath) : fieldPath), opStr, value), this._queryCriteria);
}

Expand All @@ -157,7 +158,7 @@ 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;
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