@@ -4,12 +4,12 @@ import {
44 DeclarationReflection ,
55 CommentTag ,
66} from "../../models" ;
7- import { ReflectionCategory } from "../../models/ReflectionCategory " ;
7+ import { ReflectionCategory } from "../../models" ;
88import { Component , ConverterComponent } from "../components" ;
99import { Converter } from "../converter" ;
1010import type { Context } from "../context" ;
1111import { BindOption } from "../../utils" ;
12- import type { Comment } from "../../models/comments/index " ;
12+ import type { Comment } from "../../models" ;
1313
1414/**
1515 * A handler that sorts and categorizes the found reflections in the resolving phase.
@@ -66,9 +66,12 @@ export class CategoryPlugin extends ConverterComponent {
6666 * @param context The context object describing the current state the converter is in.
6767 * @param reflection The reflection that is currently resolved.
6868 */
69- private onResolve ( _context : Context , reflection : Reflection ) {
69+ private onResolve ( context : Context , reflection : Reflection ) {
7070 if ( reflection instanceof ContainerReflection ) {
71- this . categorize ( reflection ) ;
71+ this . categorize (
72+ reflection ,
73+ context . getSearchOptions ( ) ?. searchCategoryBoosts ?? { }
74+ ) ;
7275 }
7376 }
7477
@@ -79,26 +82,36 @@ export class CategoryPlugin extends ConverterComponent {
7982 */
8083 private onEndResolve ( context : Context ) {
8184 const project = context . project ;
82- this . categorize ( project ) ;
85+ this . categorize (
86+ project ,
87+ context . getSearchOptions ( ) ?. searchCategoryBoosts ?? { }
88+ ) ;
8389 }
8490
85- private categorize ( obj : ContainerReflection ) {
91+ private categorize (
92+ obj : ContainerReflection ,
93+ categorySearchBoosts : { [ key : string ] : number }
94+ ) {
8695 if ( this . categorizeByGroup ) {
87- this . groupCategorize ( obj ) ;
96+ this . groupCategorize ( obj , categorySearchBoosts ) ;
8897 } else {
89- this . lumpCategorize ( obj ) ;
98+ CategoryPlugin . lumpCategorize ( obj , categorySearchBoosts ) ;
9099 }
91100 }
92101
93- private groupCategorize ( obj : ContainerReflection ) {
102+ private groupCategorize (
103+ obj : ContainerReflection ,
104+ categorySearchBoosts : { [ key : string ] : number }
105+ ) {
94106 if ( ! obj . groups || obj . groups . length === 0 ) {
95107 return ;
96108 }
97109 obj . groups . forEach ( ( group ) => {
98110 if ( group . categories ) return ;
99111
100112 group . categories = CategoryPlugin . getReflectionCategories (
101- group . children
113+ group . children ,
114+ categorySearchBoosts
102115 ) ;
103116 if ( group . categories && group . categories . length > 1 ) {
104117 group . categories . sort ( CategoryPlugin . sortCatCallback ) ;
@@ -112,11 +125,17 @@ export class CategoryPlugin extends ConverterComponent {
112125 } ) ;
113126 }
114127
115- private lumpCategorize ( obj : ContainerReflection ) {
128+ static lumpCategorize (
129+ obj : ContainerReflection ,
130+ categorySearchBoosts : { [ key : string ] : number }
131+ ) {
116132 if ( ! obj . children || obj . children . length === 0 || obj . categories ) {
117133 return ;
118134 }
119- obj . categories = CategoryPlugin . getReflectionCategories ( obj . children ) ;
135+ obj . categories = CategoryPlugin . getReflectionCategories (
136+ obj . children ,
137+ categorySearchBoosts
138+ ) ;
120139 if ( obj . categories && obj . categories . length > 1 ) {
121140 obj . categories . sort ( CategoryPlugin . sortCatCallback ) ;
122141 } else if (
@@ -132,10 +151,13 @@ export class CategoryPlugin extends ConverterComponent {
132151 * Create a categorized representation of the given list of reflections.
133152 *
134153 * @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
135156 * @returns An array containing all children of the given reflection categorized
136157 */
137158 static getReflectionCategories (
138- reflections : DeclarationReflection [ ]
159+ reflections : DeclarationReflection [ ] ,
160+ categorySearchBoosts : { [ key : string ] : number }
139161 ) : ReflectionCategory [ ] {
140162 const categories : ReflectionCategory [ ] = [ ] ;
141163 let defaultCat : ReflectionCategory | undefined ;
@@ -154,11 +176,18 @@ export class CategoryPlugin extends ConverterComponent {
154176 categories . push ( defaultCat ) ;
155177 }
156178 }
179+
157180 defaultCat . children . push ( child ) ;
158181 return ;
159182 }
160183 for ( const childCat of childCategories ) {
161184 let category = categories . find ( ( cat ) => cat . title === childCat ) ;
185+
186+ const catBoost = categorySearchBoosts [ category ?. title ?? - 1 ] ;
187+ if ( catBoost != undefined ) {
188+ child . relevanceBoost =
189+ ( child . relevanceBoost ?? 1 ) * catBoost ;
190+ }
162191 if ( category ) {
163192 category . children . push ( child ) ;
164193 continue ;
0 commit comments