I'm in the process of developing a Firestore project that includes group chats and forums where users can filter posts based on various criteria:
- Number of likes
- Presence of attachments (photos and/or files)
- 4 Tags (Questions, Exams, Assignments, Notes)
Users have the flexibility to apply any combination of these filters simultaneously.
Each Post document is equipped with the following attributes:
- Number of Clips
- A boolean value for each tag
- A list of files attached to the post
- The actual text content of the post
This is how I've been structuring my query creation method:
setQueryFilters() {
var queryPosts = db.collection('posts').where('course_id', '==', this.course);
if (this.filterByNotes) {
queryPosts = queryPosts.where('notesTag', '==', true);
}
if (this.filterByExams) {
queryPosts = queryPosts.where('examsTag', '==', true);
}
if (this.filterByAssignments) {
queryPosts = queryPosts.where('assignmentsTag', '==', true);
}
if (this.filterByQuestions) {
queryPosts = queryPosts.where('questionsTag', '==', true);
}
if (this.filterByFiles) {
queryPosts = queryPosts.where('files', '!=', []);
}
if (this.filterByClips) {
queryPosts = queryPosts.orderBy('clips', 'desc');
} else {
queryPosts = queryPosts.orderBy('created_at', 'desc');
}
return queryPosts;
},
With a total of 6 different filters to consider, there are potentially numerous unique queries I could generate. However, many of them require me to create compound indexes in firebase. The sheer volume of potential indexes makes me question if firebase can support them all. Is there perhaps a more efficient approach to tackle this issue?