Exemplo n.º 1
0
import fsphinx
import sphinxapi

from sgeo.config import db

# create sphinx client
cl = fsphinx.FSphinxClient()

# connect to searchd
cl.SetServer('localhost', 9312)

# matching mode (faceted client must be SPH_MATCH_EXTENDED2)
cl.SetMatchMode(sphinxapi.SPH_MATCH_EXTENDED2)

# 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=3))

## sql query to fetch the hits
db_fetch = fsphinx.DBFetch(db,
                           sql='''
select 
    g.id,
    "geonames" as source_db,
    g.name as place,
    g.ascii_name as place_ascii,
    g.alternate_names as place_alternate,
    a2.name as county,
    a2.name_ascii as county_ascii,
Exemplo n.º 2
0
# now let's see what is similar to "The Shawshank Redemption" (item id 111161)
results = handler.query(111161)
print results

# let's get detailed scores for the movie id 455275 and 107207
scores = handler.get_detailed_scores([455275, 107207], max_terms=5)
pprint(scores)

print 'Combining Full Text Search with Similarity Search'
print '-------------------------------------------------'

import fsphinx
import sphinxapi

# creating a sphinx client to handle full text search
cl = simsearch.SimClient(fsphinx.FSphinxClient(), handler, max_terms=5)

# assuming searchd is running on 10001
cl.SetServer('localhost', 10001)

# telling fsphinx how to fetch the results
db = fsphinx.utils.database(dbn='mysql', **db_params)

cl.AttachDBFetch(fsphinx.DBFetch(db, sql=''' 
    select imdb_id as id, title 
    from titles 
    where imdb_id in ($id) 
    order by field(imdb_id, $id)'''
))

# order the results solely by similarity using the log_score_attr