SOLR-18664: Add expandFilter to the graph query parser #5356
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 640 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.387
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5356"
general
weight: 0.35
nick-boss-tech
https://issues.apache.org/jira/browse/SOLR-18664
Description
{!graph}does a breadth-first traversal: at each hop it reads thetofield of every collected document and adds those values to the query used to find the next level,from IN (...). There is no way to collect a node without also expanding it.In a file/folder hierarchy (
{!graph from=parentId to=id traversalFilter=name:prefix}), only folders can have children, but every file'sidstill becomes a frontier term. Each one costs a docValues read, a hash insert and a terms-dictionary seek per segment, and can never match.traversalFilter=docType:folderwould drop the files from the results. The existing leaf-node optimization doesn't help either, because it only skips documents with no value into, and here every document has one.Solution
A new optional
expandFilterlocal param. Documents reached by the traversal (and matchingtraversalFilter) are always collected, but only those that also matchexpandFilterhave their edges followed. It applies at every level, including the root. Without the param, behaviour is unchanged.GraphQuerygets the filter's DocSet once per request (via the filterCache) and passes it to the edge collectors.GraphEdgeCollector.collect()checks it only before extracting edges; collection itself is unconditional.graphdomain goes throughGraphQueryParser, so it supports the param too.expandFilterentry in the graph query parser parameters.This change was developed with Claude Code (implementation, tests and benchmark); root cause analyzed and changes reviewed by me.
Benchmark
Synthetic 1M-doc file-system index: 80k folders, 920k files (~11.5 files per folder), depth up to 15. JDK 21, 4 GB heap, standalone,
rows=0, queryResultCache disabled so every query does the full traversal. Each session ran in a fresh JVM with 10 warmup + 30 measured iterations per root and arm, interleaved. Session order: patched, baseline (unpatched build of the same commit), patched.The query was run from 18 starting folders whose results range from ~100 documents to the whole tree. Each row covers folders that return a similar number of documents (shown as the average
numFound). For each folder we take the median QTime (in ms) of its 60 runs; the row shows the geometric mean of those medians:| Docs returned (avg
numFound) | Starting folders | WithoutexpandFilter(ms) | WithexpandFilter=docType:folder(ms) | Speedup (same build) ||---|---|---|---|---|
| 101 | 3 | 2.6 | 1.3 | 2.1×\ |
| 884 | 3 | 7.6 | 2.3 | 3.3×\ |
| 10,214 | 3 | 53 | 7.8 | 6.8× |
| 42,546 | 3 | 174 | 24 | 7.4× |
| 93,708 | 3 | 349 | 42 | 8.3× |
| 217,834 | 2 | 656 | 73 | 8.9× |
| 828,781 (whole tree) | 1 | 3,038 | 298 | 10.2× |
\ QTime is reported in whole milliseconds, so these two rows are coarse (due to rounding).
numFoundcomputed independently from the generated tree, and all variants agree.Tests
GraphQueryTest.doGraph()(runs across the existing string, docValues-only string and int/long/float/double point field matrix, so both collectors are covered):- a node with children that doesn't match
expandFilteris returned but not expanded;- a pure-negative
expandFilter;- a root that doesn't match only returns the root;
- combined with
traversalFilter;- combined with
maxDepthandreturnRoot=false../gradlew tidy,./gradlew check -x test,TestJsonFacetsand allorg.apache.solr.search.join.*tests.Checklist
mainbranch../gradlew check.🤖 Generated with Claude Code