Browse Source

feat(hadis): include all_titles and search_text in sync category tree API for cross-lingual search

master
Mohsen Taba 2 weeks ago
parent
commit
5c491c1776
  1. 23
      apps/hadis/views/category.py

23
apps/hadis/views/category.py

@ -182,6 +182,24 @@ class HadisCategoryTreeView(ListAPIView):
return Response(response_data)
def _extract_all_titles(self, title_data):
"""Extract all language titles from JSON title list"""
if not title_data:
return []
if isinstance(title_data, str):
return [title_data.strip()] if title_data.strip() else []
if isinstance(title_data, list):
titles = []
for item in title_data:
if isinstance(item, dict):
val = item.get("title") or item.get("text") or item.get("name")
if val and str(val).strip():
titles.append(str(val).strip())
elif isinstance(item, str) and item.strip():
titles.append(item.strip())
return list(dict.fromkeys(titles))
return []
def _build_tree_recursive(self, category, request, children_map, recursive_counts, hadis_ids_map, quran_data_map):
"""
Build tree from flat mapping, pruning any node that has no active children and no active hadiths.
@ -207,10 +225,15 @@ class HadisCategoryTreeView(ListAPIView):
if len(built_children) == 0 and not has_hadis and not has_quran:
return None
all_titles = self._extract_all_titles(category.title)
search_blob = f"{category.normalized_text or ''} {' '.join(all_titles)}".strip()
return {
'id': category.id,
'title': get_localized_text(category.title, request),
'description': get_localized_text(category.description, request),
'all_titles': all_titles,
'search_text': search_blob,
'slug': category.slug,
'source_type': category.source_type,
'sect_id': category.sect_id,

Loading…
Cancel
Save