summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@riseup.net>2015-11-18 19:01:52 -0200
committerBruno Wagner <bwagner@riseup.net>2015-11-18 19:02:16 -0200
commitba3fe6aca3588262e76d467ae004d0818c987358 (patch)
treeacdadd51424a341c05bfc5b50f04243bb12a6f6b /service
parent8888ad02c22f90f5888e74bde19cc67553b0b395 (diff)
Issue #526 - Fixed contacts query input and results to only return matched terms
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/search/contacts.py16
-rw-r--r--service/pixelated/resources/contacts_resource.py2
2 files changed, 11 insertions, 7 deletions
diff --git a/service/pixelated/adapter/search/contacts.py b/service/pixelated/adapter/search/contacts.py
index 0729e146..d981e0bb 100644
--- a/service/pixelated/adapter/search/contacts.py
+++ b/service/pixelated/adapter/search/contacts.py
@@ -44,9 +44,13 @@ def search_addresses(searcher, query):
results = []
for field in ['to', 'cc', 'bcc', 'sender']:
query_parser = QueryParser(field, searcher.schema)
- results.append(searcher.search(query_parser.parse("*%s*" % query),
- limit=None,
- mask=restrict_q,
- groupedby=sorting.FieldFacet(field,
- allow_overlap=True)).groups())
- return flatten(results)
+ results.append(
+ searcher.search(
+ query_parser.parse("*%s*" % query),
+ limit=None,
+ mask=restrict_q,
+ groupedby=sorting.FieldFacet(
+ field,
+ allow_overlap=True),
+ terms=True).matched_terms())
+ return [address[1] for address in flatten(results)]
diff --git a/service/pixelated/resources/contacts_resource.py b/service/pixelated/resources/contacts_resource.py
index c9b81f54..43155774 100644
--- a/service/pixelated/resources/contacts_resource.py
+++ b/service/pixelated/resources/contacts_resource.py
@@ -29,7 +29,7 @@ class ContactsResource(Resource):
self._search_engine = search_engine
def render_GET(self, request):
- query = request.args.get('q', [''])
+ query = request.args.get('q', [''])[-1]
d = deferToThread(lambda: self._search_engine.contacts(query))
d.addCallback(lambda tags: respond_json_deferred(tags, request))