Skip to content

Commit

Permalink
only accept as search keywords strings with len > 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aniversarioperu committed Nov 12, 2014
1 parent c985126 commit fb37915
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
History
=======

* v1.4.X (2014-XX-XX) Only accept as search keywords strings with len > 2.
* v1.4.1 (2014-11-11) Improved general search engine, also events in
`seguimientos` are queried. Autofocus on search box when page loads. Better
highlighting of keywords. Check errors in datefield widget (advanced search).
Expand Down
2 changes: 1 addition & 1 deletion proyectos_de_ley/pdl/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_congresista_view_pagination(self):
self.assertTrue(b'endless_page_link' in response.content)

def test_sanitize(self):
mystring = "'/\\*%"
mystring = "'/\\*% a e "
expected = ''
result = views.sanitize(mystring)
self.assertEqual(expected, result)
Expand Down
13 changes: 10 additions & 3 deletions proyectos_de_ley/pdl/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
from functools import reduce
from itertools import chain
import re
import unicodedata

from django.shortcuts import render
Expand Down Expand Up @@ -177,8 +178,7 @@ def find_in_db(query):
:param query: user's keyword
:return: QuerySet object with items or string if no results were found.
"""
#TODO, remove trailing + from keywords before doing searches
keywords = query.split(" ")
keywords = query.strip().split(" ")
with Timer() as t:
proyecto_items = Proyecto.objects.filter(
reduce(lambda x, y: x | y, [Q(short_url__icontains=word) for word in keywords]) |
Expand Down Expand Up @@ -235,7 +235,14 @@ def sanitize(s):
s = s.replace("=", "")
s = s.replace("*", "")
s = s.replace("%", "")
return s
new_s = []
append = new_s.append
for i in s.split(" "):
if len(i.strip()) > 2:
append(i)
new_s = " ".join(new_s)
new_s = re.sub("\s+", " ", new_s)
return new_s


def get_last_items():
Expand Down

0 comments on commit fb37915

Please sign in to comment.