Skip to content

Commit

Permalink
Fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
halolimat committed Oct 8, 2018
1 parent 5c38567 commit 8eef4e0
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions LNEx/osm_gazetteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import geo_calculations
import gaz_augmentation_and_filtering

import json

################################################################################
################################################################################

Expand Down Expand Up @@ -49,40 +51,43 @@ def search_index(bb):

if connection_string == '' or index_name == '':

print "\n###########################################################"
print "Global ERROR: Elastic host and port or index name not defined"
print "#############################################################\n"
print ("\n###########################################################")
print ("Global ERROR: Elastic host and port or index name not defined")
print ("#############################################################\n")
exit()

if not geo_calculations.is_bb_acceptable(bb) or bb[0] > bb[2] or bb[1] > bb[3]:

print "\n##########################################################"
print "Global ERROR: Bounding Box is too big, choose a smaller one!"
print "############################################################\n"
print ("\n##########################################################")
print ("Global ERROR: Bounding Box is too big, choose a smaller one!")
print ("############################################################\n")
exit()

connections.create_connection(hosts=[connection_string], timeout=60)

phrase_search = [Q({"filtered": {
"filter": {
"geo_bounding_box": {
"coordinate": {
"bottom_left": {
"lat": bb[0],
"lon": bb[1]
},
"top_right": {
"lat": bb[2],
"lon": bb[3]
}
}
}
},
"query": {
"match_all": {}
}
}
})]
query = { "bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_bounding_box": {
"coordinate": {
"bottom_left": {
"lat": bb[0],
"lon": bb[1]
},
"top_right": {
"lat": bb[2],
"lon": bb[3]
}
}
}
}
}
}


phrase_search = [Q(query)]

#to search with a scroll
e_search = Search(index=index_name).query(Q('bool', must=phrase_search))
Expand Down Expand Up @@ -198,7 +203,7 @@ def build_bb_gazetteer(bb, augment=True):
geo_locations[text]["meta"].append(str(_id))

except BaseException:
print extract_text(match[key])
print (extract_text(match[key]))
raise

if augment:
Expand Down Expand Up @@ -234,4 +239,4 @@ def build_bb_gazetteer(bb, augment=True):

geo_locations, geo_info, extended_words3 = build_bb_gazetteer(bb)

print geo_locations
print (json.dumps(dict(geo_locations), indent=2))

0 comments on commit 8eef4e0

Please sign in to comment.