instruction
stringlengths
0
1k
input
stringlengths
1
1k
output
stringlengths
10
6.51k
False idxed_docs_results: list[dict] = [] idxed_blogs_results: list[dict] = [] @rx.event(temporal=True) def user_query(self, value: str): self.query = value.replace("rx.", "") @rx.event(temporal=True) def reset_search(self): """Reset state variables.""" self.idxed_blogs_results = [] self.idxed_docs_results = [] self.query = "" @rx.event(temporal=True) async def apply_filter_search(self, selected_filter: str): """Re-run search with new filter.""" if self.selected_filter == selected_filter: return self.selected_filter = selected_filter if self.query.strip(): yield SimpleSearch.perform_search() @rx.event(background=True, temporal=True) async def perform_search(self): """Perform Typesense search and split results.""" async with self: if not self.query.strip(): self.idxed_docs_results = []
return try: async with self: self.is_fetching = True yield client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blo
self.idxed_blogs_results = []
=True) def user_query(self, value: str): self.query = value.replace("rx.", "") @rx.event(temporal=True) def reset_search(self): """Reset state variables.""" self.idxed_blogs_results = [] self.idxed_docs_results = [] self.query = "" @rx.event(temporal=True) async def apply_filter_search(self, selected_filter: str): """Re-run search with new filter.""" if self.selected_filter == selected_filter: return self.selected_filter = selected_filter if self.query.strip(): yield SimpleSearch.perform_search() @rx.event(background=True, temporal=True) async def perform_search(self): """Perform Typesense search and split results.""" async with self: if not self.query.strip(): self.idxed_docs_results = [] self.idxed_blogs_results = [] return try: async with self:
yield client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filte
self.is_fetching = True
uery = value.replace("rx.", "") @rx.event(temporal=True) def reset_search(self): """Reset state variables.""" self.idxed_blogs_results = [] self.idxed_docs_results = [] self.query = "" @rx.event(temporal=True) async def apply_filter_search(self, selected_filter: str): """Re-run search with new filter.""" if self.selected_filter == selected_filter: return self.selected_filter = selected_filter if self.query.strip(): yield SimpleSearch.perform_search() @rx.event(background=True, temporal=True) async def perform_search(self): """Perform Typesense search and split results.""" async with self: if not self.query.strip(): self.idxed_docs_results = [] self.idxed_blogs_results = [] return try: async with self: self.is_fetching = True yield
search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = "
client = typesense.Client(TYPESENSE_CONFIG)
rue) def reset_search(self): """Reset state variables.""" self.idxed_blogs_results = [] self.idxed_docs_results = [] self.query = "" @rx.event(temporal=True) async def apply_filter_search(self, selected_filter: str): """Re-run search with new filter.""" if self.selected_filter == selected_filter: return self.selected_filter = selected_filter if self.query.strip(): yield SimpleSearch.perform_search() @rx.event(background=True, temporal=True) async def perform_search(self): """Perform Typesense search and split results.""" async with self: if not self.query.strip(): self.idxed_docs_results = [] self.idxed_blogs_results = [] return try: async with self: self.is_fetching = True yield client = typesense.Client(TYPESENSE_CONFIG)
if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self:
search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, }
ts.""" async with self: if not self.query.strip(): self.idxed_docs_results = [] self.idxed_blogs_results = [] return try: async with self: self.is_fetching = True yield client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, }
result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype
if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter
ery.strip(): self.idxed_docs_results = [] self.idxed_blogs_results = [] return try: async with self: self.is_fetching = True yield client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content":
result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype
if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter
self.idxed_blogs_results = [] return try: async with self: self.is_fetching = True yield client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts":
else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception:
search_params["filter_by"] = "section:=Blog"
async with self: self.is_fetching = True yield client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else:
if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results
sections = self._get_sections_for_cluster(self.selected_filter)
client = typesense.Client(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter)
result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype
if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter
t(TYPESENSE_CONFIG) search_params = { "q": self.query, "query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections:
search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | No
section_filter = " || ".join(f"section:={s}" for s in sections)
"query_by": "title,content,headings,components", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections)
result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype
search_params["filter_by"] = section_filter
s", "query_by_weights": "6,8,3,12", "per_page": 15, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter
docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>
result = client.collections["docs"].documents.search(search_params)
5, "num_typos": 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params)
blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("co
docs_results = []
: 2, "sort_by": "_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = []
for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def
blog_results = []
"_text_match:desc", "text_match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = []
async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet,
for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc)
match_threshold": "0.6", "exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]:
formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in s
doc = hit["document"]
"exhaustive_search": True, "highlight_fields": "content", "highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"]
if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try:
formatted_doc = self._format_result(doc, hit.get("highlights", []))
"highlight_full_fields": "content,components", "highlight_start_tag": "<mark>", "highlight_end_tag": "</mark>", "snippet_threshold": 30, } if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", []))
async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet,
if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc)
if self.selected_filter != "All Content": if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self:
self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error:
self.idxed_docs_results = docs_results
if self.selected_filter == "Blog Posts": search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results
self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_st
self.idxed_blogs_results = blog_results
search_params["filter_by"] = "section:=Blog" else: sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results
except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return
self.is_fetching = False
sections = self._get_sections_for_cluster(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self:
self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []:
self.idxed_docs_results = []
ter(self.selected_filter) if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = []
self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"):
self.idxed_blogs_results = []
if sections: section_filter = " || ".join(f"section:={s}" for s in sections) search_params["filter_by"] = section_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = []
def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet
self.is_fetching = False
tion_filter result = client.collections["docs"].documents.search(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re
close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE )
bold_stype = '<span style="font-weight: 900; color: #AA99EC;">'
earch(search_params) docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">'
content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked:
close_tag = "</span>"
docs_results = [] blog_results = [] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>"
def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0]
content = doc.get("content", "") or ""
[] for hit in result["hits"]: doc = hit["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or ""
# 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet
def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet
["document"] formatted_doc = self._format_result(doc, hit.get("highlights", [])) if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str:
return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0:
for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}")
if doc.get("section") == "Blog": blog_results.append(formatted_doc) else: docs_results.append(formatted_doc) async with self: self.idxed_docs_results = docs_results self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try:
except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end]
snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, )
self.idxed_blogs_results = blog_results self.is_fetching = False except Exception: async with self: self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error:
return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0:
snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}")
self.idxed_docs_results = [] self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights
# 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c,
for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet )
self.idxed_blogs_results = [] self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []:
# 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c,
if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet )
self.is_fetching = False def _get_highlighted_content( self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"):
if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>"
snippet = h.get("snippet") or h.get("value") or ""
self, doc, highlights: list | None, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or ""
# 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c,
if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet )
one, snippet_length=350 ): import re bold_stype = '<span style="font-weight: 900; color: #AA99EC;">' close_tag = "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet:
if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + (
marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE )
= "</span>" content = doc.get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE )
snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("com
if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet
get("content", "") or "" def bold_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked:
idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet
token = marked[0]
_tokens(snippet: str, tokens: list[str]) -> str: for tok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0]
if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified)
idx = content.lower().find(token.lower())
ok in sorted({t for t in tokens if t}, key=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower())
snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("com
if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet
=len, reverse=True): try: snippet = re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1:
end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): v
start = max(0, idx - snippet_length // 2)
= re.sub( re.escape(tok), f"{bold_stype}\\g<0>{close_tag}", snippet, flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2)
snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [
end = min( len(content), idx + len(token) + snippet_length // 2 )
flags=re.IGNORECASE, ) except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 )
snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close
snippet = content[start:end]
except re.error: snippet = snippet.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end]
if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values
snippet = bold_tokens(snippet, marked)
.replace(tok, f"{bold_stype}{tok}{close_tag}") return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked)
if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}"
if start > 0: snippet = "..." + snippet
return snippet # 1) Typesense content/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0:
if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}"
snippet = "..." + snippet
ntent/title highlights for h in highlights or []: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet
return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower()
if end < len(content): snippet = snippet + "..."
]: if h.get("field") in ("content", "title"): snippet = h.get("snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content):
return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower()
snippet = snippet + "..."
"snippet") or h.get("value") or "" if snippet: marked = re.findall( r"<mark>(.*?)</mark>", snippet, flags=re.IGNORECASE ) if marked: token = marked[0] idx = content.lower().find(token.lower()) if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet
return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded
snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag )
if idx != -1: start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified)
# 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -
for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}"
start = max(0, idx - snippet_length // 2) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []:
# 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -
if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}"
) end = min( len(content), idx + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"):
if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content retu
values = h.get("values") or ([h.get("value")] if h.get("value") else [])
x + len(token) + snippet_length // 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else [])
# 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -
if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}"
// 2 ) snippet = content[start:end] snippet = bold_tokens(snippet, marked) if start > 0: snippet = "..." + snippet if end < len(content): snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values:
return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, [])
cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ]
snippet = snippet + "..." return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match
if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("se
q = (getattr(self, "query", "") or "").strip().lower()
return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower()
# 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""),
if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}"
return snippet snippet = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q:
matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name"
comps = doc.get("components") or []
t = snippet.replace("<mark>", bold_stype).replace( "</mark>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or []
if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []),
matched = [c for c in comps if isinstance(c, str) and q in c.lower()]
>", close_tag ) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()]
# 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""),
if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}"
) return snippet[:snippet_length] + ( "..." if len(snippet) > snippet_length else snippet ) # 2) Typesense component highlights (simplified) for h in highlights or []: if h.get("field", "").startswith("components"): values = h.get("values") or ([h.get("value")] if h.get("value") else []) if values: cleaned = [ v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched:
return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("titl
bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ]
v.replace("<mark>", bold_stype).replace("</mark>", close_tag) for v in values if v ] return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length)
def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), } def _get_cluster_from_section(self, section: str) -> str
def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, [])
return f"Matches found: {', '.join(cleaned[:6])}" # 3) Client-side components match q = (getattr(self, "query", "") or "").strip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, [])
def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items(): if section in sections: return cluster return "Docs" def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..." def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" retu
def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), }
trip().lower() if q: comps = doc.get("components") or [] matched = [c for c in comps if isinstance(c, str) and q in c.lower()] if matched: bolded = [ re.sub( re.escape(q), f"{bold_stype}\\g<0>{close_tag}", c, flags=re.IGNORECASE, ) for c in matched[:6] ] return f"Matches found: {', '.join(bolded)}" # 4) fallback: truncated content return self._truncate_content(content, max_length=snippet_length) def _get_sections_for_cluster(self, cluster_name: str) -> list[str]: """Map cluster names to section names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure."""
def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items(): if section in sections: return cluster return "Docs" def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..." def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" retu
if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), }
names.""" return CLUSTERS.get(cluster_name, []) def _format_result(self, doc: dict, highlights: list | None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), }
def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..." def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.33374 7.33472 1.33374C4
def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items(): if section in sections: return cluster return "Docs"
| None = None) -> dict: """Format Typesense result to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), } def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name."""
return "Docs" def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..." def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.3
for cluster, sections in CLUSTERS.items(): if section in sections: return cluster
sult to match your fuzzy search structure.""" if doc.get("section") != "Blog": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), } def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items():
return "Docs" def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..." def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.3
if section in sections: return cluster
og": return { "name": doc.get("title", ""), "parts": doc.get("parts", []), "url": doc.get("url", ""), "image": doc.get("path", ""), "cluster": self._get_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), } def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items(): if section in sections: return cluster return "Docs"
def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.33374 7.33472 1.33374C4.02101 1.33374 1.33472 4.02003 1.33472 7.33374C1.33472 10.6475 4.02101 13.3337 7.33472 13.3337C10.6485 13.3337 13.3347 10.6475 13.3347 7.33374Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>"""
def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..."
et_cluster_from_section(doc.get("section", "")), "description": self._get_highlighted_content(doc, highlights), } else: return { "title": doc.get("title", ""), "url": doc.get("url", ""), "author": doc.get("author", ""), "date": doc.get("date", ""), "description": self._truncate_content(doc.get("content", "")), "image": doc.get("image", ""), } def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items(): if section in sections: return cluster return "Docs" def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..."
def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.33374 7.33472 1.33374C4.02101 1.33374 1.33472 4.02003 1.33472 7.33374C1.33472 10.6475 4.02101 13.3337 7.33472 13.3337C10.6485 13.3337 13.3347 10.6475 13.3347 7.33374Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>""" ), rx.el.span( "Search", class_name="hidden md:block text-sm font-medium", ), rx.el.span( "⌘ K", class_name="px-2 bg-slate-4 rounded-sm ml-0.5 hidden md:block h-5 font-medium", ), variant="outline", size="sm", class_name="md:w-full text-secondary-11", ) def search_breadcrumb(items): """Cr
def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ )
tent(doc.get("content", "")), "image": doc.get("image", ""), } def _get_cluster_from_section(self, section: str) -> str: """Map section back to cluster name.""" for cluster, sections in CLUSTERS.items(): if section in sections: return cluster return "Docs" def _truncate_content(self, content: str, max_length: int = 200) -> str: """Truncate content for description.""" if len(content) <= max_length: return content return content[:max_length].rstrip() + "..." def keyboard_shortcut_script() -> rx.Component: """Add keyboard shortcut support for opening search.""" return rx.script( """ document.addEventListener('keydown', function(e) { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault(); document.getElementById('search-trigger').click(); } }); """ )
def search_breadcrumb(items): """Create a breadcrumb navigation component.""" return rx.hstack( rx.foreach( items, lambda item, index: rx.fragment( rx.cond( index > 0, rx.el.label( "›", # noqa: RUF001 class_name="text-sm font-medium", color=rx.color("slate", 11), ), ), rx.el.label( item, class_name=rx.cond( index == (items.length() - 1), "text-sm font-medium", "text-sm font-regular", ), color=rx.cond( index == (items.length() - 1), rx.color("slate", 12), rx.color("slate", 11), ), ), ), ),
def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.33374 7.33472 1.33374C4.02101 1.33374 1.33472 4.02003 1.33472 7.33374C1.33472 10.6475 4.02101 13.3337 7.33472 13.3337C10.6485 13.3337 13.3347 10.6475 13.3347 7.33374Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>""" ), rx.el.span( "Search", class_name="hidden md:block text-sm font-medium", ), rx.el.span( "⌘ K", class_name="px-2 bg-slate-4 rounded-sm ml-0.5 hidden md:block h-5 font-medium", ), variant="outline", size="sm", class_name="md:w-full text-secondary-11", )
} }); """ ) def search_trigger() -> rx.Component: """Render the search trigger button.""" return ui.button( rx.html( """<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> <path d="M11.6681 11.6671L14.6681 14.6671M13.3347 7.33374C13.3347 4.02003 10.6485 1.33374 7.33472 1.33374C4.02101 1.33374 1.33472 4.02003 1.33472 7.33374C1.33472 10.6475 4.02101 13.3337 7.33472 13.3337C10.6485 13.3337 13.3347 10.6475 13.3347 7.33374Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>""" ), rx.el.span( "Search", class_name="hidden md:block text-sm font-medium", ), rx.el.span( "⌘ K", class_name="px-2 bg-slate-4 rounded-sm ml-0.5 hidden md:block h-5 font-medium", ), variant="outline", size="sm", class_name="md:w-full text-secondary-11", )
def cluster_icon(filter_name: str): icons = { "All Content": "DragDropIcon", "AI Builder": "RoboticIcon", "Hosting": "CloudIcon", "Components": "BlockGameIcon", "Docs": "File01Icon", "Enterprise": "City02Icon", "API Reference": "ApiIcon", "Blog Posts": "BloggerIcon", } return ui.icon(icon=icons.get(filter_name, ""), class_name="shrink-0 size-4") def filter_items(filter_name: str): return ui.popover.close( rx.el.div( rx.el.div( cluster_icon(filter_name), rx.el.button( filter_name, class_name="w-full text-left", type="button", ), class_name="flex flex-row items-center gap-x-3", ), rx.cond( SimpleSearch.selected_filter == filter_name, rx.icon(tag="check", size=12), ), on_click=SimpleSe
def search_breadcrumb(items): """Create a breadcrumb navigation component.""" return rx.hstack( rx.foreach( items, lambda item, index: rx.fragment( rx.cond( index > 0, rx.el.label( "›", # noqa: RUF001 class_name="text-sm font-medium", color=rx.color("slate", 11), ), ), rx.el.label( item, class_name=rx.cond( index == (items.length() - 1), "text-sm font-medium", "text-sm font-regular", ), color=rx.cond( index == (items.length() - 1), rx.color("slate", 12), rx.color("slate", 11), ), ), ), ), spacing="1", cursor="pointer", )
dcrumb navigation component.""" return rx.hstack( rx.foreach( items, lambda item, index: rx.fragment( rx.cond( index > 0, rx.el.label( "›", # noqa: RUF001 class_name="text-sm font-medium", color=rx.color("slate", 11), ), ), rx.el.label( item, class_name=rx.cond( index == (items.length() - 1), "text-sm font-medium", "text-sm font-regular", ), color=rx.cond( index == (items.length() - 1), rx.color("slate", 12), rx.color("slate", 11), ), ), ), ), spacing="1", cursor="pointer", )
def filter_items(filter_name: str): return ui.popover.close( rx.el.div( rx.el.div( cluster_icon(filter_name), rx.el.button( filter_name, class_name="w-full text-left", type="button", ), class_name="flex flex-row items-center gap-x-3", ), rx.cond( SimpleSearch.selected_filter == filter_name, rx.icon(tag="check", size=12), ), on_click=SimpleSearch.apply_filter_search(filter_name), class_name="flex flex-row gap-x-2 items-center px-3 py-1 w-full justify-between cursor-pointer outline-none hover:bg-slate-3 focus:border-none", ) ) def filter_icon(tag: str): """Helper to render icons for filters consistently.""" return ui.icon(icon=tag, class_name="shrink-0 size-3") def filter_component(): return ui.popover.root( ui.po
def cluster_icon(filter_name: str): icons = { "All Content": "DragDropIcon", "AI Builder": "RoboticIcon", "Hosting": "CloudIcon", "Components": "BlockGameIcon", "Docs": "File01Icon", "Enterprise": "City02Icon", "API Reference": "ApiIcon", "Blog Posts": "BloggerIcon", } return ui.icon(icon=icons.get(filter_name, ""), class_name="shrink-0 size-4")
rn rx.hstack( rx.foreach( items, lambda item, index: rx.fragment( rx.cond( index > 0, rx.el.label( "›", # noqa: RUF001 class_name="text-sm font-medium", color=rx.color("slate", 11), ), ), rx.el.label( item, class_name=rx.cond( index == (items.length() - 1), "text-sm font-medium", "text-sm font-regular", ), color=rx.cond( index == (items.length() - 1), rx.color("slate", 12), rx.color("slate", 11), ), ), ), ), spacing="1", cursor="pointer", ) def cluster_icon(filter_name: str):
return ui.icon(icon=icons.get(filter_name, ""), class_name="shrink-0 size-4") def filter_items(filter_name: str): return ui.popover.close( rx.el.div( rx.el.div( cluster_icon(filter_name), rx.el.button( filter_name, class_name="w-full text-left", type="button", ), class_name="flex flex-row items-center gap-x-3", ), rx.cond( SimpleSearch.selected_filter == filter_name, rx.icon(tag="check", size=12), ), on_click=SimpleSearch.apply_filter_search(filter_name), class_name="flex flex-row gap-x-2 items-center px-3 py-1 w-full justify-between cursor-pointer outline-none hover:bg-slate-3 focus:border-none", ) ) def filter_icon(tag: str): """Helper to render icons for filters consistently.""" return ui.icon(icon=tag, class_name="shr
icons = { "All Content": "DragDropIcon", "AI Builder": "RoboticIcon", "Hosting": "CloudIcon", "Components": "BlockGameIcon", "Docs": "File01Icon", "Enterprise": "City02Icon", "API Reference": "ApiIcon", "Blog Posts": "BloggerIcon", }
rx.el.label( item, class_name=rx.cond( index == (items.length() - 1), "text-sm font-medium", "text-sm font-regular", ), color=rx.cond( index == (items.length() - 1), rx.color("slate", 12), rx.color("slate", 11), ), ), ), ), spacing="1", cursor="pointer", ) def cluster_icon(filter_name: str): icons = { "All Content": "DragDropIcon", "AI Builder": "RoboticIcon", "Hosting": "CloudIcon", "Components": "BlockGameIcon", "Docs": "File01Icon", "Enterprise": "City02Icon", "API Reference": "ApiIcon", "Blog Posts": "BloggerIcon", } return ui.icon(icon=icons.get(filter_name, ""), class_name="shrink-0 size-4")
def filter_icon(tag: str): """Helper to render icons for filters consistently.""" return ui.icon(icon=tag, class_name="shrink-0 size-3") def filter_component(): return ui.popover.root( ui.popover.trigger( ui.button( rx.el.div( rx.el.div( rx.match( SimpleSearch.selected_filter, ("All Content", filter_icon("DragDropIcon")), ("AI Builder", filter_icon("RoboticIcon")), ("Hosting", filter_icon("CloudIcon")), ("Components", filter_icon("BlockGameIcon")), ("Docs", filter_icon("File01Icon")), ("Enterprise", filter_icon("City02Icon")), ("API Reference", filter_icon("ApiIcon")), ("Blog Posts", filter_icon("BloggerIcon")), ),
def filter_items(filter_name: str): return ui.popover.close( rx.el.div( rx.el.div( cluster_icon(filter_name), rx.el.button( filter_name, class_name="w-full text-left", type="button", ), class_name="flex flex-row items-center gap-x-3", ), rx.cond( SimpleSearch.selected_filter == filter_name, rx.icon(tag="check", size=12), ), on_click=SimpleSearch.apply_filter_search(filter_name), class_name="flex flex-row gap-x-2 items-center px-3 py-1 w-full justify-between cursor-pointer outline-none hover:bg-slate-3 focus:border-none", ) )
: "File01Icon", "Enterprise": "City02Icon", "API Reference": "ApiIcon", "Blog Posts": "BloggerIcon", } return ui.icon(icon=icons.get(filter_name, ""), class_name="shrink-0 size-4") def filter_items(filter_name: str): return ui.popover.close( rx.el.div( rx.el.div( cluster_icon(filter_name), rx.el.button( filter_name, class_name="w-full text-left", type="button", ), class_name="flex flex-row items-center gap-x-3", ), rx.cond( SimpleSearch.selected_filter == filter_name, rx.icon(tag="check", size=12), ), on_click=SimpleSearch.apply_filter_search(filter_name), class_name="flex flex-row gap-x-2 items-center px-3 py-1 w-full justify-between cursor-pointer outline-none hover:bg-slate-3 focus:border-none", ) )
def filter_component(): return ui.popover.root( ui.popover.trigger( ui.button( rx.el.div( rx.el.div( rx.match( SimpleSearch.selected_filter, ("All Content", filter_icon("DragDropIcon")), ("AI Builder", filter_icon("RoboticIcon")), ("Hosting", filter_icon("CloudIcon")), ("Components", filter_icon("BlockGameIcon")), ("Docs", filter_icon("File01Icon")), ("Enterprise", filter_icon("City02Icon")), ("API Reference", filter_icon("ApiIcon")), ("Blog Posts", filter_icon("BloggerIcon")), ), SimpleSearch.selected_filter, class_name="text-sm flex flex-row items-center gap-x-2",
def filter_icon(tag: str): """Helper to render icons for filters consistently.""" return ui.icon(icon=tag, class_name="shrink-0 size-3")
on(icon=icons.get(filter_name, ""), class_name="shrink-0 size-4") def filter_items(filter_name: str): return ui.popover.close( rx.el.div( rx.el.div( cluster_icon(filter_name), rx.el.button( filter_name, class_name="w-full text-left", type="button", ), class_name="flex flex-row items-center gap-x-3", ), rx.cond( SimpleSearch.selected_filter == filter_name, rx.icon(tag="check", size=12), ), on_click=SimpleSearch.apply_filter_search(filter_name), class_name="flex flex-row gap-x-2 items-center px-3 py-1 w-full justify-between cursor-pointer outline-none hover:bg-slate-3 focus:border-none", ) ) def filter_icon(tag: str): """Helper to render icons for filters consistently.""" return ui.icon(icon=tag, class_name="shrink-0 size-3")
def search_input(): return rx.box( rx.box( rx.icon( tag="search", size=14, class_name="absolute left-2 top-1/2 transform -translate-y-1/2 !text-gray-500/40", ), rx.box( filter_component(), rx.link( ui.button( ui.icon(icon="SparklesIcon", class_name="shrink-0 size-2"), "Ask AI", type="button", variant="secondary", size="xs", class_name="text-sm flex flex-row gap-x-2 items-center", ), href="https://reflex.dev/docs/ai-builder/integrations/mcp-overview/", ), ui.button( "Esc", size="xs", type="button", variant="outline", on_click=rx
def filter_component(): return ui.popover.root( ui.popover.trigger( ui.button( rx.el.div( rx.el.div( rx.match( SimpleSearch.selected_filter, ("All Content", filter_icon("DragDropIcon")), ("AI Builder", filter_icon("RoboticIcon")), ("Hosting", filter_icon("CloudIcon")), ("Components", filter_icon("BlockGameIcon")), ("Docs", filter_icon("File01Icon")), ("Enterprise", filter_icon("City02Icon")), ("API Reference", filter_icon("ApiIcon")), ("Blog Posts", filter_icon("BloggerIcon")), ), SimpleSearch.selected_filter, class_name="text-sm flex flex-row items-center gap-x-2", ), ui.icon(icon="UnfoldMoreIcon", class_name="shrink-0 size-3"), class_name="flex flex-row items-center justify-between w-[150px] text-sm", ), class_name="flex flex-row justify-between items-center gap-x-4 rounded-md outline-none", type="button", variant="outline", size="xs", ), ), ui.popover.portal( ui.popover.positioner( ui.popover.popup( rx.box( *[filter_items(filter_name) for filter_name in CLUSTERS], class_name="w-[190px] flex flex-col text-sm rounded-md shadow-md gap-y-1 py-2", ), class_name="items-center !p-0 w-auto overflow-visible pointer-events-auto", ), side="bottom", side_offset=15, ), ), class_name="rounded-md border border-slate-5", id="my-popover", )
con", class_name="shrink-0 size-3"), class_name="flex flex-row items-center justify-between w-[150px] text-sm", ), class_name="flex flex-row justify-between items-center gap-x-4 rounded-md outline-none", type="button", variant="outline", size="xs", ), ), ui.popover.portal( ui.popover.positioner( ui.popover.popup( rx.box( *[filter_items(filter_name) for filter_name in CLUSTERS], class_name="w-[190px] flex flex-col text-sm rounded-md shadow-md gap-y-1 py-2", ), class_name="items-center !p-0 w-auto overflow-visible pointer-events-auto", ), side="bottom", side_offset=15, ), ), class_name="rounded-md border border-slate-5", id="my-popover", )
def copy_button(url: str): return ui.button( rx.cond( last_copied.value == url, ui.icon("CheckmarkCircle02Icon", class_name="size-2"), ui.icon("Share08Icon", size=10, class_name="size-2"), ), variant="outline", size="xs", on_click=[ rx.set_clipboard(url).prevent_default, rx.call_function(last_copied.set_value(url)), ], on_mouse_down=rx.call_function(last_copied.set_value("")).debounce(1500), ) def search_result(tags: list, value: dict): return rx.link( rx.box( rx.box( rx.text(value["name"], class_name="text-sm font-bold"), copy_button(url=f"https://reflex.dev/{value['url'].to(str)}"), class_name="flex flex-row items-center justify-between pr-1 w-full", ), rx.html( value["description"], class_name=( "text-sm font-r
def search_input(): return rx.box( rx.box( rx.icon( tag="search", size=14, class_name="absolute left-2 top-1/2 transform -translate-y-1/2 !text-gray-500/40", ), rx.box( filter_component(), rx.link( ui.button( ui.icon(icon="SparklesIcon", class_name="shrink-0 size-2"), "Ask AI", type="button", variant="secondary", size="xs", class_name="text-sm flex flex-row gap-x-2 items-center", ), href="https://reflex.dev/docs/ai-builder/integrations/mcp-overview/", ), ui.button( "Esc", size="xs", type="button", variant="outline", on_click=rx.run_script( "document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))" ), ), class_name="hidden md:flex absolute right-2 top-1/2 transform -translate-y-1/2 text-sm flex-row items-center gap-x-2", ), rx.el.input( on_change=[ lambda value: SimpleSearch.user_query(value).debounce(500), SimpleSearch.perform_search(), ], auto_focus=True, placeholder="Search documentation ...", class_name="py-2 pl-7 md:pr-[310px] w-full placeholder:text-sm text-sm rounded-lg outline-none focus:outline-none border border-secondary-a4 bg-secondary-1 text-secondary-12", ), class_name="w-full relative focus:outline-none", ), class_name="w-full flex flex-col absolute top-0 left-0 p-3 z-[999]", )
outline", on_click=rx.run_script( "document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))" ), ), class_name="hidden md:flex absolute right-2 top-1/2 transform -translate-y-1/2 text-sm flex-row items-center gap-x-2", ), rx.el.input( on_change=[ lambda value: SimpleSearch.user_query(value).debounce(500), SimpleSearch.perform_search(), ], auto_focus=True, placeholder="Search documentation ...", class_name="py-2 pl-7 md:pr-[310px] w-full placeholder:text-sm text-sm rounded-lg outline-none focus:outline-none border border-secondary-a4 bg-secondary-1 text-secondary-12", ), class_name="w-full relative focus:outline-none", ), class_name="w-full flex flex-col absolute top-0 left-0 p-3 z-[999]", )
def search_result(tags: list, value: dict): return rx.link( rx.box( rx.box( rx.text(value["name"], class_name="text-sm font-bold"), copy_button(url=f"https://reflex.dev/{value['url'].to(str)}"), class_name="flex flex-row items-center justify-between pr-1 w-full", ), rx.html( value["description"], class_name=( "text-sm font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), search_breadcrumb(tags), class_name="p-2 w-full flex flex-col gap-y-2 justify-start items-start align-start", ), href=f"/{value['url'].to(str)}", class_name="!tex
def copy_button(url: str): return ui.button( rx.cond( last_copied.value == url, ui.icon("CheckmarkCircle02Icon", class_name="size-2"), ui.icon("Share08Icon", size=10, class_name="size-2"), ), variant="outline", size="xs", on_click=[ rx.set_clipboard(url).prevent_default, rx.call_function(last_copied.set_value(url)), ], on_mouse_down=rx.call_function(last_copied.set_value("")).debounce(1500), )
h(), ], auto_focus=True, placeholder="Search documentation ...", class_name="py-2 pl-7 md:pr-[310px] w-full placeholder:text-sm text-sm rounded-lg outline-none focus:outline-none border border-secondary-a4 bg-secondary-1 text-secondary-12", ), class_name="w-full relative focus:outline-none", ), class_name="w-full flex flex-col absolute top-0 left-0 p-3 z-[999]", ) def copy_button(url: str): return ui.button( rx.cond( last_copied.value == url, ui.icon("CheckmarkCircle02Icon", class_name="size-2"), ui.icon("Share08Icon", size=10, class_name="size-2"), ), variant="outline", size="xs", on_click=[ rx.set_clipboard(url).prevent_default, rx.call_function(last_copied.set_value(url)), ], on_mouse_down=rx.call_function(last_copied.set_value("")).debounce(1500), )
def search_result_blog(value: dict): return rx.link( rx.box( rx.box( rx.box( rx.text(value["author"]), "-", rx.text(value["date"]), class_name="flex flex-row gap-x-2 items-center text-sm !text-slate-10", ), copy_button(url=f"https://reflex.dev{value['url'].to(str)}"), class_name="flex flex-row w-full items-center justify-between pr-1", ), rx.text(value["title"], class_name="text-md font-bold"), rx.text( value["description"], class_name=( "text-sm font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical",
def search_result(tags: list, value: dict): return rx.link( rx.box( rx.box( rx.text(value["name"], class_name="text-sm font-bold"), copy_button(url=f"https://reflex.dev/{value['url'].to(str)}"), class_name="flex flex-row items-center justify-between pr-1 w-full", ), rx.html( value["description"], class_name=( "text-sm font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), search_breadcrumb(tags), class_name="p-2 w-full flex flex-col gap-y-2 justify-start items-start align-start", ), href=f"/{value['url'].to(str)}", class_name="!text-inherit no-underline hover:!text-inherit hover:bg-secondary-2 group", )
x( rx.box( rx.text(value["name"], class_name="text-sm font-bold"), copy_button(url=f"https://reflex.dev/{value['url'].to(str)}"), class_name="flex flex-row items-center justify-between pr-1 w-full", ), rx.html( value["description"], class_name=( "text-sm font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), search_breadcrumb(tags), class_name="p-2 w-full flex flex-col gap-y-2 justify-start items-start align-start", ), href=f"/{value['url'].to(str)}", class_name="!text-inherit no-underline hover:!text-inherit hover:bg-secondary-2 group", )
def search_result_start(item: dict): return rx.link( rx.box( rx.box( rx.icon(tag=item["icon"], size=11, class_name="size-4 !text-slate-9"), rx.text(item["name"], class_name="text-sm font-bold"), class_name="flex flex-row items-center justify-start gap-x-2", ), rx.text( item["description"], class_name=( "text-xs font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), class_name="p-2 w-full flex flex-col gap-y-1 justify-start items-start align-start", ), href=item["path"], class_name="!text-inherit no-underline hover:!text-inherit rounded-md hove
def search_result_blog(value: dict): return rx.link( rx.box( rx.box( rx.box( rx.text(value["author"]), "-", rx.text(value["date"]), class_name="flex flex-row gap-x-2 items-center text-sm !text-slate-10", ), copy_button(url=f"https://reflex.dev{value['url'].to(str)}"), class_name="flex flex-row w-full items-center justify-between pr-1", ), rx.text(value["title"], class_name="text-md font-bold"), rx.text( value["description"], class_name=( "text-sm font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), rx.box( rx.image( src=value["image"].to(str), class_name="rounded-md", ), class_name="w-full rounded-[10px] pt-3", ), class_name="p-2 w-full flex flex-col gap-y-1 justify-start items-start align-start", ), href=f"{value['url'].to(str)}", class_name="!text-inherit no-underline hover:!text-inherit hover:bg-secondary-2", )
1", ), rx.text(value["title"], class_name="text-md font-bold"), rx.text( value["description"], class_name=( "text-sm font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), rx.box( rx.image( src=value["image"].to(str), class_name="rounded-md", ), class_name="w-full rounded-[10px] pt-3", ), class_name="p-2 w-full flex flex-col gap-y-1 justify-start items-start align-start", ), href=f"{value['url'].to(str)}", class_name="!text-inherit no-underline hover:!text-inherit hover:bg-secondary-2", )
def no_results_found(): return rx.box( rx.el.p( rx.fragment( "No results found for ", rx.el.strong(f"'{SimpleSearch.query}'"), ), ), class_name="w-full flex items-center justify-center text-sm py-4", ) def searching_in_progress(): return rx.box( rx.el.p( rx.fragment( "Searching for ", rx.el.strong(f"'{SimpleSearch.query}'"), "...", ), ), class_name="w-full flex items-center justify-center text-sm py-4", ) def search_content(): return rx.scroll_area( rx.cond( SimpleSearch.query.length() < 3, rx.box( rx.foreach(suggestion_items, lambda value: search_result_start(value)), class_name="flex flex-col gap-y-2", ), rx.cond( SimpleSearch.is_fetching, rx.cond(
def search_result_start(item: dict): return rx.link( rx.box( rx.box( rx.icon(tag=item["icon"], size=11, class_name="size-4 !text-slate-9"), rx.text(item["name"], class_name="text-sm font-bold"), class_name="flex flex-row items-center justify-start gap-x-2", ), rx.text( item["description"], class_name=( "text-xs font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), class_name="p-2 w-full flex flex-col gap-y-1 justify-start items-start align-start", ), href=item["path"], class_name="!text-inherit no-underline hover:!text-inherit rounded-md hover:bg-secondary-2", )
item: dict): return rx.link( rx.box( rx.box( rx.icon(tag=item["icon"], size=11, class_name="size-4 !text-slate-9"), rx.text(item["name"], class_name="text-sm font-bold"), class_name="flex flex-row items-center justify-start gap-x-2", ), rx.text( item["description"], class_name=( "text-xs font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), class_name="p-2 w-full flex flex-col gap-y-1 justify-start items-start align-start", ), href=item["path"], class_name="!text-inherit no-underline hover:!text-inherit rounded-md hover:bg-secondary-2", )
def searching_in_progress(): return rx.box( rx.el.p( rx.fragment( "Searching for ", rx.el.strong(f"'{SimpleSearch.query}'"), "...", ), ), class_name="w-full flex items-center justify-center text-sm py-4", ) def search_content(): return rx.scroll_area( rx.cond( SimpleSearch.query.length() < 3, rx.box( rx.foreach(suggestion_items, lambda value: search_result_start(value)), class_name="flex flex-col gap-y-2", ), rx.cond( SimpleSearch.is_fetching, rx.cond( (SimpleSearch.idxed_docs_results.length() >= 1) | (SimpleSearch.idxed_blogs_results.length() >= 1), rx.box( rx.box( rx.foreach( SimpleSearch.idxed_docs_results,
def no_results_found(): return rx.box( rx.el.p( rx.fragment( "No results found for ", rx.el.strong(f"'{SimpleSearch.query}'"), ), ), class_name="w-full flex items-center justify-center text-sm py-4", )
art gap-x-2", ), rx.text( item["description"], class_name=( "text-xs font-regular opacity-[0.81] " "line-clamp-2 overflow-hidden text-ellipsis" ), style={ "display": "-webkit-box", "-webkit-line-clamp": "2", "-webkit-box-orient": "vertical", }, ), class_name="p-2 w-full flex flex-col gap-y-1 justify-start items-start align-start", ), href=item["path"], class_name="!text-inherit no-underline hover:!text-inherit rounded-md hover:bg-secondary-2", ) def no_results_found(): return rx.box( rx.el.p( rx.fragment( "No results found for ", rx.el.strong(f"'{SimpleSearch.query}'"), ), ), class_name="w-full flex items-center justify-center text-sm py-4", )
def search_content(): return rx.scroll_area( rx.cond( SimpleSearch.query.length() < 3, rx.box( rx.foreach(suggestion_items, lambda value: search_result_start(value)), class_name="flex flex-col gap-y-2", ), rx.cond( SimpleSearch.is_fetching, rx.cond( (SimpleSearch.idxed_docs_results.length() >= 1) | (SimpleSearch.idxed_blogs_results.length() >= 1), rx.box( rx.box( rx.foreach( SimpleSearch.idxed_docs_results, lambda value: search_result( value["parts"].to(list), value ), ), class_name="flex flex-col gap-y-2", ), rx.box(
def searching_in_progress(): return rx.box( rx.el.p( rx.fragment( "Searching for ", rx.el.strong(f"'{SimpleSearch.query}'"), "...", ), ), class_name="w-full flex items-center justify-center text-sm py-4", )
rx.foreach( SimpleSearch.idxed_docs_results, lambda value: search_result( value["parts"].to(list), value ), ), class_name="flex flex-col gap-y-2", ), rx.box( rx.foreach( SimpleSearch.idxed_blogs_results, lambda value: search_result_blog(value), ), class_name="flex flex-col gap-y-2", ), class_name="flex flex-col", ), no_results_found(), ), ), ), class_name="w-full h-full pt-11 [&_.rt-ScrollAreaScrollbar]:mr-[0.1875rem] [&_.rt-ScrollAreaScrollbar]:mt-[3rem]", )
def typesense_search() -> rx.Component: """Create the main search component for Reflex Web.""" return rx.fragment( rx.dialog.root( rx.dialog.trigger(search_trigger(), id="search-trigger"), rx.dialog.content( search_input(), search_content(), on_interact_outside=SimpleSearch.reset_search, on_escape_key_down=SimpleSearch.reset_search, class_name="w-full max-w-[650px] mx-auto bg-secondary-1 border-none outline-none p-3 lg:!fixed lg:!top-24 lg:!left-1/2 lg:!transform lg:!-translate-x-1/2 lg:!translate-y-0 lg:!m-0 " + rx.cond(SimpleSearch.query.length() < 3, "min-h[57vh]", "h-[57vh]"), ), ), keyboard_shortcut_script(), class_name="w-full", )
from reflex.style import toggle_color_mode from pcweb.components.icons import get_icon def color() -> rx.Component: return rx.el.button( rx.color_mode.icon( light_component=get_icon("sun", class_name="shrink-0 !text-slate-9"), dark_component=get_icon("moon", class_name="shrink-0 !text-slate-9"), ), on_click=toggle_color_mode, custom_attrs={"aria-label": "Toggle color mode"}, class_name="hover:bg-slate-3 size-8 text-slate-9 flex justify-center items-center rounded-[10px] border border-slate-5 bg-slate-1 transition-bg cursor-pointer shadow-large py-0.5 px-3", )
import reflex as rx
import reflex as rx
from pcweb.components.icons import get_icon def color() -> rx.Component: return rx.el.button( rx.color_mode.icon( light_component=get_icon("sun", class_name="shrink-0 !text-slate-9"), dark_component=get_icon("moon", class_name="shrink-0 !text-slate-9"), ), on_click=toggle_color_mode, custom_attrs={"aria-label": "Toggle color mode"}, class_name="hover:bg-slate-3 size-8 text-slate-9 flex justify-center items-center rounded-[10px] border border-slate-5 bg-slate-1 transition-bg cursor-pointer shadow-large py-0.5 px-3", )
from reflex.style import toggle_color_mode
import reflex as rx from reflex.style import toggle_color_mode
def color() -> rx.Component: return rx.el.button( rx.color_mode.icon( light_component=get_icon("sun", class_name="shrink-0 !text-slate-9"), dark_component=get_icon("moon", class_name="shrink-0 !text-slate-9"), ), on_click=toggle_color_mode, custom_attrs={"aria-label": "Toggle color mode"}, class_name="hover:bg-slate-3 size-8 text-slate-9 flex justify-center items-center rounded-[10px] border border-slate-5 bg-slate-1 transition-bg cursor-pointer shadow-large py-0.5 px-3", )
from pcweb.components.icons import get_icon
import reflex_ui as ui from pcweb.components.icons.icons import get_icon from pcweb.constants import DISCORD_URL def discord() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="discord_navbar", class_name="shrink-0 text-secondary-11"), custom_attrs={"aria-label": "Discord link"}, size="icon-sm", variant="outline", class_name="text-secondary-11", ), to=DISCORD_URL, )
import reflex as rx
import reflex as rx
from pcweb.components.icons.icons import get_icon from pcweb.constants import DISCORD_URL def discord() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="discord_navbar", class_name="shrink-0 text-secondary-11"), custom_attrs={"aria-label": "Discord link"}, size="icon-sm", variant="outline", class_name="text-secondary-11", ), to=DISCORD_URL, )
import reflex_ui as ui
import reflex as rx import reflex_ui as ui
from pcweb.constants import DISCORD_URL def discord() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="discord_navbar", class_name="shrink-0 text-secondary-11"), custom_attrs={"aria-label": "Discord link"}, size="icon-sm", variant="outline", class_name="text-secondary-11", ), to=DISCORD_URL, )
from pcweb.components.icons.icons import get_icon
import reflex as rx import reflex_ui as ui from pcweb.components.icons.icons import get_icon
def discord() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="discord_navbar", class_name="shrink-0 text-secondary-11"), custom_attrs={"aria-label": "Discord link"}, size="icon-sm", variant="outline", class_name="text-secondary-11", ), to=DISCORD_URL, )
from pcweb.constants import DISCORD_URL
import reflex_ui as ui from pcweb.components.icons.icons import get_icon from pcweb.constants import GITHUB_STARS, GITHUB_URL def github() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="github_navbar", class_name="shrink-0 text-secondary-11"), f"{GITHUB_STARS // 1000}K", custom_attrs={"aria-label": "Github link"}, size="sm", variant="outline", class_name="text-secondary-11", ), to=GITHUB_URL, )
import reflex as rx
import reflex as rx
from pcweb.components.icons.icons import get_icon from pcweb.constants import GITHUB_STARS, GITHUB_URL def github() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="github_navbar", class_name="shrink-0 text-secondary-11"), f"{GITHUB_STARS // 1000}K", custom_attrs={"aria-label": "Github link"}, size="sm", variant="outline", class_name="text-secondary-11", ), to=GITHUB_URL, )
import reflex_ui as ui
import reflex as rx import reflex_ui as ui
from pcweb.constants import GITHUB_STARS, GITHUB_URL def github() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="github_navbar", class_name="shrink-0 text-secondary-11"), f"{GITHUB_STARS // 1000}K", custom_attrs={"aria-label": "Github link"}, size="sm", variant="outline", class_name="text-secondary-11", ), to=GITHUB_URL, )
from pcweb.components.icons.icons import get_icon
import reflex as rx import reflex_ui as ui from pcweb.components.icons.icons import get_icon
def github() -> rx.Component: return ui.link( render_=ui.button( get_icon(icon="github_navbar", class_name="shrink-0 text-secondary-11"), f"{GITHUB_STARS // 1000}K", custom_attrs={"aria-label": "Github link"}, size="sm", variant="outline", class_name="text-secondary-11", ), to=GITHUB_URL, )
from pcweb.constants import GITHUB_STARS, GITHUB_URL
import reflex as rx
from pcweb.components.icons.icons import get_icon from pcweb.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL from pcweb.pages.blog import blogs from pcweb.pages.docs import getting_started from pcweb.pages.docs.library import library from pcweb.pages.framework.framework import framework from pcweb.pages.gallery import gallery from pcweb.pages.hosting.hosting import hosting_landing def social_menu_item( icon: str, url="/", border: bool = False, ) -> rx.Component: return rx.link( get_icon(icon=icon, class_name="!text-slate-9"), class_name="flex justify-center items-center gap-2 hover:bg-slate-3 px-4 py-[0.875rem] w-full h-[47px] transition-bg overflow-hidden" + (" border-slate-4 border-x border-solid border-y-0" if border else ""), href=url, is_external=True, ) def drawer_socials() -> rx.Component: return rx.box( social_menu_item("github", GITHUB_URL), social_menu_item( "twitter",
from reflex.style import toggle_color_mode
import reflex as rx from reflex.style import toggle_color_mode
from pcweb.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL from pcweb.pages.blog import blogs from pcweb.pages.docs import getting_started from pcweb.pages.docs.library import library from pcweb.pages.framework.framework import framework from pcweb.pages.gallery import gallery from pcweb.pages.hosting.hosting import hosting_landing def social_menu_item( icon: str, url="/", border: bool = False, ) -> rx.Component: return rx.link( get_icon(icon=icon, class_name="!text-slate-9"), class_name="flex justify-center items-center gap-2 hover:bg-slate-3 px-4 py-[0.875rem] w-full h-[47px] transition-bg overflow-hidden" + (" border-slate-4 border-x border-solid border-y-0" if border else ""), href=url, is_external=True, ) def drawer_socials() -> rx.Component: return rx.box( social_menu_item("github", GITHUB_URL), social_menu_item( "twitter", TWITTER_URL, border=True,
from pcweb.components.icons.icons import get_icon
import reflex as rx from reflex.style import toggle_color_mode from pcweb.components.icons.icons import get_icon
from pcweb.pages.blog import blogs from pcweb.pages.docs import getting_started from pcweb.pages.docs.library import library from pcweb.pages.framework.framework import framework from pcweb.pages.gallery import gallery from pcweb.pages.hosting.hosting import hosting_landing def social_menu_item( icon: str, url="/", border: bool = False, ) -> rx.Component: return rx.link( get_icon(icon=icon, class_name="!text-slate-9"), class_name="flex justify-center items-center gap-2 hover:bg-slate-3 px-4 py-[0.875rem] w-full h-[47px] transition-bg overflow-hidden" + (" border-slate-4 border-x border-solid border-y-0" if border else ""), href=url, is_external=True, ) def drawer_socials() -> rx.Component: return rx.box( social_menu_item("github", GITHUB_URL), social_menu_item( "twitter", TWITTER_URL, border=True, ), social_menu_item("discord", DISCORD_URL), c
from pcweb.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL
import reflex as rx from reflex.style import toggle_color_mode from pcweb.components.icons.icons import get_icon from pcweb.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL
from pcweb.pages.docs import getting_started from pcweb.pages.docs.library import library from pcweb.pages.framework.framework import framework from pcweb.pages.gallery import gallery from pcweb.pages.hosting.hosting import hosting_landing def social_menu_item( icon: str, url="/", border: bool = False, ) -> rx.Component: return rx.link( get_icon(icon=icon, class_name="!text-slate-9"), class_name="flex justify-center items-center gap-2 hover:bg-slate-3 px-4 py-[0.875rem] w-full h-[47px] transition-bg overflow-hidden" + (" border-slate-4 border-x border-solid border-y-0" if border else ""), href=url, is_external=True, ) def drawer_socials() -> rx.Component: return rx.box( social_menu_item("github", GITHUB_URL), social_menu_item( "twitter", TWITTER_URL, border=True, ), social_menu_item("discord", DISCORD_URL), class_name="flex flex-row items-cent
from pcweb.pages.blog import blogs
import reflex as rx from reflex.style import toggle_color_mode from pcweb.components.icons.icons import get_icon from pcweb.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL from pcweb.pages.blog import blogs
from pcweb.pages.docs.library import library from pcweb.pages.framework.framework import framework from pcweb.pages.gallery import gallery from pcweb.pages.hosting.hosting import hosting_landing def social_menu_item( icon: str, url="/", border: bool = False, ) -> rx.Component: return rx.link( get_icon(icon=icon, class_name="!text-slate-9"), class_name="flex justify-center items-center gap-2 hover:bg-slate-3 px-4 py-[0.875rem] w-full h-[47px] transition-bg overflow-hidden" + (" border-slate-4 border-x border-solid border-y-0" if border else ""), href=url, is_external=True, ) def drawer_socials() -> rx.Component: return rx.box( social_menu_item("github", GITHUB_URL), social_menu_item( "twitter", TWITTER_URL, border=True, ), social_menu_item("discord", DISCORD_URL), class_name="flex flex-row items-center border-slate-4 border-y-0 !border-b w-full
from pcweb.pages.docs import getting_started
import reflex as rx from reflex.style import toggle_color_mode from pcweb.components.icons.icons import get_icon from pcweb.constants import DISCORD_URL, GITHUB_URL, TWITTER_URL from pcweb.pages.blog import blogs from pcweb.pages.docs import getting_started
from pcweb.pages.framework.framework import framework from pcweb.pages.gallery import gallery from pcweb.pages.hosting.hosting import hosting_landing def social_menu_item( icon: str, url="/", border: bool = False, ) -> rx.Component: return rx.link( get_icon(icon=icon, class_name="!text-slate-9"), class_name="flex justify-center items-center gap-2 hover:bg-slate-3 px-4 py-[0.875rem] w-full h-[47px] transition-bg overflow-hidden" + (" border-slate-4 border-x border-solid border-y-0" if border else ""), href=url, is_external=True, ) def drawer_socials() -> rx.Component: return rx.box( social_menu_item("github", GITHUB_URL), social_menu_item( "twitter", TWITTER_URL, border=True, ), social_menu_item("discord", DISCORD_URL), class_name="flex flex-row items-center border-slate-4 border-y-0 !border-b w-full", ) def drawer_item(text: str, url: st
from pcweb.pages.docs.library import library