If I have a database full of vehicles with information such as price, make, model, year, mileage, color, style, transmission, etc how do I structure my data so a user could filter through all of the data?
Note that I would prefer that the user can filter on a range of values, for example, on price where you want the price to be between $3000 to $6000. Is there a good way to do this? I assume you might be able to duplicate your data or hash the data somehow to be able to create a value you could search for but I'm not sure how to approach that kind of thing.
How much of this can be done server-side vs client-side? I'm at a loss.
For example, right now, you can only order by one key. Let's say my data structure is simply the list of cars and their keys and values.
cars {
"someLongId": {
price: 5000,
make: "Honda",
model: "Accord",
year: 1996,
mileage: 154000,
color: "blue",
transmission: "standard"
},
}
The problem is that this structure only supports filtering on one key. I would need to duplicate this data in the following way in order to allow a user to receive all of the blue Hondas in the database:
carsByColor: {
"blue": {
"someLongId": {
price: 5000,
make: "Honda",
model: "Accord",
year: 1996,
mileage: 154000,
color: "blue",
transmission: "standard"
}
}
}
They would then receive the blue Hondas like this:
var ref = firebase.database().ref('carsByColor/blue');
ref.orderByChild('make').equalTo('Honda').on('child_added', data => {
// do something with data
});
What I want to know is, how would I structure my data if I wanted something like 8 different filters as stated in the beginning of the question. Is it a good idea to duplicate the data to a point where it may exist in 100+ places just so I can find all of the blue 1996 Honda Accord's that cost between $3000-$6000 and have a mileage lower than 180,000?
My understanding is that I would need to have different paths for EVERYTHING and all of my car data would be duplicated. So I would have a path called "carsByColor/blue/Honda/Accord/1996" but also for 1997, 1998, etc. However, I would also have to do this over for any other model of Honda as well. It seems like a lot of work just to get basic filtering. It's that or I do all of the searching on the server/client.