Browse files

pass kw args to catalog query

  • Loading branch information...
1 parent f03d64c commit 02656c529578b2174da28838310634aeb36bf8a1 @rnixx rnixx committed Jul 16, 2012
Showing with 19 additions and 8 deletions.
  1. +8 −8 src/souper/soup.py
  2. +11 −0 src/souper/soup.rst
View
16 src/souper/soup.py
@@ -88,18 +88,18 @@ def add(self, record):
def query(self, queryobject, sort_index=None, limit=None, sort_type=None,
reverse=False, names=None):
- num, resultseq = self.catalog.query(queryobject, sort_index=None,
- limit=None, sort_type=None,
- reverse=False, names=None)
- for iid in resultseq:
+ result = self.catalog.query(queryobject, sort_index=sort_index,
+ limit=limit, sort_type=sort_type,
+ reverse=reverse, names=names)
+ for iid in result[1]:
yield self.data[iid]
def lazy(self, queryobject, sort_index=None, limit=None, sort_type=None,
reverse=False, names=None):
- num, resultseq = self.catalog.query(queryobject, sort_index=None,
- limit=None, sort_type=None,
- reverse=False, names=None)
- for iid in resultseq:
+ result = self.catalog.query(queryobject, sort_index=sort_index,
+ limit=limit, sort_type=sort_type,
+ reverse=reverse, names=names)
+ for iid in result[1]:
yield LazyRecord(iid, self)
def clear(self):
View
11 src/souper/soup.rst
@@ -168,6 +168,17 @@ Check keyword index::
>>> len(list(soup.query(Any('keywords', [u'ü']))))
1
+Check sorting::
+
+ >>> res = soup.query(Eq('user', ['user1', 'user2']), sort_index='user')
+ >>> [_.attrs['user'] for _ in res]
+ ['user1', 'user2', 'user2']
+
+ >>> res = soup.query(
+ ... Eq('user', ['user1', 'user2']), sort_index='user', reverse=True)
+ >>> [_.attrs['user'] for _ in res]
+ ['user2', 'user2', 'user1']
+
You can reindex all records in soup at once::
>>> all = [r for r in soup.data.values()]

0 comments on commit 02656c5

Please sign in to comment.