Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetSelect api command #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions djangosphinx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def __init__(self, model=None, using=None, **kwargs):
self._excludes = {}
self._extra = {}
self._query = ''
self._select = ''
self.__metadata = None
self._offset = 0
self._limit = 20
Expand Down Expand Up @@ -236,6 +237,14 @@ def __repr__(self):
else:
return '<%s instance>' % (self.__class__.__name__,)

def __getstate__(self):
dict = self.__dict__.copy()
if self._result_cache:
dict['_result_cache'] = None
dict['_metadata'] = {}
dict['_SphinxQuerySet__metadata'] = {}
return dict

def __len__(self):
return self.count()

Expand Down Expand Up @@ -326,6 +335,9 @@ def geoanchor(self, lat_attr, lng_attr, lat, lng):
assert sphinxapi.VER_COMMAND_SEARCH >= 0x113, "You must upgrade sphinxapi to version 0.98 to use Geo Anchoring."
return self._clone(_anchor=(lat_attr, lng_attr, float(lat), float(lng)))

def select(self, select_str):
return self._clone(_select=select_str)

# this actually does nothing, its just a passthru to
# keep things looking/working generally the same
def all(self):
Expand Down Expand Up @@ -406,6 +418,10 @@ def _clone(self, **kwargs):
c.__dict__.update(self.__dict__.copy())
for k, v in kwargs.iteritems():
setattr(c, k, v)
# reset cached data
c._result_cache = None
c.__metadata = {}
c._SphinxQuerySet__metadata = {}
return c

def _sphinx(self):
Expand Down Expand Up @@ -500,6 +516,9 @@ def _handle_filters(filter_list, exclude=False):
if self._excludes:
params.append('excludes=%s' % (self._excludes,))
_handle_filters(self._excludes, True)

if self._select:
client.SetSelect(self._select)

if self._groupby:
params.append('groupby=%s' % (self._groupby,))
Expand Down