feat(notes): _strip_type_nouns helper for search query sanitization

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 16:40:54 -04:00
parent 0fbb1fbd92
commit 42c11dedae
2 changed files with 37 additions and 0 deletions
+11
View File
@@ -22,6 +22,17 @@ def _normalize_tags(tags: list[str]) -> list[str]:
return out
# Type-nouns the LLM tends to include in search queries. Treating them as
# required ILIKE terms drops literal-title matches; we strip them server-side
# and let the `type` / `project` parameters scope results instead.
_SEARCH_TYPE_NOUNS = {"task", "tasks", "note", "notes", "project", "projects"}
def _strip_type_nouns(q: str) -> list[str]:
"""Return q's tokens with type-nouns removed (case-insensitive)."""
return [t for t in q.split() if t.lower() not in _SEARCH_TYPE_NOUNS]
async def _maybe_reactivate_project(project_id: int) -> None:
"""If a project is paused, reactivate it — activity indicates resumed work."""
from fabledassistant.models.project import Project
+26
View File
@@ -28,3 +28,29 @@ async def test_search_projects_tool_returns_success_true():
assert result["success"] is True
assert result["type"] == "projects_list"
assert len(result["data"]["projects"]) == 1
def test_strip_type_nouns_removes_task_word():
from fabledassistant.services.notes import _strip_type_nouns
assert _strip_type_nouns("sebring secondary task") == ["sebring", "secondary"]
def test_strip_type_nouns_removes_all_variants():
from fabledassistant.services.notes import _strip_type_nouns
assert _strip_type_nouns("project notes task") == []
def test_strip_type_nouns_case_insensitive():
from fabledassistant.services.notes import _strip_type_nouns
assert _strip_type_nouns("Sebring Task NOTES") == ["Sebring"]
def test_strip_type_nouns_preserves_real_content_words():
from fabledassistant.services.notes import _strip_type_nouns
assert _strip_type_nouns("circuit configuration") == ["circuit", "configuration"]
def test_strip_type_nouns_handles_empty_string():
from fabledassistant.services.notes import _strip_type_nouns
assert _strip_type_nouns("") == []
assert _strip_type_nouns(" ") == []