Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Works with newly refactored fSphinx

  • Loading branch information...
commit d5c3a59e3080181822716ee9837b98635f8bea42 1 parent e6eb6c2
@alexksikes authored
View
5 TODO
@@ -18,6 +18,11 @@
[*] create repository
[*] search logs
>> use data/sph_logs/query.log
+[ ] release fsphinx
+[ ] promote sGeo
+ >> http://groups.google.com/group/geonames/topics
+ >> http://forum.geonames.org/gforum/recentTopics/list.page
+ >> Sphinx
[ ] implement get_locations_batch
>> fpshinx must implement add_query instead
[ ] mispellings (use soundex stemmer and/or aspell)
View
5 sgeo/config/geocoders/geonames.py
@@ -4,7 +4,7 @@
from sgeo.config import db
# create sphinx client
-cl = fsphinx.SphinxClientSQL()
+cl = fsphinx.FSphinxClient()
# connect to searchd
cl.SetServer('localhost', 9312)
@@ -19,7 +19,7 @@
cl.SetFieldWeights(dict(place=3))
## sql query to fetch the hits
-cl.SetSQLQuery(db, '''
+db_fetch = fsphinx.DBFetch(db, sql = '''
select
g.id,
"geonames" as source_db,
@@ -51,6 +51,7 @@
where id in ($id)
order by field(id, $id)'''
)
+cl.AttachDBFetch(db_fetch)
# by default only this index will be queried
cl.SetDefaultIndex('geonames')
View
10 sgeo/config/geocoders/geonames_P_US.py
@@ -4,7 +4,7 @@
from sgeo.config import db
# create sphinx client
-cl = fsphinx.SphinxClientSQL()
+cl = fsphinx.FSphinxClient()
# connect to searchd
cl.SetServer('localhost', 9312)
@@ -15,11 +15,8 @@
# sorting and possible custom sorting function
cl.SetSortMode(sphinxapi.SPH_SORT_EXPR, '@weight * population')
-# some fields could matter more than others
-cl.SetFieldWeights(dict(place=4))
-
-## sql query to fetch the hits
-cl.SetSQLQuery(db, '''
+# sql query to fetch the hits
+db_fetch = fsphinx.DBFetch(db, sql = '''
select
g.id,
"geonames" as source_db,
@@ -49,6 +46,7 @@
where id in ($id)
order by field(id, $id)'''
)
+cl.AttachDBFetch(db_fetch)
# by default only this index will be queried
cl.SetDefaultIndex('geonames_P_US')
View
5 sgeo/config/geocoders/geonames_postals.py
@@ -4,7 +4,7 @@
from sgeo.config import db
# create sphinx client
-cl = fsphinx.SphinxClientSQL()
+cl = fsphinx.FSphinxClient()
# connect to searchd
cl.SetServer('localhost', 9312)
@@ -19,7 +19,7 @@
cl.SetFieldWeights(dict(postal_code=40))
# sql query to fetch the hits
-cl.SetSQLQuery(db, '''
+db_fetch = fsphinx.DBFetch(db, sql = '''
select
id,
"geonames.postals" as source_db,
@@ -38,6 +38,7 @@
where id in ($id)
order by field(id, $id)'''
)
+cl.AttachDBFetch(db_fetch)
# by default only this index will be queried
cl.SetDefaultIndex('geonames_postals')
View
5 sgeo/config/geocoders/zipcodes_US.py
@@ -4,7 +4,7 @@
from sgeo.config import db
# create sphinx client
-cl = fsphinx.SphinxClientSQL()
+cl = fsphinx.FSphinxClient()
# connect to searchd
cl.SetServer('localhost', 9312)
@@ -16,7 +16,7 @@
cl.SetSortMode(sphinxapi.SPH_SORT_EXTENDED, '@relevance desc')
## sql query to fetch the hits
-cl.SetSQLQuery(db, '''
+db_fetch = fsphinx.DBFetch(db, sql = '''
select
id,
"zipcodesdotcom" as source_db,
@@ -32,6 +32,7 @@
where id in ($id)
order by field(id, $id)'''
)
+cl.AttachDBFetch(db_fetch)
# by default only this index will be queried
cl.SetDefaultIndex('zipcodes_US')
View
5 sgeo/config/nearby_places.py
@@ -4,7 +4,7 @@
from sgeo.config import db
# create sphinx client
-cl = fsphinx.SphinxClientSQL()
+cl = fsphinx.FSphinxClient()
# connect to searchd
cl.SetServer('localhost', 9312)
@@ -16,7 +16,7 @@
cl.SetSortMode(sphinxapi.SPH_SORT_EXTENDED, '@geodist asc')
## sql query to fetch the hits
-cl.SetSQLQuery(db, '''
+db_fetch = fsphinx.DBFetch(db, sql = '''
select
g.id,
g.name as place,
@@ -45,6 +45,7 @@
where id in ($id)
order by field(id, $id)'''
)
+cl.AttachDBFetch(db_fetch)
# by default only this index will be queried
cl.SetDefaultIndex('geonames')
View
24 sgeo/geo.py
@@ -1,3 +1,5 @@
+# should probably be renamed sgeo.py and remove __init__.py
+
import fsphinx
import math
import new
@@ -25,7 +27,7 @@
class GeoCoder(object):
def __init__(self, listen='', usa_only=False):
def make_client(config):
- return fsphinx.make_client_from_config(config)
+ return fsphinx.FSphinxClient.FromConfig(config)
if usa_only:
self.cl_place = make_client(geonames_P_US)
self.cl_zip = make_client(zipcodes_US)
@@ -66,8 +68,8 @@ def get_hits(self):
def get_hits_from_ip(self, ip):
coords = get_coords_from_ip(ip)
if coords:
- return fsphinx.Hits(dict(total=1, total_found=1,
- matches=[{'@hit':coords, 'id':0, 'weight':0, 'attrs':{}}]))
+ return web.storage(total=1, total_found=1, time=0,
+ matches=[{'@hit':coords, 'id':0, 'weight':0, 'attrs':{}}])
else:
return fsphinx.Hits()
@@ -82,25 +84,11 @@ def set_location(cl, lat, lon, radius=RADIUS, exclude=False):
cl.SetFilterFloatRange('@geodist', 0.0, 0.0, exclude=True)
def get_nearby_places(lat, lon, query, radius=RADIUS, exclude=False, offset=0, limit=10):
- cl = fsphinx.make_client_from_config(nearby_places)
+ cl = fsphinx.FSphinxClient.FromConfig(nearby_places)
cl.SetLimits(offset, limit)
set_location(cl, lat, lon, radius, exclude)
return cl.Query(query)
-#class GeoQuery(fsphinx.ParsedQuery):
-# _reserved = ['address', 'lat', 'lon']
-#
-# def __init__(self, query):
-# fsphinx.ParsedQuery.__init__(self, query)
-# self.address = self.get_term('address')
-# self.lat = float(self.get_term('lat', 0))
-# self.lon = float(self.get_term('lon', 0))
-#
-# @property
-# def sphinx_query(self):
-# s = [q.sphinx_query for q in self if q.field not in GeoQuery._reserved]
-# return ' '.join(s).strip()
-
def is_zip_code(zip):
m = re.search('\s*(\d{5}(?:[\-]\d{4})?)\s*', zip, re.I)
if m:
View
1  sgeo/sg_cli.py
@@ -25,7 +25,6 @@
def run(place, listen='', usa=False, limit=1, nearby=0):
gc = sgeo.GeoCoder(listen=listen, usa_only=usa)
center = gc.get_locations(place, limit=limit)
- print center
hits = gc.get_hits()
print 'Found the following locations:'
Please sign in to comment.
Something went wrong with that request. Please try again.