add optional search term to search image metadata

This commit is contained in:
maryhipp 2024-06-25 20:27:37 -04:00
parent e3e8d689d7
commit 89c5662848
5 changed files with 14 additions and 0 deletions

View File

@ -316,6 +316,7 @@ async def list_image_dtos(
), ),
offset: int = Query(default=0, description="The page offset"), offset: int = Query(default=0, description="The page offset"),
limit: int = Query(default=10, description="The number of images per page"), limit: int = Query(default=10, description="The number of images per page"),
search_term: Optional[str] = Query(default=None, description="The term to search for"),
) -> OffsetPaginatedResults[ImageDTO]: ) -> OffsetPaginatedResults[ImageDTO]:
"""Gets a list of image DTOs""" """Gets a list of image DTOs"""
@ -326,6 +327,7 @@ async def list_image_dtos(
categories, categories,
is_intermediate, is_intermediate,
board_id, board_id,
search_term
) )
return image_dtos return image_dtos

View File

@ -41,6 +41,7 @@ class ImageRecordStorageBase(ABC):
categories: Optional[list[ImageCategory]] = None, categories: Optional[list[ImageCategory]] = None,
is_intermediate: Optional[bool] = None, is_intermediate: Optional[bool] = None,
board_id: Optional[str] = None, board_id: Optional[str] = None,
search_term: Optional[str] = None,
) -> OffsetPaginatedResults[ImageRecord]: ) -> OffsetPaginatedResults[ImageRecord]:
"""Gets a page of image records.""" """Gets a page of image records."""
pass pass

View File

@ -148,6 +148,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
categories: Optional[list[ImageCategory]] = None, categories: Optional[list[ImageCategory]] = None,
is_intermediate: Optional[bool] = None, is_intermediate: Optional[bool] = None,
board_id: Optional[str] = None, board_id: Optional[str] = None,
search_term: Optional[str] = None,
) -> OffsetPaginatedResults[ImageRecord]: ) -> OffsetPaginatedResults[ImageRecord]:
try: try:
self._lock.acquire() self._lock.acquire()
@ -208,6 +209,13 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
""" """
query_params.append(board_id) query_params.append(board_id)
# Search term condition
if search_term:
query_conditions += """--sql
AND json_extract(images.metadata, '$') LIKE ?
"""
query_params.append(f'%{search_term}%')
query_pagination = """--sql query_pagination = """--sql
ORDER BY images.starred DESC, images.created_at DESC LIMIT ? OFFSET ? ORDER BY images.starred DESC, images.created_at DESC LIMIT ? OFFSET ?
""" """

View File

@ -120,6 +120,7 @@ class ImageServiceABC(ABC):
categories: Optional[list[ImageCategory]] = None, categories: Optional[list[ImageCategory]] = None,
is_intermediate: Optional[bool] = None, is_intermediate: Optional[bool] = None,
board_id: Optional[str] = None, board_id: Optional[str] = None,
search_term: Optional[str] = None
) -> OffsetPaginatedResults[ImageDTO]: ) -> OffsetPaginatedResults[ImageDTO]:
"""Gets a paginated list of image DTOs.""" """Gets a paginated list of image DTOs."""
pass pass

View File

@ -206,6 +206,7 @@ class ImageService(ImageServiceABC):
categories: Optional[list[ImageCategory]] = None, categories: Optional[list[ImageCategory]] = None,
is_intermediate: Optional[bool] = None, is_intermediate: Optional[bool] = None,
board_id: Optional[str] = None, board_id: Optional[str] = None,
search_term: Optional[str] = None,
) -> OffsetPaginatedResults[ImageDTO]: ) -> OffsetPaginatedResults[ImageDTO]:
try: try:
results = self.__invoker.services.image_records.get_many( results = self.__invoker.services.image_records.get_many(
@ -215,6 +216,7 @@ class ImageService(ImageServiceABC):
categories, categories,
is_intermediate, is_intermediate,
board_id, board_id,
search_term
) )
image_dtos = [ image_dtos = [