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

Commit

Permalink
Allows to overwrite the used columns when full-text querying notices
Browse files Browse the repository at this point in the history
  • Loading branch information
msom committed Dec 4, 2018
1 parent 7dbd574 commit 0367053
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
---------

- Allows to overwrite the used columns when full-text querying notices.
[msom]

0.9.0 (2018-11-23)
~~~~~~~~~~~~~~~~~~~

Expand Down
28 changes: 18 additions & 10 deletions onegov/notice/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ class OfficialNoticeCollection(OfficialNoticeCollectionPagination):
def model_class(self):
return OfficialNotice

@property
def term_columns(self):
""" The columns used for full text search. """

return [
cast(self.model_class.id, String),
self.model_class.title,
self.model_class.text,
self.model_class.author_name,
self.model_class.author_place,
self.model_class.category,
self.model_class.organization,
UserGroup.name,
User.realname,
User.username
]

def filter_query(self, query):
""" Filters the given query by the state of the collection. """

Expand All @@ -202,16 +219,7 @@ def filter_query(self, query):
term = '%{}%'.format(self.term)
query = query.filter(
or_(
cast(self.model_class.id, String).ilike(term),
self.model_class.title.ilike(term),
self.model_class.text.ilike(term),
self.model_class.author_name.ilike(term),
self.model_class.author_place.ilike(term),
self.model_class.category.ilike(term),
self.model_class.organization.ilike(term),
UserGroup.name.ilike(term),
User.realname.ilike(term),
User.username.ilike(term)
*[column.ilike(term) for column in self.term_columns]
)
)
if self.user_ids:
Expand Down

0 comments on commit 0367053

Please sign in to comment.