@@ -4,12 +4,12 @@ import {
4
4
DeclarationReflection ,
5
5
CommentTag ,
6
6
} from "../../models" ;
7
- import { ReflectionCategory } from "../../models/ReflectionCategory " ;
7
+ import { ReflectionCategory } from "../../models" ;
8
8
import { Component , ConverterComponent } from "../components" ;
9
9
import { Converter } from "../converter" ;
10
10
import type { Context } from "../context" ;
11
11
import { BindOption } from "../../utils" ;
12
- import type { Comment } from "../../models/comments/index " ;
12
+ import type { Comment } from "../../models" ;
13
13
14
14
/**
15
15
* A handler that sorts and categorizes the found reflections in the resolving phase.
@@ -66,9 +66,12 @@ export class CategoryPlugin extends ConverterComponent {
66
66
* @param context The context object describing the current state the converter is in.
67
67
* @param reflection The reflection that is currently resolved.
68
68
*/
69
- private onResolve ( _context : Context , reflection : Reflection ) {
69
+ private onResolve ( context : Context , reflection : Reflection ) {
70
70
if ( reflection instanceof ContainerReflection ) {
71
- this . categorize ( reflection ) ;
71
+ this . categorize (
72
+ reflection ,
73
+ context . getSearchOptions ( ) . boosts ?. byCategory ?? { }
74
+ ) ;
72
75
}
73
76
}
74
77
@@ -79,26 +82,36 @@ export class CategoryPlugin extends ConverterComponent {
79
82
*/
80
83
private onEndResolve ( context : Context ) {
81
84
const project = context . project ;
82
- this . categorize ( project ) ;
85
+ this . categorize (
86
+ project ,
87
+ context . getSearchOptions ( ) . boosts ?. byCategory ?? { }
88
+ ) ;
83
89
}
84
90
85
- private categorize ( obj : ContainerReflection ) {
91
+ private categorize (
92
+ obj : ContainerReflection ,
93
+ categorySearchBoosts : { [ key : string ] : number }
94
+ ) {
86
95
if ( this . categorizeByGroup ) {
87
- this . groupCategorize ( obj ) ;
96
+ this . groupCategorize ( obj , categorySearchBoosts ) ;
88
97
} else {
89
- this . lumpCategorize ( obj ) ;
98
+ CategoryPlugin . lumpCategorize ( obj , categorySearchBoosts ) ;
90
99
}
91
100
}
92
101
93
- private groupCategorize ( obj : ContainerReflection ) {
102
+ private groupCategorize (
103
+ obj : ContainerReflection ,
104
+ categorySearchBoosts : { [ key : string ] : number }
105
+ ) {
94
106
if ( ! obj . groups || obj . groups . length === 0 ) {
95
107
return ;
96
108
}
97
109
obj . groups . forEach ( ( group ) => {
98
110
if ( group . categories ) return ;
99
111
100
112
group . categories = CategoryPlugin . getReflectionCategories (
101
- group . children
113
+ group . children ,
114
+ categorySearchBoosts
102
115
) ;
103
116
if ( group . categories && group . categories . length > 1 ) {
104
117
group . categories . sort ( CategoryPlugin . sortCatCallback ) ;
@@ -112,11 +125,17 @@ export class CategoryPlugin extends ConverterComponent {
112
125
} ) ;
113
126
}
114
127
115
- private lumpCategorize ( obj : ContainerReflection ) {
128
+ static lumpCategorize (
129
+ obj : ContainerReflection ,
130
+ categorySearchBoosts : { [ key : string ] : number }
131
+ ) {
116
132
if ( ! obj . children || obj . children . length === 0 || obj . categories ) {
117
133
return ;
118
134
}
119
- obj . categories = CategoryPlugin . getReflectionCategories ( obj . children ) ;
135
+ obj . categories = CategoryPlugin . getReflectionCategories (
136
+ obj . children ,
137
+ categorySearchBoosts
138
+ ) ;
120
139
if ( obj . categories && obj . categories . length > 1 ) {
121
140
obj . categories . sort ( CategoryPlugin . sortCatCallback ) ;
122
141
} else if (
@@ -132,10 +151,13 @@ export class CategoryPlugin extends ConverterComponent {
132
151
* Create a categorized representation of the given list of reflections.
133
152
*
134
153
* @param reflections The reflections that should be categorized.
154
+ * @param categorySearchBoosts A user-supplied map of category titles, for computing a
155
+ * relevance boost to be used when searching
135
156
* @returns An array containing all children of the given reflection categorized
136
157
*/
137
158
static getReflectionCategories (
138
- reflections : DeclarationReflection [ ]
159
+ reflections : DeclarationReflection [ ] ,
160
+ categorySearchBoosts : { [ key : string ] : number }
139
161
) : ReflectionCategory [ ] {
140
162
const categories : ReflectionCategory [ ] = [ ] ;
141
163
let defaultCat : ReflectionCategory | undefined ;
@@ -154,11 +176,17 @@ export class CategoryPlugin extends ConverterComponent {
154
176
categories . push ( defaultCat ) ;
155
177
}
156
178
}
179
+
157
180
defaultCat . children . push ( child ) ;
158
181
return ;
159
182
}
160
183
for ( const childCat of childCategories ) {
161
184
let category = categories . find ( ( cat ) => cat . title === childCat ) ;
185
+
186
+ const catBoost = categorySearchBoosts [ category ?. title ?? - 1 ] ;
187
+ if ( catBoost != undefined ) {
188
+ child . categoryBoost = catBoost ;
189
+ }
162
190
if ( category ) {
163
191
category . children . push ( child ) ;
164
192
continue ;
0 commit comments