Skip to content

Commit

Permalink
Added sort mode options and GetFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
alexksikes committed Jan 19, 2012
1 parent c020a6f commit f7e3296
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fsphinx/facets.py
Expand Up @@ -336,6 +336,11 @@ def Preload(self, query):
self.Compute(query, caching=False)
self.cache.SetFacets(query, self.facets, replace=True, sticky=True)

def GetFacet(self, facet_name):
for f in self.facets:
if f.name == facet_name:
return f

def _ComputeCache(self, query, save_to_cache=True):
"""Set the cache in the given database.
Expand Down
2 changes: 2 additions & 0 deletions fsphinx/queries.py
Expand Up @@ -68,6 +68,8 @@ def sphinx(self):
"""The string representation of this query which should be sent to sphinx.
"""
s = utils.strips(' '.join(qt.sphinx for qt in self))
if s == '(@* "")':
s = ''
if not s and not self.ALLOW_EMPTY:
s = ' '
return s
Expand Down
17 changes: 17 additions & 0 deletions fsphinx/sphinx.py
Expand Up @@ -14,6 +14,10 @@
# NOTE: batch queries with AddQuery and RunQueries are not implemented.

class FSphinxClient(SphinxClient):
def __init__(self):
self.sort_mode_options = []
SphinxClient.__init__(self)

"""Creates a sphinx client but with all of fSphinx additional functionalities.
"""
def AttachQueryParser(self, query_parser=MultiFieldQuery):
Expand Down Expand Up @@ -79,6 +83,19 @@ def SetDefaultIndex(self, index):
"""
self.default_index = index

def SetSortModeOptions(self, options, reset=True):
if reset:
self.sort_mode_options = options
else:
self.sort_mode_options.update(options)

def SetSortMode(self, mode, clause=''):
if mode in self.sort_mode_options:
sort_mode = self.sort_mode_options[mode]
else:
sort_mode = (mode, clause)
SphinxClient.SetSortMode(self, *sort_mode)

@classmethod
def FromConfig(cls, path):
"""Creates a client from a config file.
Expand Down

0 comments on commit f7e3296

Please sign in to comment.