Initial upload: snippet-manager with CI/CD workflow
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled

This commit is contained in:
2026-03-22 11:22:27 +00:00
parent d8bc8a44ee
commit c228ac3da0

28
snip/search/engine.py Normal file
View File

@@ -0,0 +1,28 @@
"""FTS5 search engine for snippets."""
from typing import Any
from snip.db.database import Database
class SearchEngine:
def __init__(self, db: Database):
self.db = db
def search(
self,
query: str,
limit: int = 50,
language: str | None = None,
tag: str | None = None,
) -> list[dict[str, Any]]:
"""Search snippets using FTS5."""
return self.db.search_snippets(query, limit=limit, language=language, tag=tag)
def highlight(self, text: str, query: str) -> str:
"""Add highlighting markers around matched terms."""
terms = query.split()
result = text
for term in terms:
result = result.replace(term, f"**{term}**")
return result