Merge lp:~pedronis/u1db/document-get-index-w-bool-number into lp:u1db

Proposed by Samuele Pedroni
Status: Merged
Approved by: Stuart Langridge
Approved revision: 439
Merged at revision: 439
Proposed branch: lp:~pedronis/u1db/document-get-index-w-bool-number
Merge into: lp:u1db
Diff against target: 51 lines (+27/-2)
1 file modified
html-docs/high-level-api.rst (+27/-2)
To merge this branch: bzr merge lp:~pedronis/u1db/document-get-index-w-bool-number
Reviewer Review Type Date Requested Status
Stuart Langridge (community) Approve
Review via email: mp+165218@code.launchpad.net

Commit message

clarify querying of number() and bool() indexes, values for querying are always strings (atm)

Description of the change

clarify querying of number() and bool() indexes, values for querying are always strings (atm)

To post a comment you must log in.
438. By Samuele Pedroni

bool() query example

439. By Samuele Pedroni

number() example and note

Revision history for this message
Stuart Langridge (sil) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'html-docs/high-level-api.rst'
2--- html-docs/high-level-api.rst 2012-09-18 16:25:41 +0000
3+++ html-docs/high-level-api.rst 2013-05-24 12:41:26 +0000
4@@ -308,8 +308,8 @@
5 Querying an index
6 ^^^^^^^^^^^^^^^^^
7
8-Pass an index key or a tuple of index keys (if the index is on multiple fields)
9-to ``get_from_index``; the last index key in each tuple (and *only* the last
10+Pass an index key or multiple index keys (if the index is on multiple fields)
11+to ``get_from_index``; the last index key (and *only* the last
12 one) can end with an asterisk, which matches initial substrings. So, querying
13 our ``by-firstname`` index from above:
14
15@@ -332,6 +332,30 @@
16 >>> assert(jb.doc_id in js)
17 >>> assert(jm.doc_id in js)
18
19+Index key values used when querying are always strings. If querying an
20+index built with ``bool()`` use the values '0' and '1' to query for
21+false and true respectively. For an index built with ``number()`` turn
22+key number values into strings with the appropriate left zero-padding
23+(and note in particular that querying a ``number()`` index with an int
24+value, such as ``db.get_from_index('by-number', 9)``, will throw an error).
25+
26+.. doctest ::
27+
28+ >>> db = u1db.open('mydb11.u1db', create=True)
29+ >>> db.create_index('done', "bool(done)")
30+ >>> doc1 = db.create_doc({'task': 'milk', 'done': False, 'hours': 1})
31+ >>> doc2 = db.create_doc({'task': 'coding', 'done': True, 'hours': 12})
32+ >>> [doc.content['task'] for doc in db.get_from_index('done', '1')]
33+ [u'coding']
34+ >>> db.create_index('by-hours', "number(hours, 3)")
35+ >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '12')]
36+ []
37+ >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '012')]
38+ [u'coding']
39+ >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '001')]
40+ [u'milk']
41+
42+
43 Index functions
44 ^^^^^^^^^^^^^^^
45
46@@ -399,4 +423,5 @@
47 os.remove(os.path.join(tmp_dir, "mydb8.u1db"))
48 os.remove(os.path.join(tmp_dir, "mydb9.u1db"))
49 os.remove(os.path.join(tmp_dir, "mydb10.u1db"))
50+ os.remove(os.path.join(tmp_dir, "mydb11.u1db"))
51 os.rmdir(tmp_dir)

Subscribers

People subscribed via source and target branches