Skip to content

Commit 92ad915

Browse files
Merge pull request #32 from mikez/main
refactoring; improve documentation; more consistent and precise names
2 parents c2cab71 + 6c7da7c commit 92ad915

File tree

2 files changed

+150
-122
lines changed

2 files changed

+150
-122
lines changed

things/api.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ def tasks(uuid=None, include_items=False, **kwargs): # noqa: C901
9090
If the argument is `True`, only include tasks _with_ a due date.
9191
If the argument is `None` (default), then include all tasks.
9292
93+
search_query : str, optional
94+
The string value is passed to the SQL LIKE operator. It can thus
95+
include placeholders such as '%' and '_'. Per default, it is
96+
wrapped in '% ... %'.
97+
98+
Currently titles and notes of to-dos, projects, headings, and areas
99+
are taken into account.
100+
101+
If the query is `False`, then return items where titles or notes
102+
are empty.
103+
104+
If the query `None`, then return all items.
105+
93106
index : {'index', 'todayIndex'}, default 'index'
94107
Database field to order result by.
95108
@@ -315,26 +328,35 @@ def tags(title=None, include_items=False, **kwargs):
315328
# Utility API functions derived from above
316329
# --------------------------------------------------
317330

331+
318332
def search(query: str, **kwargs) -> List[Dict]:
319333
"""
320-
Search the database. This takes mainly notes and titles into account.
334+
Search tasks in the database.
321335
322-
Parameters
323-
----------
324-
query : str
325-
The string with optional placeholders (%) to search for.
336+
Currently any part of a title and note of a to-do, project,
337+
heading, or area is matched.
326338
327-
Returns
328-
-------
329-
list of dict
330-
Representing Things items.
339+
See the `search_query` parameter of `api.tasks` for details.
331340
332341
Examples
333342
--------
334-
>>> things.search('substring % within notes and titles')
335-
...
343+
>>> things.search('book')
344+
[{'uuid': 'YrOmUnEXASmpq8ch6RsyPt',
345+
'type': 'to-do',
346+
'title': 'Book a hotel room',
347+
...},
348+
{'uuid': 'KVHAxIIJ52a0h1RCbmg5D6',
349+
'type': 'to-do',
350+
'title': 'Book flights',
351+
...}]
352+
353+
>>> things.search('book%room')
354+
[{'uuid': 'YrOmUnEXASmpq8ch6RsyPt',
355+
'type': 'to-do',
356+
'title': 'Book a hotel room',
357+
...}]
336358
"""
337-
return tasks(querystr=query, **kwargs)
359+
return tasks(search_query=query, **kwargs)
338360

339361

340362
def get(uuid, default=None, **kwargs):

0 commit comments

Comments
 (0)