Skip to content

Commit bca9ca5

Browse files
committed
Adding values in the item score
1 parent 6b8385f commit bca9ca5

File tree

5 files changed

+243
-7
lines changed

5 files changed

+243
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ lib/**/*
4040
# ignore yarn.lock
4141
yarn.lock
4242
/tests/test.sqlite
43+
lib

src/fuzzyScoring.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ export type ItemScore = {
1313
*/
1414
score: number;
1515

16+
label?: string;
1617
/**
1718
* Matches within the label.
1819
*/
1920
labelMatch?: Match[];
2021

22+
description?: string;
2123
descriptionMatch?: Match[];
2224

23-
/**
24-
* Matches within the path.
25-
*/
26-
pathMatch?: Match[];
27-
25+
rawValue?: string;
2826
/**
2927
* Matches within the rawValue.
3028
* Only available if the item has a rawValue.
@@ -33,6 +31,7 @@ export type ItemScore = {
3331
*/
3432
rawValueMatch?: Match[];
3533

34+
formattedValue?: string;
3635
/**
3736
* Matches within the formattedValue.
3837
* Only available if the item has a formattedValue.
@@ -240,6 +239,10 @@ function doScoreItemFuzzy(
240239
score: PATH_IDENTITY_SCORE,
241240
labelMatch: [{ start: 0, end: label.length }],
242241
descriptionMatch: description ? [{ start: 0, end: description.length }] : undefined,
242+
label,
243+
description,
244+
rawValue,
245+
formattedValue,
243246
};
244247
}
245248

@@ -382,6 +385,10 @@ function doScoreItemFuzzySingle(
382385
{
383386
score: baseScore + labelScore,
384387
labelMatch: labelPrefixMatch || createMatches(labelPositions),
388+
label,
389+
description,
390+
rawValue,
391+
formattedValue,
385392
},
386393
rawValue,
387394
formattedValue,
@@ -436,7 +443,15 @@ function doScoreItemFuzzySingle(
436443
});
437444

438445
return integrateValueScores(
439-
{ score: labelDescriptionScore, labelMatch, descriptionMatch },
446+
{
447+
score: labelDescriptionScore,
448+
labelMatch,
449+
descriptionMatch,
450+
label,
451+
description,
452+
rawValue,
453+
formattedValue,
454+
},
440455
rawValue,
441456
formattedValue,
442457
query,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { JSONHeroSearch } from "./JSONHeroSearch";
1+
export { JSONHeroSearch, JSONHeroSearchOptions, JSONHeroPathAccessor } from "./JSONHeroSearch";
22
export { search, SearchResult } from "./search";

tests/jsonHeroSearch.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
5050
],
5151
},
5252
"score": Object {
53+
"description": "",
5354
"descriptionMatch": undefined,
55+
"formattedValue": "null",
56+
"label": "foo",
5457
"labelMatch": Array [
5558
Object {
5659
"end": 3,
5760
"start": 0,
5861
},
5962
],
63+
"rawValue": undefined,
6064
"score": 262144,
6165
},
6266
},
@@ -86,6 +90,7 @@ test("JSONHeroSearch can search with just json and a query", () => {
8690
],
8791
},
8892
"score": Object {
93+
"description": "github.profile.repo",
8994
"descriptionMatch": Array [
9095
Object {
9196
"end": 11,
@@ -96,12 +101,15 @@ test("JSONHeroSearch can search with just json and a query", () => {
96101
"start": 18,
97102
},
98103
],
104+
"formattedValue": "null",
105+
"label": "description",
99106
"labelMatch": Array [
100107
Object {
101108
"end": 10,
102109
"start": 9,
103110
},
104111
],
112+
"rawValue": undefined,
105113
"score": 6,
106114
},
107115
},
@@ -124,13 +132,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
124132
],
125133
},
126134
"score": Object {
135+
"description": "",
127136
"descriptionMatch": undefined,
137+
"formattedValue": "null",
138+
"label": "github",
128139
"labelMatch": Array [
129140
Object {
130141
"end": 6,
131142
"start": 0,
132143
},
133144
],
145+
"rawValue": undefined,
134146
"score": 262144,
135147
},
136148
},
@@ -152,13 +164,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
152164
],
153165
},
154166
"score": Object {
167+
"description": "github",
155168
"descriptionMatch": Array [
156169
Object {
157170
"end": 6,
158171
"start": 0,
159172
},
160173
],
174+
"formattedValue": "null",
175+
"label": "profile",
161176
"labelMatch": Array [],
177+
"rawValue": undefined,
162178
"score": 95,
163179
},
164180
},
@@ -184,13 +200,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
184200
],
185201
},
186202
"score": Object {
203+
"description": "github.profile",
187204
"descriptionMatch": Array [
188205
Object {
189206
"end": 6,
190207
"start": 0,
191208
},
192209
],
210+
"formattedValue": "null",
211+
"label": "id",
193212
"labelMatch": Array [],
213+
"rawValue": undefined,
194214
"score": 95,
195215
},
196216
},
@@ -216,13 +236,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
216236
],
217237
},
218238
"score": Object {
239+
"description": "github.profile",
219240
"descriptionMatch": Array [
220241
Object {
221242
"end": 6,
222243
"start": 0,
223244
},
224245
],
246+
"formattedValue": "null",
247+
"label": "name",
225248
"labelMatch": Array [],
249+
"rawValue": undefined,
226250
"score": 95,
227251
},
228252
},
@@ -248,13 +272,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
248272
],
249273
},
250274
"score": Object {
275+
"description": "github.profile",
251276
"descriptionMatch": Array [
252277
Object {
253278
"end": 6,
254279
"start": 0,
255280
},
256281
],
282+
"formattedValue": "null",
283+
"label": "repo",
257284
"labelMatch": Array [],
285+
"rawValue": undefined,
258286
"score": 95,
259287
},
260288
},
@@ -284,13 +312,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
284312
],
285313
},
286314
"score": Object {
315+
"description": "github.profile.repo",
287316
"descriptionMatch": Array [
288317
Object {
289318
"end": 6,
290319
"start": 0,
291320
},
292321
],
322+
"formattedValue": "null",
323+
"label": "id",
293324
"labelMatch": Array [],
325+
"rawValue": undefined,
294326
"score": 95,
295327
},
296328
},
@@ -320,13 +352,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
320352
],
321353
},
322354
"score": Object {
355+
"description": "github.profile.repo",
323356
"descriptionMatch": Array [
324357
Object {
325358
"end": 6,
326359
"start": 0,
327360
},
328361
],
362+
"formattedValue": "null",
363+
"label": "name",
329364
"labelMatch": Array [],
365+
"rawValue": undefined,
330366
"score": 95,
331367
},
332368
},
@@ -356,13 +392,17 @@ test("JSONHeroSearch can search with just json and a query", () => {
356392
],
357393
},
358394
"score": Object {
395+
"description": "github.profile.repo",
359396
"descriptionMatch": Array [
360397
Object {
361398
"end": 6,
362399
"start": 0,
363400
},
364401
],
402+
"formattedValue": "null",
403+
"label": "description",
365404
"labelMatch": Array [],
405+
"rawValue": undefined,
366406
"score": 95,
367407
},
368408
},

0 commit comments

Comments
 (0)