Skip to content

Commit 54582b6

Browse files
authored
Merge pull request #9 from arcadeai-labs/Spartee/fix-date-filtering
Use file mtime for date filtering
2 parents 33b747e + 706f0fa commit 54582b6

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

librarian/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ async def search_library_by_dates(
658658

659659
# If end_date has no time component, set to end of day
660660
if end_dt.hour == 0 and end_dt.minute == 0 and end_dt.second == 0:
661-
end_dt = end_dt.replace(hour=23, minute=59, second=59)
661+
end_dt = end_dt.replace(hour=23, minute=59, second=59, microsecond=999999)
662662

663663
db = get_database()
664664
filter_doc_ids = db.get_document_ids_in_timerange(start_dt, end_dt)

librarian/storage/database.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,20 +480,31 @@ def get_document_ids_in_timerange(
480480
"""
481481
Get document IDs that fall within a time range.
482482
483+
Uses file_mtime (actual file modification time) when available,
484+
falling back to updated_at (database indexing time) for documents
485+
without file_mtime.
486+
483487
Args:
484488
start_date: Start of the time range (inclusive).
485489
end_date: End of the time range (exclusive).
486490
487491
Returns:
488492
List of document IDs.
489493
"""
494+
start_ts = start_date.timestamp()
495+
end_ts = end_date.timestamp()
490496
with self.connection() as conn:
491497
rows = conn.execute(
492498
"""
493499
SELECT id FROM documents
494-
WHERE updated_at >= ? AND updated_at < ?
500+
WHERE
501+
CASE
502+
WHEN file_mtime IS NOT NULL
503+
THEN file_mtime >= ? AND file_mtime < ?
504+
ELSE updated_at >= ? AND updated_at < ?
505+
END
495506
""",
496-
(start_date.isoformat(), end_date.isoformat()),
507+
(start_ts, end_ts, start_date.isoformat(), end_date.isoformat()),
497508
).fetchall()
498509
return [row["id"] for row in rows]
499510

0 commit comments

Comments
 (0)