# Path: cloudmining/app/models/items.py
# def get_sphinx_client(query):
# def search(query, offset=0, limit=10, sort_by='', user_pref={}):
# def compute_facet(query, fname, visu_type=''):
# def get_facets_from_cache(query, user_pref={}):
# def setup_user_pref(cl, user_pref):
# def is_sim_query(query, is_active=False):
# def to_sim_query(query):
# 
# Path: cloudmining/app/models/user_pref.py
# def get():
# def reset():
# def get_default(as_module=True):
# 
# Path: cloudmining/lib/paging.py
# def get_paging(start, max_results, query=False, results_per_page=15,
#     window_size=15, max_allowed_results=1000):


import web
import fsphinx
from cloudmining.app.models import items
from cloudmining.app.models import user_pref
from cloudmining.lib import paging
from cloudmining.app.helpers import templating
class search:
    def GET(self):
        i = web.input(previous_query='', query_inactive='', params='',
            search_mode='', q='', query='')
        # maintain compatibility with old urls
        query = i.q or i.query
        # searching in all results in current
        if i.search_mode == 'in_results':
            query = i.previous_query + ' ' + query
        else:
            query = i.query_inactive + ' ' + query
        # redirect to a pretty url
        url = fsphinx.QueryToPrettyUrl(query)
        raise web.redirect('/search/' + url + '?' + i.params)


class search_url:
    def GET(self, path):
        # get variables including the user preferences
        i = web.input(s=0, so='', ot='')
        start = int(i.s)
        pref = user_pref.get()
        # transform pretty url path into a query
        query = fsphinx.PrettyUrlToQuery(path, order=i.ot)
        # call model to search the items
        query, hits, facets = items.search(query, start, config.results_per_page, i.so, pref)
        # handle empty result set
        if not hits.total_found:
            facets = items.get_facets_from_cache('', pref)
        # create a pager to go through the results

# Path: cloudmining/app/models/items.py
# def get_sphinx_client(query):
# def search(query, offset=0, limit=10, sort_by='', user_pref={}):
# def compute_facet(query, fname, visu_type=''):
# def get_facets_from_cache(query, user_pref={}):
# def setup_user_pref(cl, user_pref):
# def is_sim_query(query, is_active=False):
# def to_sim_query(query):
# 
# Path: cloudmining/app/models/user_pref.py
# def get():
# def reset():
# def get_default(as_module=True):
# 
# Path: cloudmining/lib/paging.py
# def get_paging(start, max_results, query=False, results_per_page=15,
#     window_size=15, max_allowed_results=1000):


# Path: cloudmining/app/controllers/base.py
import web
import fsphinx
from cloudmining.app.models import items
from cloudmining.app.models import user_pref
from cloudmining.lib import paging
from cloudmining.app.helpers import templating

class search:
    def GET(self):
        i = web.input(previous_query='', query_inactive='', params='',
            search_mode='', q='', query='')
        # maintain compatibility with old urls
        query = i.q or i.query
        # searching in all results in current
        if i.search_mode == 'in_results':
            query = i.previous_query + ' ' + query
        else:
            query = i.query_inactive + ' ' + query
        # redirect to a pretty url
        url = fsphinx.QueryToPrettyUrl(query)
        raise web.redirect('/search/' + url + '?' + i.params)


class search_url:
    def GET(self, path):
        # get variables including the user preferences
        i = web.input(s=0, so='', ot='')
        start = int(i.s)
        pref = user_pref.get()
        # transform pretty url path into a query
        query = fsphinx.PrettyUrlToQuery(path, order=i.ot)
        # call model to search the items
        query, hits, facets = items.search(query, start, config.results_per_page, i.so, pref)
        # handle empty result set
        if not hits.total_found:
            facets = items.get_facets_from_cache('', pref)
        # create a pager to go through the results

        pager = paging.get_paging(start, hits['total_found'],