Commit fab75f2b authored by Fize Jacques's avatar Fize Jacques
Browse files

Add _all query + modify n_label similar and n_alias_similar

parent f1e46889
......@@ -102,3 +102,5 @@ venv.bak/
# mypy
.mypy_cache/
.DS_Store
.idea
......@@ -28,8 +28,15 @@ class Geodict(Base):
sorted_by=self.score_field, sized=True,
size=n)
try:
return self.to_element(self.es_client.search("gazetteer", "place", query))
except :
res = self.to_element(self.es_client.search("gazetteer", "place", query))
if not len(res)>0:
query = self.qb.query(query_string=True,_all=True, regexp=True, regexp_value=".* ({0}) .*".format(label), field=lang,
value=label, sorted=score,
sorted_by=self.score_field, sized=True,
size=n)
res = self.to_element(self.es_client.search("gazetteer", "place", query))
return res
except Exception as e:
return []
def get_n_alias_similar(self, alias, lang, n, score=True):
......@@ -38,7 +45,13 @@ class Geodict(Base):
sorted_by=self.score_field, sized=True,
size=n)
try:
return self.to_element(self.es_client.search("gazetteer", "place", query))
res= self.to_element(self.es_client.search("gazetteer", "place", query))
if not len(res) >0:
query = self.qb.query(query_string=True, _all=True, nested=True, nested_field=lang, regexp=True,
regexp_value=".* ({0}) .*".format(alias), field="aliases", value=alias, sorted=score,
sorted_by=self.score_field, sized=True,
size=n)
return res
except :
return []
......
......@@ -19,7 +19,7 @@ class QueryBuilder():
query_string = kwargs.get("query_string", False)
nested = kwargs.get("nested", False)
match_all=kwargs.get("match_all",False)
_all =kwargs.get("_all",False)
#Value
value=kwargs.get("value","")
......@@ -69,12 +69,12 @@ class QueryBuilder():
if query_string:
body_query["query"]={"query_string":{"default_field":field,"query":value if not regexped else regexp_value}}
ff=(field if not _all else "_all")
body_query["query"]={"query_string":{"default_field":ff,"query":value if not regexped else regexp_value}}
elif term:
body_query["query"]={"term":{field:value}}
elif match_all:
body_query["query"] = {"match_all":{}}
body_query["query"]={"bool":{"must":[body_query["query"]]}}
if min_valued:
......
......@@ -7,7 +7,7 @@ from setuptools.command import install
setup(
name='gazpy',
version='0.1',
version='0.3',
packages=['gazpy', 'gazpy.query', 'gazpy.gazetteer'],
url='',
license='MIT',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment