Skip to content

Commit 4734d10

Browse files
committed
fix(fpf): preserve routed seeds in tree drilldown
1 parent f3e1a9b commit 4734d10

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

internal/fpf/specsearch_drilldown.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type drillDownBranch struct {
3232
Path []drillDownSection
3333
Score int
3434
SeedOrder int
35+
SeedTier string
3536
}
3637

3738
func searchTreeDrillDown(db *sql.DB, query string, limit int) ([]SpecSearchResult, error) {
@@ -169,6 +170,7 @@ func buildDrillDownBranches(
169170
Path: path,
170171
Score: scoreDrillDownPath(path, queryTokens, seedOrder),
171172
SeedOrder: seedOrder,
173+
SeedTier: seed.Tier,
172174
})
173175
}
174176

@@ -222,6 +224,16 @@ func sortDrillDownBranches(branches []drillDownBranch) {
222224
}
223225

224226
func drillDownBranchLess(left, right drillDownBranch) bool {
227+
leftSeedPriority := drillDownSeedPriority(left.SeedTier)
228+
rightSeedPriority := drillDownSeedPriority(right.SeedTier)
229+
if leftSeedPriority != rightSeedPriority {
230+
return leftSeedPriority < rightSeedPriority
231+
}
232+
233+
return drillDownBranchScoreLess(left, right)
234+
}
235+
236+
func drillDownBranchScoreLess(left, right drillDownBranch) bool {
225237
if left.Score != right.Score {
226238
return left.Score > right.Score
227239
}
@@ -234,6 +246,17 @@ func drillDownBranchLess(left, right drillDownBranch) bool {
234246
return left.LeafPatternID < right.LeafPatternID
235247
}
236248

249+
func drillDownSeedPriority(seedTier string) int {
250+
switch seedTier {
251+
case SpecSearchTierPattern:
252+
return 0
253+
case SpecSearchTierFTS:
254+
return 1
255+
default:
256+
return 2
257+
}
258+
}
259+
237260
func buildDrillDownResults(branches []drillDownBranch, limit int) []SpecSearchResult {
238261
if limit <= 0 {
239262
limit = DefaultSpecSearchLimit

internal/fpf/tree_drilldown_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,74 @@ func TestSearchSpecWithOptions_TreeModeReturnsLeafBeforeAncestors(t *testing.T)
6262
}
6363
}
6464

65+
func TestDrillDownRouteSeedsStayAheadOfFTSLeaves(t *testing.T) {
66+
section := func(patternID string, parentPatternID string) drillDownSection {
67+
return drillDownSection{
68+
PatternID: patternID,
69+
Heading: patternID,
70+
Summary: patternID,
71+
ParentPatternID: parentPatternID,
72+
}
73+
}
74+
75+
branches := []drillDownBranch{
76+
{
77+
LeafPatternID: "A.6.3.CR",
78+
Path: []drillDownSection{
79+
section("A.6.3.CR", ""),
80+
},
81+
Score: 4,
82+
SeedOrder: 0,
83+
SeedTier: SpecSearchTierPattern,
84+
},
85+
{
86+
LeafPatternID: "E.17.EFP",
87+
Path: []drillDownSection{
88+
section("E.17.EFP", ""),
89+
},
90+
Score: 3,
91+
SeedOrder: 1,
92+
SeedTier: SpecSearchTierPattern,
93+
},
94+
{
95+
LeafPatternID: "A.6.3",
96+
Path: []drillDownSection{
97+
section("A.6.3", ""),
98+
},
99+
Score: 2,
100+
SeedOrder: 2,
101+
SeedTier: SpecSearchTierPattern,
102+
},
103+
{
104+
LeafPatternID: "A.6.3.RT",
105+
Path: []drillDownSection{
106+
section("A.6.3.RT", ""),
107+
},
108+
Score: 1,
109+
SeedOrder: 3,
110+
SeedTier: SpecSearchTierPattern,
111+
},
112+
{
113+
LeafPatternID: "A.6.3.CR:2",
114+
Path: []drillDownSection{
115+
section("A.6.3.CR:2", "A.6.3.CR"),
116+
section("A.6.3.CR", ""),
117+
},
118+
Score: 1000,
119+
SeedOrder: 4,
120+
SeedTier: SpecSearchTierFTS,
121+
},
122+
}
123+
124+
sortDrillDownBranches(branches)
125+
results := buildDrillDownResults(branches, 4)
126+
got := resultPatternIDs(results)
127+
want := []string{"A.6.3.CR", "E.17.EFP", "A.6.3", "A.6.3.RT"}
128+
if !reflect.DeepEqual(got, want) {
129+
t.Fatalf("drill-down results = %v, want %v", got, want)
130+
}
131+
}
132+
65133
func TestSearchSpecWithOptions_DrillDownTierFilterKeepsOnlyExperimentalHits(t *testing.T) {
66134
chunks := []SpecChunk{
67135
{

0 commit comments

Comments
 (0)