Mercurial > libervia-backend
diff src/memory/sqlite.py @ 1224:f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 04 Oct 2014 10:25:32 +0200 |
parents | e6e0ea4dc835 |
children | 069ad98b360d |
line wrap: on
line diff
--- a/src/memory/sqlite.py Sat Oct 04 10:23:13 2014 +0200 +++ b/src/memory/sqlite.py Sat Oct 04 10:25:32 2014 +0200 @@ -264,7 +264,7 @@ {"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message}))) return d - def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=None): + def getHistory(self, from_jid, to_jid, limit=None, between=True, search=None, profile=None): """Retrieve messages in history @param from_jid (JID): source JID (full, or bare for catchall) @param to_jid (JID): dest JID (full, or bare for catchall) @@ -272,6 +272,7 @@ - 0 for no message (returns the empty list) - None for unlimited @param between (bool): confound source and dest (ignore the direction) + @param search (str): pattern to filter the history results @param profile (str): %(doc_profile)s @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory """ @@ -311,6 +312,10 @@ else: query_parts.append("%s AND %s" % (test_jid('source', from_jid), test_jid('dest', to_jid))) + if search: + # TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html + query_parts.append("AND message GLOB ?") + values.append("*%s*" % search) query_parts.append("ORDER BY timestamp DESC")