Skip to content

Commit

Permalink
feat: searching notes by text
Browse files Browse the repository at this point in the history
  • Loading branch information
iazzenma committed Aug 18, 2024
1 parent ea859de commit dc3a216
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/birdxplorer_api/routers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def get_notes(
topic_ids: Union[List[TopicId], None] = Query(default=None),
post_ids: Union[List[PostId], None] = Query(default=None),
language: Union[LanguageIdentifier, None] = Query(default=None),
search_text: Union[None, str] = Query(default=None),
) -> NoteListResponse:
return NoteListResponse(
data=list(
Expand All @@ -86,6 +87,7 @@ def get_notes(
topic_ids=topic_ids,
post_ids=post_ids,
language=language,
search_text=search_text,
)
)
)
Expand Down
3 changes: 3 additions & 0 deletions common/birdxplorer_common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def get_notes(
topic_ids: Union[List[TopicId], None] = None,
post_ids: Union[List[PostId], None] = None,
language: Union[LanguageIdentifier, None] = None,
search_text: Union[None, str] = None,
) -> Generator[NoteModel, None, None]:
with Session(self.engine) as sess:
query = sess.query(NoteRecord)
Expand All @@ -248,6 +249,8 @@ def get_notes(
query = query.filter(NoteRecord.post_id.in_(post_ids))
if language is not None:
query = query.filter(NoteRecord.language == language)
if search_text is not None and len(search_text) > 0:
query = query.filter(NoteRecord.text.like(f"%{search_text}%"))
for note_record in query.all():
yield NoteModel(
note_id=note_record.note_id,
Expand Down

0 comments on commit dc3a216

Please sign in to comment.