Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

show only companies with a score>80 #597

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions labonneboite/common/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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:

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions labonneboite/conf/common/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=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
# So an api key is chosen according to the GET param `user` **not** `origin_user`
Expand Down