From a31443f3f928b569e69eeb4217cefcbe27d28a8e Mon Sep 17 00:00:00 2001 From: Martin Aceto Date: Mon, 22 Jul 2024 19:42:47 -0400 Subject: [PATCH] implementing FieldFilter for lighthouse endpoint --- functions/lighthouse/libs/queries.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/functions/lighthouse/libs/queries.py b/functions/lighthouse/libs/queries.py index 5bd7c96..fee3cc4 100644 --- a/functions/lighthouse/libs/queries.py +++ b/functions/lighthouse/libs/queries.py @@ -1,10 +1,11 @@ import os -import json from google.cloud import firestore +from google.cloud.firestore_v1.base_query import FieldFilter from .result import Result from .utils import convert_to_array DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE')) +TABLE = 'lighthouse' def list_data(params): @@ -12,16 +13,16 @@ def list_data(params): data = [] for technology in technology_array: - query = DB.collection(u'lighthouse') + query = DB.collection(TABLE) if 'start' in params: - query = query.where('date', '>=', params['start']) + query = query.where(filter=FieldFilter('date', '>=', params['start'])) if 'end' in params: - query = query.where('date', '<=', params['end']) + query = query.where(filter=FieldFilter('date', '<=', params['end'])) - query = query.where('geo', '==', params['geo']) - query = query.where('rank', '==', params['rank']) - query = query.where('technology', '==', technology) + query = query.where(filter=FieldFilter('geo', '==', params['geo'])) + query = query.where(filter=FieldFilter('rank', '==', params['rank'])) + query = query.where(filter=FieldFilter('technology', '==', technology)) documents = query.stream()