3131 SearchIndexKey ,
3232 SearchIndexRow ,
3333 capped_snippet_columns ,
34+ snippet_length_columns ,
3435)
3536from basic_memory .repository .search_query import (
3637 PreparedSearchQuery ,
4849# tsquery special characters that must not reach the parser as text.
4950_TSQUERY_SPECIAL_CHARS = ("&" , "|" , "!" , "(" , ")" , ":" )
5051
51- # Every FTS statement returns these columns plus a score.
52- _RESULT_COLUMNS = f"""
52+
53+ def _result_columns (text_columns : str ) -> str :
54+ """The columns every FTS statement returns, plus a score."""
55+ return f"""
5356 search_index.project_id,
5457 search_index.id,
5558 search_index.title,
6164 search_index.to_id,
6265 search_index.relation_type,
6366 search_index.entity_id,
64- { capped_snippet_columns ( "search_index" ) } ,
67+ { text_columns } ,
6568 search_index.category,
6669 search_index.created_at,
6770 search_index.updated_at"""
@@ -712,6 +715,7 @@ async def search(
712715 session : AsyncSession | None = None ,
713716 candidate_keys : Sequence [SearchIndexKey ] | None = None ,
714717 trace : SearchTraceCollector | None = None ,
718+ with_text : bool = True ,
715719 ) -> list [SearchIndexRow ]:
716720 """Run one tsquery page, retrying a malformed or empty strict query relaxed."""
717721 search_text = query .search_text
@@ -721,9 +725,14 @@ async def search(
721725 params = compiled .params
722726 params ["limit" ] = limit
723727 params ["offset" ] = offset
728+ text_columns = (
729+ capped_snippet_columns ("search_index" )
730+ if with_text
731+ else snippet_length_columns ("search_index" )
732+ )
724733
725734 sql = f"""
726- SELECT{ _RESULT_COLUMNS } ,
735+ SELECT{ _result_columns ( text_columns ) } ,
727736 { compiled .score_expression } as score
728737 FROM { compiled .from_clause }
729738 WHERE { compiled .where_clause }
0 commit comments