Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion graphiti_core/driver/neo4j/operations/search_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def _build_neo4j_fulltext_query(
for f in group_ids_filter_list:
group_ids_filter += f if not group_ids_filter else f' OR {f}'

group_ids_filter += ' AND ' if group_ids_filter else ''
# Wrap the OR-chain in parens before AND-ing the query terms. Without parens, Lucene's
# AND > OR precedence binds the terms to only the LAST group_id clause, so a multi-group
# full-text search collapses to that group alone. Parenthesizing applies the terms across
# all groups.
group_ids_filter = f'({group_ids_filter}) AND ' if group_ids_filter else ''

lucene_query = lucene_sanitize(query)
if len(lucene_query.split(' ')) + len(group_ids or '') >= max_query_length:
Expand Down
6 changes: 5 additions & 1 deletion graphiti_core/search/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def fulltext_query(query: str, group_ids: list[str] | None, driver: GraphDriver)
for f in group_ids_filter_list:
group_ids_filter += f if not group_ids_filter else f' OR {f}'

group_ids_filter += ' AND ' if group_ids_filter else ''
# Wrap the OR-chain in parens before AND-ing the query terms. Without parens, Lucene's
# AND > OR precedence binds the terms to only the LAST group_id clause, so a multi-group
# full-text search collapses to that group alone (zeroing bm25-only episode search when the
# last group is empty/non-matching). Parenthesizing applies the terms across all groups.
group_ids_filter = f'({group_ids_filter}) AND ' if group_ids_filter else ''

lucene_query = lucene_sanitize(query)
# If the lucene query is too long return no query
Expand Down
Loading