Skip to content

Commit

Permalink
Merge pull request #44 from Sefaria/fix/db-filter
Browse files Browse the repository at this point in the history
fix: handle metadata fields with lists as values
  • Loading branch information
Paul-Yu-Chun-Chang authored Oct 8, 2024
2 parents 04c3f59 + 8019a96 commit 948118f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion VirtualHavruta/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ def construct_db_filter(matched_filters: dict) -> dict:
# Create filter conditions for each field
filter_conditions = []
for k, v in matched_filters.items():
if len(v) == 1:
# As of Oct-2024, metadata field names ending with s have lists as values (e.g., authorIDs). But langchain-community==0.2.7 doesn't support an $elemMatch operator. So, in such cases we tentatively use $eq for the whole list.
if k.endswith('s'):
filter_conditions.append({k: {"$eq": v}})
elif len(v) == 1:
filter_conditions.append({k: {"$eq": v[0]}})
else:
filter_conditions.append({k: {"$in": v}})
Expand Down

0 comments on commit 948118f

Please sign in to comment.