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

vgrange/convenient_switch_to_show_autocomplete_score #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions labonneboite/common/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
FILTERS = ['naf', 'headcount', 'flag_alternance', 'distance']
DISTANCE_FILTER_MAX = 3000

# easy on/off switch to display scores directly in autocomplete - never commit a True value!
SHOW_AUTOCOMPLETE_SCORE = False


class Fetcher(object):
Expand Down Expand Up @@ -787,21 +789,24 @@ def build_location_suggestions(term):
res = es.search(index=settings.ES_INDEX, doc_type="location", body=body)

suggestions = []
first_score = None

for hit in res['hits']['hits']:
if not first_score:
first_score = hit['_score']
source = hit['_source']
if source['zipcode']: # and hit['_score'] > 0.1 * first_score:
if source['zipcode']:
city_name = source['city_name'].replace('"', '')
label = u'%s (%s)' % (city_name, source['zipcode'])
score = round(hit['_score'], 1)

if SHOW_AUTOCOMPLETE_SCORE:
label = "[score=%s] %s" % (score, label)

city = {
'city': source['slug'],
'zipcode': source['zipcode'],
'label': label,
'latitude': source['location']['lat'],
'longitude': source['location']['lon'],
'score': score,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a besoin de ça ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

effectivement non, je vais dégager la partie autocomplete geo, qui de toute façon n'est plus utilisée sur le frontend LBB

}
suggestions.append(city)
return suggestions
Expand Down Expand Up @@ -878,6 +883,10 @@ def build_job_label_suggestions(term, size=autocomplete.MAX_JOBS):
label = "%s (%s, ...)" % (rome_description, ogr_description)
value = "%s (%s, ...)" % (source["rome_description"], source["ogr_description"])
score = round(hit['_score'], 1)

if SHOW_AUTOCOMPLETE_SCORE:
label = "[score=%s] %s" % (score, label)

suggestions.append({
'id': source['rome_code'],
'label': label,
Expand Down