mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Include archive details in file search.
This commit is contained in:
parent
4918ea5ef6
commit
4a21499bdd
2 changed files with 20 additions and 5 deletions
|
|
@ -38,6 +38,18 @@ class Archive(Base, ModelHelper):
|
|||
file_group_id = Column(BigInteger, ForeignKey('file_group.id', ondelete='CASCADE'), unique=True, nullable=False)
|
||||
file_group: FileGroup = relationship('FileGroup')
|
||||
|
||||
def __json__(self) -> dict:
|
||||
d = self.file_group.__json__()
|
||||
d['archive'] = dict(
|
||||
id=self.id,
|
||||
collection_id=self.collection_id,
|
||||
domain=self.domain,
|
||||
singlefile_path=self.singlefile_path.name if self.singlefile_path else None,
|
||||
readability_txt_path=self.readability_txt_path.name if self.readability_txt_path else None,
|
||||
screenshot_path=self.screenshot_path.name if self.screenshot_path else None,
|
||||
)
|
||||
return d
|
||||
|
||||
def __repr__(self):
|
||||
domain_name = self.domain if self.collection else None
|
||||
if domain_name:
|
||||
|
|
|
|||
|
|
@ -1013,18 +1013,21 @@ def handle_file_group_search_results(statement: str, params: dict) -> Tuple[List
|
|||
extras = []
|
||||
|
||||
with get_db_session() as session:
|
||||
from modules.archive.models import Archive
|
||||
from modules.videos.models import Video
|
||||
results = session.query(FileGroup, Video) \
|
||||
results = session.query(FileGroup, Video, Archive) \
|
||||
.filter(FileGroup.id.in_(ordered_ids)) \
|
||||
.outerjoin(Video, Video.file_group_id == FileGroup.id)
|
||||
.outerjoin(Video, Video.file_group_id == FileGroup.id) \
|
||||
.outerjoin(Archive, Archive.file_group_id == FileGroup.id)
|
||||
# Order FileGroups by their location in ordered_ids. Use dict for O(1) lookups instead of O(n) list.index().
|
||||
id_to_order = {id_: idx for idx, id_ in enumerate(ordered_ids)}
|
||||
file_groups: List[Tuple[FileGroup, Video]] = sorted(results, key=lambda i: id_to_order.get(i[0].id, 0))
|
||||
file_groups = sorted(results, key=lambda i: id_to_order.get(i[0].id, 0))
|
||||
results = list()
|
||||
for extra, (file_group, video) in zip_longest(extras, file_groups):
|
||||
video: Video
|
||||
for extra, (file_group, video, archive) in zip_longest(extras, file_groups):
|
||||
if video:
|
||||
results.append(video.__json__())
|
||||
elif archive:
|
||||
results.append(archive.__json__())
|
||||
else:
|
||||
results.append(file_group.__json__())
|
||||
# Preserve the ts_ranks, if any.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue