From 8b9a8689fc16f4957f4a2545a27302ab105b7e99 Mon Sep 17 00:00:00 2001 From: Alex Hoyau Date: Tue, 5 Oct 2021 14:10:12 +0200 Subject: [PATCH 1/2] show only companies with a score>80 --- labonneboite/common/search.py | 32 +++++++++++++++------ labonneboite/conf/common/settings_common.py | 4 +++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/labonneboite/common/search.py b/labonneboite/common/search.py index 73c441bb3..925169357 100644 --- a/labonneboite/common/search.py +++ b/labonneboite/common/search.py @@ -60,6 +60,7 @@ def __init__( sort=None, hiring_type=None, from_number=1, + # FIXME: the variable to_number is useless, remove it and use OFFICES_PER_PAGE where needed to_number=OFFICES_PER_PAGE, audience=None, headcount=None, @@ -270,7 +271,7 @@ def get_offices(self, add_suggestions=False): result = {} aggregations = {} if self.office_count: - result, _, aggregations = fetch_offices( + result, new_count, aggregations = fetch_offices( self.naf_codes, self.romes, self.latitude, @@ -290,6 +291,7 @@ def get_offices(self, add_suggestions=False): flag_pmsmp=self.flag_pmsmp, aggregate_by=self.aggregate_by, ) + self.office_count = new_count if self.office_count <= current_page_size and add_suggestions: @@ -351,6 +353,8 @@ def fetch_offices(naf_codes, rome_codes, latitude, longitude, distance, aggregat sort=sort, rome_codes=rome_codes, hiring_type=kwargs['hiring_type'], + from_number=kwargs.get('from_number', None), + to_number=kwargs.get('to_number', None), ) # Extract aggregations @@ -722,20 +726,24 @@ def build_json_body_elastic_search( } # Process from_number and to_number. + # if from_number: + # json_body["from"] = from_number - 1 + # if to_number: + # if to_number < from_number: + # # this should never happen + # logger.exception("to_number < from_number : %s < %s", to_number, from_number) + # raise Exception("to_number < from_number") + # json_body["size"] = to_number - from_number + 1 + + # Prevent default page size in ES if from_number: - json_body["from"] = from_number - 1 - if to_number: - if to_number < from_number: - # this should never happen - logger.exception("to_number < from_number : %s < %s", to_number, from_number) - raise Exception("to_number < from_number") - json_body["size"] = to_number - from_number + 1 + json_body["size"] = 1000 return json_body -def get_offices_from_es_and_db(json_body, sort, rome_codes, hiring_type): +def get_offices_from_es_and_db(json_body, sort, rome_codes, hiring_type, from_number=None, to_number=None): """ Fetch offices first from Elasticsearch, then from the database. @@ -848,6 +856,12 @@ def get_offices_from_es_and_db(json_body, sort, rome_codes, hiring_type): # Set contact mode and position office.contact_mode = util.get_contact_mode_for_rome_and_office(rome_code_for_contact_mode, office) + # Filter results + offices = list(filter(lambda office: office.score>settings.OFFICE_SCORE_THRESHOLD, offices)) + office_count = len(offices) + if from_number and to_number: + offices = offices[from_number:to_number+1] + try: aggregations = res['aggregations'] except KeyError: diff --git a/labonneboite/conf/common/settings_common.py b/labonneboite/conf/common/settings_common.py index 5629da290..a425bb4b2 100644 --- a/labonneboite/conf/common/settings_common.py +++ b/labonneboite/conf/common/settings_common.py @@ -70,6 +70,10 @@ SCORE_80_HIRINGS = 100.0 SCORE_100_HIRINGS = 500.0 +# Filter offices with these values +# Filter is applied in labonneboite.common.search.HiddenMarketFetcher +OFFICE_SCORE_THRESHOLD=80 + # API keys used to sign requests and check that a user is authorised to use the API # Note for API proxies such as ESD: they have api keys and need to sign the requests with it # So an api key is chosen according to the GET param `user` **not** `origin_user` From d8f3b4854298222c75f2dd00ed50c22acfc4aa66 Mon Sep 17 00:00:00 2001 From: Alex Hoyau Date: Thu, 7 Oct 2021 10:10:42 +0200 Subject: [PATCH 2/2] show only companies with a score>60 --- labonneboite/conf/common/settings_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labonneboite/conf/common/settings_common.py b/labonneboite/conf/common/settings_common.py index a425bb4b2..bd3e73b8d 100644 --- a/labonneboite/conf/common/settings_common.py +++ b/labonneboite/conf/common/settings_common.py @@ -72,7 +72,7 @@ # Filter offices with these values # Filter is applied in labonneboite.common.search.HiddenMarketFetcher -OFFICE_SCORE_THRESHOLD=80 +OFFICE_SCORE_THRESHOLD=60 # API keys used to sign requests and check that a user is authorised to use the API # Note for API proxies such as ESD: they have api keys and need to sign the requests with it