Added case-insensitive searching of entry title and body

added search test
Renamed searching to contains. Made changes as per pull-request:
https://github.com/jrnl-org/jrnl/pull/740
This commit is contained in:
Jims 2019-11-12 11:53:12 -05:00
parent 657eb8fcda
commit b8d43db558
3 changed files with 38 additions and 3 deletions

View file

@ -188,7 +188,7 @@ class Journal:
tag_counts = {(tags.count(tag), tag) for tag in tags}
return [Tag(tag, count=count) for count, tag in sorted(tag_counts)]
def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False, exclude=[]):
def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False, contains=None, exclude=[]):
"""Removes all entries from the journal that don't match the filter.
tags is a list of tags, each being a string that starts with one of the
@ -210,6 +210,9 @@ class Journal:
# If strict mode is on, all tags have to be present in entry
tagged = self.search_tags.issubset if strict else self.search_tags.intersection
excluded = lambda tags: len([tag for tag in tags if tag in excluded_tags]) > 0
if contains:
contains_lower = contains.casefold()
result = [
entry for entry in self.entries
if (not tags or tagged(entry.tags))
@ -217,6 +220,7 @@ class Journal:
and (not start_date or entry.date >= start_date)
and (not end_date or entry.date <= end_date)
and (not exclude or not excluded(entry.tags))
and (not contains or (contains_lower in entry.title.casefold() or contains_lower in entry.body.casefold()))
]
self.entries = result