allenporter/ical

Search for an event

fustom opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
I would love to have a search function to find an event by the summary or by the description (or maybe by the location).

Describe the solution you'd like
A class method which returns a list (iterator) with every event who contains the search term.

Describe alternatives you've considered
Of course the best would be a complex search method, the returned list sorted by relevance. Maybe there is a python package for that.

Additional context
The easiest way without sorting:

class Event
[...]
  def contains(self, term: str) -> bool:
      """Return True if this event summary or description or location contains the search term."""
      return term in self.summary or term in str(self.description) or term in str(self.location)

class Timeline
[...]
  def search(self, term: str) -> Iterator[Event]:
      """Return an iterator containing all events contains the search term."""
      for item in self._iterable:
          if item.item.contains(term):
              yield item.item

Thanks for the feature request. Your opening request at the challenge here: what is in scope for search vs what is not in scope? So picking the right API is difficult.

Yet your examples are pretty straightforward. Seems like callers can implement this without much difficulty given they can iterate over the items and implement custom fields like in your examples.

As a result, my intuition is to not add this in the API.

Alright, tnx anyway.