refactor: remove total_streams filter and simplify text index in models to improve searching accuracy

This commit is contained in:
mhdzumair
2025-03-02 22:06:42 +05:30
parent 7104ec77cd
commit dd368ec471
3 changed files with 23 additions and 5 deletions
-1
View File
@@ -1109,7 +1109,6 @@ async def process_search_query(
"$caseSensitive": False,
},
"type": catalog_type,
"total_streams": {"$gt": 0},
}
filter_conditions = []
+1 -4
View File
@@ -73,10 +73,7 @@ class MediaFusionMetaData(Document):
[("title", ASCENDING), ("year", ASCENDING), ("type", ASCENDING)],
unique=False,
),
IndexModel(
[("title", TEXT), ("aka_titles", TEXT)],
weights={"title": 10, "aka_titles": 5}, # Prioritize main title matches
),
IndexModel([("title", TEXT)]),
IndexModel([("year", ASCENDING), ("end_year", ASCENDING)]),
IndexModel([("_class_id", ASCENDING)]),
IndexModel([("type", ASCENDING), ("genres", ASCENDING)]),
@@ -0,0 +1,22 @@
from beanie import Document, free_fall_migration
class MediaFusionMetaData(Document):
id: str
class Settings:
name = "MediaFusionMetaData"
class Forward:
@free_fall_migration(document_models=[MediaFusionMetaData])
async def update_text_index(self, session):
"""Update text index to use only title field for better search relevance"""
metadata_collection = MediaFusionMetaData.get_motor_collection()
# drop index "title_text_aka_titles_text"
await metadata_collection.drop_index("title_text_aka_titles_text")
print("title_text_aka_titles_text Index dropped successfully.")
class Backward: ...