firebase / firebase/geofire-js

Feature Suggestion: Multiple Query Criteria with Compound Keys

Open
#118 3 comments 0 reactions 0 assignees View on GitHub
type: feature request
Dominant language
TypeScript
Stars
1.4k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

Hi all,
I've seen a couple questions around the web asking about writing queries with multiple criteria, rather than just location-based queries. For example, maybe I want all users that are within 15 miles AND are in college AND are male AND are under 20. I know there's no built-in way to do this, but I suggested a workaround [here](http://stackoverflow.com/questions/34347571/filtering-results-with-geofire-firebase/#39108927).

If that seems like a reasonable workaround, maybe it would be a nice addition to the library? You could use an obscure unicode character as the delimiter, and do something like:

```
geoFire
.compoundKey('my/geofire/ref')
.addKey('user_key')
.addKey('in_college')
.addKey('gender')
.addKey('age');
.setLocation('whatever')

```

Then, once retrieved from the query, you could do

geoFireKey.split(), which would return something like

```
{
user_key: 1234567890,
in_college: true,
gender: female,
age: 19
}
```

Maybe it could even have a filtering function that you set,

```
geoQuery.setFilterFunction(function(compoundKey) {
if (compoundKey.in_college === true &&
compoundKey.gender === 'female' &&
compoundKey.age === 19) {
return true;
}
return false;
})
```

Thoughts?

Contributor guide

Open the contributing guide

Research direction

Start with README.md, docs/reference.md, and examples/README.md to understand the current location-query API, then review the linked Stack Overflow workaround. The issue needs decisions about compound-key encoding, filtering semantics, and edge cases before implementation; done should include a defined API and documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.