[tor-commits] [pyonionoo/master] Implement search filter
karsten at torproject.org
karsten at torproject.org
Sun Sep 23 19:07:05 UTC 2012
commit 3fce02cc02caa2e91d5d10133f596a14b3245292
Author: Sathyanarayanan Gunasekaran <gsathya.ceg at gmail.com>
Date: Sun Sep 23 15:12:18 2012 +0530
Implement search filter
---
pyonionoo/database.py | 35 +++++++++++------------------------
pyonionoo/handlers/arguments.py | 2 +-
2 files changed, 12 insertions(+), 25 deletions(-)
diff --git a/pyonionoo/database.py b/pyonionoo/database.py
index 18eb4bc..128ccae 100644
--- a/pyonionoo/database.py
+++ b/pyonionoo/database.py
@@ -203,29 +203,16 @@ def query_summary_tbl(running_filter=None, type_filter=None, hex_fingerprint_fil
# some subset (possibly empty) of {'running', 'type', 'lookup', 'country'}.
clauses = []
if search_filter:
- # We have to do some heuristics here, because the search filters
- # do not come with anything to identify which field they correspond
- # to. E.g., the request search=ffa means any relay with nickname
- # starting with 'ffa' or fingerprint starting with 'ffa' or '$ffa'.
-
- # Actually, this is a moderately painful parameter to implement.
- # Testing for an IP address probably means using regular expressions.
- # SQLite doesn't support them without a user-defined function.
- # Matching against a Python RE is easy to do, but then we have
- # to have a where clause that matches against the beginning of a
- # field value, and SQLite doesn't appear to support such a search
- # (unless, of course, you want to write a user-defined match()
- # function).
- pass
- else:
- if running_filter:
- clauses.append("running = %s" % int(running_filter))
- if type_filter:
- clauses.append("type = '%s'" % type_filter)
- if hex_fingerprint_filter:
- clauses.append("fingerprint = '%s'" % hex_fingerprint_filter)
- if country_filter:
- clauses.append("country_code = '%s'" % country_filter)
+ for filter in search_filter:
+ clauses.append("search like '%%%s%%'" % filter)
+ if running_filter:
+ clauses.append("running = %s" % int(running_filter))
+ if type_filter:
+ clauses.append("type = '%s'" % type_filter)
+ if hex_fingerprint_filter:
+ clauses.append("fingerprint = '%s'" % hex_fingerprint_filter)
+ if country_filter:
+ clauses.append("country_code = '%s'" % country_filter)
where_clause = ('WHERE %s' % ' and '.join(clauses)) if clauses else ''
# Construct the ORDER, LIMIT, and OFFSET clauses.
@@ -259,7 +246,7 @@ def get_summary_routers(running_filter=None, type_filter=None, hex_fingerprint_f
@return: tuple of form (relays, bridges, relays_time, bridges_time), where
* relays/bridges is a list of Router objects
* relays_time/bridges_time is a datetime object with the most
- recent timestamp of the relay descriptors in relays.
+ recent timestamp of the relay/bridges descriptors in relays.
"""
# Timestamps of most recent relay/bridge in the returned set.
diff --git a/pyonionoo/handlers/arguments.py b/pyonionoo/handlers/arguments.py
index e853faf..4c18b84 100644
--- a/pyonionoo/handlers/arguments.py
+++ b/pyonionoo/handlers/arguments.py
@@ -74,7 +74,7 @@ def parse(arguments):
# the search parameter, which is then given to us as a single
# (space-separated) string.
if key == "search":
- search_filter = values.split()
+ search_filter = values[0].split()
# TODO: Handle list of ordering fields.
if key == "order":
More information about the tor-commits
mailing list