Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Limits search queries to 100 characters
Browse files Browse the repository at this point in the history
Fixes #191
  • Loading branch information
Denis Krienbühl committed Apr 29, 2016
1 parent 802e6e6 commit 1516b0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Changelog
- Adds full history and url sharing support to the calendar.
[href]

- Limits search queries to 100 characters.
[href]

- Improve legibility for ticket badges with numbers > 99.
[href]

Expand Down
9 changes: 7 additions & 2 deletions onegov/town/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class Search(Pagination):

results_per_page = 10
max_query_length = 100

def __init__(self, request, query, page):
self.request = request
Expand Down Expand Up @@ -47,10 +48,14 @@ def batch(self):
explain=self.explain
)

# queries need to be cut at some point to make sure we're not
# pushing the elasticsearch cluster to the brink
query = self.query[:self.max_query_length]

# make sure the title matches with a higher priority, otherwise the
# "get lucky" functionality is not so lucky after all
match_title = MatchPhrase(title={"query": self.query, "boost": 3})
match_rest = MultiMatch(query=self.query, fields=[
match_title = MatchPhrase(title={"query": query, "boost": 3})
match_rest = MultiMatch(query=query, fields=[
'title', 'lead', 'text', 'email', 'function', 'number',
'ticket_email', 'ticket_data', 'description', 'location',
'group'
Expand Down

0 comments on commit 1516b0f

Please sign in to comment.