I am struggling to find good material on best practices for filtering data using firebase firestore, angularfire5 and angular 5. I am building a map based web app, similar to a real estate app. And I have pins on the map that need to be filtered by different attributes. Do you know of any good articles I can read? Or how this should be best approached.
Some questions that come to mind are:
- Client side filtering vs query based filtering?
- What is a good way to store data in firestore that assists with filtering?
Example object data:
{
"key": {
"suburb": "Chelsea",
"lng": 90,
"lat": -90,
"street": "Lennox",
"streetNo": 200,
"lotSize": 600,
"city": "langdon",
"attributeKeys": [
{
"key1": true,
"key2": true,
"key3": true,
"key4": false,
"key5": false
}
]
}
}
Let's assume the following filter scenario: All map items in chelsea, lot size greater than 400, where key1 = true and key2 = true.
Below is an example of my current service:
this.mapItems = Observable.combineLatest(
this.suburb,
this.minLotSize,
this.maxLotSize,
this.attrbute1Filter,
).switchMap(([suburb, minLotSize, maxLotSize, attrbute1Filter]) =>
afs.collection('properties', ref => {
let query: any = ref;
if (suburb) { query = query.where('address.suburb', '==', suburb) };
if (minLotSize) { query = query.where('attributes.lotArea', '>=', minLotSize) };
if (maxLotSize) { query = query.where('attributes.lotArea', '<=', maxLotSize) };
if (attrbute1Filter) { query = query.where('attributeKeys.key1', '==', subdivisionFilter) }
return query;
})
.valueChanges()
);
Thanks for your help.