diff options
author | Sascha Silbe <sascha-pgp@silbe.org> | 2013-07-29 13:23:05 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha-pgp@silbe.org> | 2013-07-29 13:23:05 (GMT) |
commit | 7752b80101762e1b4c80a28009a3b4ed268d9e69 (patch) | |
tree | 1c36503ab73d81a7bed83eb3bfbcd5ca379dfb77 | |
parent | 23164d7f0d0ce69556225315f1c2989780576f7b (diff) |
Add support for uid in Xapian query for Sugar 0.84+ find() API
With the Sugar 0.84+ API (without version support), there are three
ways to look up the metadata of a single entry:
1. get_properties(uid)
2. find({'uid': uid}, {})
3. find({'query': 'uid:' + uid}, {})
The former two were already supported by explicit conversion inside
the API adapter class.
The last one matches the uid inside a Xapian query string. This is
more tricky to support as the string gets parsed by Xapian, not
ourselves.
We're going the simple route for now and just add a 'uid'
compatibility prefix for our custom Xapian query parser. This will
leak some Sugar API details to other APIs. If any issue comes up
because of that, we'll need to pass in different sets of prefixes to
Index.find() for each query, based on which API was used.
-rw-r--r-- | gdatastore/index.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gdatastore/index.py b/gdatastore/index.py index 5730f54..faa02c5 100644 --- a/gdatastore/index.py +++ b/gdatastore/index.py @@ -144,6 +144,9 @@ class QueryParser(xapian.QueryParser): for name, info in _STANDARD_TERMS.items(): self.add_prefix(name, info['prefix']) self.add_prefix('', info['prefix']) + # For compatibility with Sugar 0.84+ data store API (without + # version support). + self.add_prefix('uid', _STANDARD_TERMS['tree_id']['prefix']) def _parse_query_term(self, prefix, value): if isinstance(value, list): |