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

Commit

Permalink
Merge pull request #117 from QwantResearch/optim-es
Browse files Browse the repository at this point in the history
Replace post filter with query filter in wiki and reverse ES queries
  • Loading branch information
amatissart authored Feb 10, 2020
2 parents 67cb0b9 + 7d80a38 commit e20ae4f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions idunn/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ def init_wiki_es(cls):
@classmethod
def get_wiki_info(cls, wikidata_id, wiki_index):
cls.init_wiki_es()

try:
with prometheus.wiki_request_duration("wiki_es", "get_wiki_info"):
resp = (
cls._wiki_es.search(
index=wiki_index, body={"filter": {"term": {"wikibase_item": wikidata_id}}}
index=wiki_index,
body={
"query": {"bool": {"filter": {"term": {"wikibase_item": wikidata_id}}}}
},
)
.get("hits", {})
.get("hits", [])
Expand All @@ -128,7 +130,6 @@ def get_wiki_info(cls, wikidata_id, wiki_index):
return None

wiki = resp[0]["_source"]

return wiki


Expand Down Expand Up @@ -238,7 +239,17 @@ def fetch_closest(lat, lon, max_distance, es):
body={
"query": {
"function_score": {
"query": {"match_all": {}},
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "{}m".format(max_distance),
"coord": {"lat": lat, "lon": lon},
"distance_type": "plane",
}
}
}
},
"boost_mode": "replace",
"functions": [
{
Expand All @@ -252,13 +263,6 @@ def fetch_closest(lat, lon, max_distance, es):
],
}
},
"filter": {
"geo_distance": {
"distance": "{}m".format(max_distance),
"coord": {"lat": lat, "lon": lon},
"distance_type": "plane",
}
},
"from": 0,
"size": 1,
},
Expand Down

0 comments on commit e20ae4f

Please sign in to comment.