Skip to content

Commit

Permalink
refactor: remove search_text filter functions from the storage class
Browse files Browse the repository at this point in the history
  • Loading branch information
osoken committed Aug 18, 2024
1 parent 3c757ef commit ef5136e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions common/birdxplorer_common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ def get_posts(
query = query.filter(PostRecord.created_at >= start)
if end is not None:
query = query.filter(PostRecord.created_at < end)
if search_text is not None:
query = query.filter(PostRecord.text.like(f"%{search_text}%"))
for post_record in query.all():
yield self._post_record_to_model(post_record)

Expand All @@ -299,11 +301,6 @@ def get_posts_by_note_ids(self, note_ids: List[NoteId]) -> Generator[PostModel,
for post_record in sess.execute(query).scalars().all():
yield self._post_record_to_model(post_record)

def search_posts_by_text(self, search_word: str) -> Generator[PostModel, None, None]:
with Session(self.engine) as sess:
for post_record in sess.query(PostRecord).filter(PostRecord.text.like(f"%{search_word}%")):
yield self._post_record_to_model(post_record)

def get_number_of_posts(
self,
post_ids: Union[List[PostId], None] = None,
Expand Down
2 changes: 1 addition & 1 deletion common/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_search_posts_by_text(
storage = Storage(engine=engine_for_test)
search_word = "https://t.co/xxxxxxxxxxx/"
expected = [post_samples[i] for i in (0, 2)]
actual = list(storage.search_posts_by_text(search_word))
actual = list(storage.get_posts(search_text=search_word))
assert actual == expected


Expand Down

0 comments on commit ef5136e

Please sign in to comment.