Ejemplo n.º 1
0
import web
import fsphinx

from fsphinx import FSphinxClient, Facet, DBFetch, MultiFieldQuery, QueryParser, hits

# connect to database
db = web.database(dbn='mysql', db='medline_sample', user='******', passwd='fsphinx')

# turn db printing off
db.printing = False

# make sure we don't chop off
db.query('set group_concat_max_len = 5000')

# create sphinx client
cl = FSphinxClient()

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

# we don't accept queries which take longer than 2 sec.
cl.SetConnectTimeout(20.0)

# provide search cache
cl.AttachCache(fsphinx.RedisCache(db=2))

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

# sorting and possible custom sorting function
# use natural order of document ids (see optimization)
Ejemplo n.º 2
0
from fsphinx import FSphinxClient, Facet, DBFetch, MultiFieldQuery, QueryParser, hits

# database parameters
db = web.database(dbn='mysql', db='imdb_sample', user='******', passwd='fsphinx')

# redis cache pparameters
redis_cache = fsphinx.RedisCache(db=1)

# show output of mysql statements
db.printing = False

# make sure multi value fields are not chopped off
db.query('set group_concat_max_len = 50000')

# create sphinx client
cl = FSphinxClient()

# connect to searchd
cl.SetServer('http://0.0.0.0', 10001)

# we don't accept queries which take longer than 2 sec.
#cl.SetConnectTimeout(2.0)

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

# specify different sorting options
cl.SetSortModeOptions({
    'pop' : (sphinxapi.SPH_SORT_EXPR, '@weight * user_rating_attr * nb_votes_attr * year_attr / 100000'),
    'dat' : (sphinxapi.SPH_SORT_EXTENDED, 'year_attr desc'),
    'rat' : (sphinxapi.SPH_SORT_EXTENDED, 'user_rating_attr desc'),
Ejemplo n.º 3
0
import sphinxapi
import web

from fsphinx import FSphinxClient, Facet, DBFetch, MultiFieldQuery

# connect to database
# IMPORTANT: note that this will re-create a connection each time
# Better import db using from ... import db
db = web.database(dbn='mysql', db='fsphinx', user='******', passwd='fsphinx')

# show output of mysql statements
db.printing = False

# create sphinx client
cl = FSphinxClient()

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

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

# sorting and possible custom sorting function
cl.SetSortMode(
    sphinxapi.SPH_SORT_EXPR,
    '@weight * user_rating_attr * nb_votes_attr * year_attr / 100000')

# some fields could matter more than others
cl.SetFieldWeights({'title': 30})

# sql query to fetch the hits
Ejemplo n.º 4
0
#!/usr/bin/env python
from fsphinx import FSphinxClient
from simsearch import SimClient
from cloudmining import CloudMiningApp

# create a FSphinxClient from the configuration file
cl = FSphinxClient.FromConfig('config/sphinx_client.py')

# create similarity search client
sim_cl = SimClient.FromConfig('config/simsearch_client.py')

# create a new CloudMining web application
app = CloudMiningApp(autoreload=True)

# set the fsphinx client of the webapp
app.set_fsphinx_client(cl)

# same for similarity search
app.set_sim_client(sim_cl)

# if cl has a search cache preload it
app.set_preload_cache_file('data/redis-cache.dat')

# some more options which can be set
app.set_debug(True)  # also web.config.debug
app.set_template_caching(False)  # also web.config.template_caching
app.set_flush_cache_on_startup(True)

# what sorting options are shown (key must match cl sort options)
app.set_ui_sort_by(dict(key='cit', description='number of citations'),
                   dict(key='rel', description='relevance'),
Ejemplo n.º 5
0
 def FromConfig(cls, path):
     """Creates a client from a config file.
     """
     return FSphinxClient.FromConfig(path)
import web

from fsphinx import FSphinxClient, Facet, DBFetch, SplitOnSep
from fsphinx import QueryParser, MultiFieldQuery, RedisCache

# connect to database
db = web.database(dbn='mysql', db='powertest', user='******', passwd='mobutu')

# let's have a cache for later use
cache = RedisCache(db=0)

# show output of mysql statements
db.printing = False

# create sphinx client
cl = FSphinxClient()

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

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

# sorting and possible custom sorting function
#cl.SetSortMode(sphinxapi.SPH_SORT_EXPR, '@weight * user_rating_attr * nb_votes_attr * year_attr / 100000')

# set the default index to search
cl.SetDefaultIndex('items')

# some fields could matter more than others
cl.SetFieldWeights({'alias' : 30})