@usereactify/search 5.60.0-beta.2 → 5.60.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/package.json +1 -1
- package/dist/src/components/Example/ExampleProductCardWeight.js +12 -13
- package/dist/src/components/Example/ExampleProductCardWeight.js.map +1 -1
- package/dist/src/utility/weight.js +14 -54
- package/dist/src/utility/weight.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.60.0-beta.3](///compare/beta-v5.60.0-beta.2...beta-v5.60.0-beta.3) (2026-01-16)
|
|
6
|
+
|
|
5
7
|
## [5.60.0-beta.2](///compare/beta-v5.60.0-beta.1...beta-v5.60.0-beta.2) (2026-01-15)
|
|
6
8
|
|
|
7
9
|
|
package/dist/package.json
CHANGED
|
@@ -43,31 +43,30 @@ const ExampleProductCardWeight = ({ document }) => {
|
|
|
43
43
|
if (!weight)
|
|
44
44
|
return null;
|
|
45
45
|
return (react_1.default.createElement("div", { className: "rs__result-card-product__weight", onClick: toggleWeightBreakdown, style: {
|
|
46
|
-
background: "
|
|
47
|
-
borderRadius: "
|
|
46
|
+
background: "linear-gradient(135deg, #7858F7 0%, #9174ff 100%)",
|
|
47
|
+
borderRadius: "6px",
|
|
48
48
|
color: "white",
|
|
49
49
|
cursor: "pointer",
|
|
50
|
-
|
|
51
|
-
fontSize: "11px",
|
|
52
|
-
fontWeight: "bold",
|
|
50
|
+
fontSize: "12px",
|
|
53
51
|
maxWidth: "100%",
|
|
54
|
-
padding: "
|
|
52
|
+
padding: "6px",
|
|
55
53
|
} },
|
|
56
|
-
react_1.default.createElement("div",
|
|
54
|
+
react_1.default.createElement("div", { style: { fontWeight: "bold" } },
|
|
57
55
|
"Weight: ",
|
|
58
56
|
weight.toFixed(2)),
|
|
59
57
|
showWeightBreakdown && weightBreakdown.length > 0 && (react_1.default.createElement("div", { style: {
|
|
60
58
|
backgroundColor: "rgba(255, 255, 255, 0.95)",
|
|
61
|
-
border: "1px solid #
|
|
62
|
-
borderRadius: "
|
|
59
|
+
border: "1px solid #e0e0e0",
|
|
60
|
+
borderRadius: "6px",
|
|
61
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
63
62
|
color: "black",
|
|
64
|
-
fontSize: "
|
|
65
|
-
marginTop: "
|
|
63
|
+
fontSize: "12px",
|
|
64
|
+
marginTop: "6px",
|
|
66
65
|
maxHeight: "150px",
|
|
67
66
|
overflowY: "auto",
|
|
68
|
-
padding: "
|
|
67
|
+
padding: "6px",
|
|
69
68
|
} },
|
|
70
|
-
react_1.default.createElement("div", { style: { whiteSpace: "pre-line"
|
|
69
|
+
react_1.default.createElement("div", { style: { whiteSpace: "pre-line" } }, formattedBreakdown)))));
|
|
71
70
|
};
|
|
72
71
|
exports.ExampleProductCardWeight = ExampleProductCardWeight;
|
|
73
72
|
//# sourceMappingURL=ExampleProductCardWeight.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExampleProductCardWeight.js","sourceRoot":"","sources":["../../../../src/components/Example/ExampleProductCardWeight.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiD;AAEjD,uCAAuD;AACvD,2CAMuB;AAOhB,MAAM,wBAAwB,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE;IACtF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC/C,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAEtE,8CAA8C;IAC9C,MAAM,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC;IAC1C,MAA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AAO,CAAC,CAAC,CAAC,CAAO;QAEpE,mBAAmB,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,IAAI,CACpD,uCACE,KAAK,EAAE;gBACL,eAAe,EAAE,2BAA2B;gBAC5C,MAAM,EAAE,mBAAmB;gBAC3B,YAAY,EAAE,KAAK;gBACnB,SAAS,EAAE,gCAAgC;gBAC3C,KAAK,EAAE,OAAO;gBACd,QAAQ,EAAE,MAAM;gBAChB,SAAS,EAAE,KAAK;gBAChB,SAAS,EAAE,OAAO;gBAClB,SAAS,EAAE,MAAM;gBACjB,OAAO,EAAE,KAAK;aACf;YAED,uCAAK,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,IAAG,kBAAkB,CAAO,CAC9D,CACP,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AA9DW,QAAA,wBAAwB,4BA8DnC","sourcesContent":["import React, { useState, useMemo } from \"react\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\nimport {\n explainWeight,\n getWeight,\n ExplainScoreDetail,\n ExplainParsedWeight,\n formatWeightBreakdown,\n} from \"../../utility\";\nimport { ElasticProduct } from \"../../types\";\n\nexport interface ExampleProductCardWeightProps {\n document: ElasticProduct;\n}\n\nexport const ExampleProductCardWeight = ({ document }: ExampleProductCardWeightProps) => {\n const { options } = useReactifySearchContext();\n const [showWeightBreakdown, setShowWeightBreakdown] = useState(false);\n\n // Extract score and explanation from document\n const explanation = document._explanation;\n const weight = useMemo(\n () => (explanation ? getWeight(explanation) : document._score),\n [explanation, document._score],\n );\n\n // Parse the weight breakdown if available\n const weightBreakdown: ExplainParsedWeight[] = useMemo(\n () => (explanation ? explainWeight(explanation as ExplainScoreDetail) : []),\n [explanation],\n );\n\n // Memoized formatted breakdown for performance\n const formattedBreakdown = useMemo(() => formatWeightBreakdown(weightBreakdown), [weightBreakdown]);\n\n const toggleWeightBreakdown = () => setShowWeightBreakdown(!showWeightBreakdown);\n\n if (!options.devMode) return null;\n\n if (!weight) return null;\n\n return (\n <div\n className=\"rs__result-card-product__weight\"\n onClick={toggleWeightBreakdown}\n style={{\n background: \"linear-gradient(135deg, #7858F7 0%, #9174ff 100%)\",\n borderRadius: \"6px\",\n color: \"white\",\n cursor: \"pointer\",\n fontSize: \"12px\",\n maxWidth: \"100%\",\n padding: \"6px\",\n }}\n >\n <div style={{ fontWeight: \"bold\" }}>Weight: {weight.toFixed(2)}</div>\n\n {showWeightBreakdown && weightBreakdown.length > 0 && (\n <div\n style={{\n backgroundColor: \"rgba(255, 255, 255, 0.95)\",\n border: \"1px solid #e0e0e0\",\n borderRadius: \"6px\",\n boxShadow: \"0 4px 12px rgba(0, 0, 0, 0.15)\",\n color: \"black\",\n fontSize: \"12px\",\n marginTop: \"6px\",\n maxHeight: \"150px\",\n overflowY: \"auto\",\n padding: \"6px\",\n }}\n >\n <div style={{ whiteSpace: \"pre-line\" }}>{formattedBreakdown}</div>\n </div>\n )}\n </div>\n );\n};\n"]}
|
|
@@ -20,8 +20,7 @@ function parseWeights(detail) {
|
|
|
20
20
|
if (detail.description.includes("min of:")) {
|
|
21
21
|
if (detail.details) {
|
|
22
22
|
for (const subDetail of detail.details) {
|
|
23
|
-
if (subDetail.description.includes("function score") &&
|
|
24
|
-
subDetail.description.includes("product of:")) {
|
|
23
|
+
if (subDetail.description.includes("function score") && subDetail.description.includes("product of:")) {
|
|
25
24
|
const parentWeight = subDetail.value;
|
|
26
25
|
if (subDetail.details) {
|
|
27
26
|
for (const functionDetail of subDetail.details) {
|
|
@@ -31,13 +30,7 @@ function parseWeights(detail) {
|
|
|
31
30
|
parsedWeights.push({
|
|
32
31
|
field: fieldTermData.field,
|
|
33
32
|
weight: 0, // Will be calculated in mergeWeights
|
|
34
|
-
terms: [
|
|
35
|
-
{
|
|
36
|
-
term: fieldTermData.term,
|
|
37
|
-
weight: parentWeight,
|
|
38
|
-
isSynonym: fieldTermData.isSynonym,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
33
|
+
terms: [{ term: fieldTermData.term, weight: parentWeight, isSynonym: fieldTermData.isSynonym }],
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
}
|
|
@@ -47,13 +40,7 @@ function parseWeights(detail) {
|
|
|
47
40
|
parsedWeights.push({
|
|
48
41
|
field,
|
|
49
42
|
weight: 0, // Will be calculated in mergeWeights
|
|
50
|
-
terms: [
|
|
51
|
-
{
|
|
52
|
-
term: "unknown",
|
|
53
|
-
weight: parentWeight,
|
|
54
|
-
isSynonym: false,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
43
|
+
terms: [{ term: "unknown", weight: parentWeight, isSynonym: false }],
|
|
57
44
|
});
|
|
58
45
|
}
|
|
59
46
|
}
|
|
@@ -65,8 +52,7 @@ function parseWeights(detail) {
|
|
|
65
52
|
}
|
|
66
53
|
// Fallback to original parsing if min_of is not found
|
|
67
54
|
if (parsedWeights.length === 0) {
|
|
68
|
-
if (detail.description.includes("function score") &&
|
|
69
|
-
detail.description.includes("product of:")) {
|
|
55
|
+
if (detail.description.includes("function score") && detail.description.includes("product of:")) {
|
|
70
56
|
const parentWeight = detail.value;
|
|
71
57
|
if (detail.details) {
|
|
72
58
|
for (const subDetail of detail.details) {
|
|
@@ -76,13 +62,7 @@ function parseWeights(detail) {
|
|
|
76
62
|
parsedWeights.push({
|
|
77
63
|
field: fieldTermData.field,
|
|
78
64
|
weight: 0, // Will be calculated in mergeWeights
|
|
79
|
-
terms: [
|
|
80
|
-
{
|
|
81
|
-
term: fieldTermData.term,
|
|
82
|
-
weight: parentWeight,
|
|
83
|
-
isSynonym: fieldTermData.isSynonym,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
65
|
+
terms: [{ term: fieldTermData.term, weight: parentWeight, isSynonym: fieldTermData.isSynonym }],
|
|
86
66
|
});
|
|
87
67
|
}
|
|
88
68
|
}
|
|
@@ -92,9 +72,7 @@ function parseWeights(detail) {
|
|
|
92
72
|
parsedWeights.push({
|
|
93
73
|
field,
|
|
94
74
|
weight: 0, // Will be calculated in mergeWeights
|
|
95
|
-
terms: [
|
|
96
|
-
{ term: "unknown", weight: parentWeight, isSynonym: false },
|
|
97
|
-
],
|
|
75
|
+
terms: [{ term: "unknown", weight: parentWeight, isSynonym: false }],
|
|
98
76
|
});
|
|
99
77
|
}
|
|
100
78
|
}
|
|
@@ -122,9 +100,7 @@ function extractFieldFromMatchFilter(description) {
|
|
|
122
100
|
const synonymMatch = description.match(/\+Synonym\(([^:]+):/);
|
|
123
101
|
if (synonymMatch) {
|
|
124
102
|
const field = synonymMatch[1];
|
|
125
|
-
if (field.includes("freq") ||
|
|
126
|
-
field.includes("*") ||
|
|
127
|
-
field.includes("_all")) {
|
|
103
|
+
if (field.includes("freq") || field.includes("*") || field.includes("_all")) {
|
|
128
104
|
return null;
|
|
129
105
|
}
|
|
130
106
|
return field;
|
|
@@ -133,9 +109,7 @@ function extractFieldFromMatchFilter(description) {
|
|
|
133
109
|
const simpleMatch = description.match(/match filter: ([a-zA-Z_]+):/);
|
|
134
110
|
if (simpleMatch) {
|
|
135
111
|
const field = simpleMatch[1];
|
|
136
|
-
if (field.includes("freq") ||
|
|
137
|
-
field.includes("*") ||
|
|
138
|
-
field.includes("_all")) {
|
|
112
|
+
if (field.includes("freq") || field.includes("*") || field.includes("_all")) {
|
|
139
113
|
return null;
|
|
140
114
|
}
|
|
141
115
|
return field;
|
|
@@ -144,9 +118,7 @@ function extractFieldFromMatchFilter(description) {
|
|
|
144
118
|
const parenthesizedMatch = description.match(/match filter: \(([^:]+):/);
|
|
145
119
|
if (parenthesizedMatch) {
|
|
146
120
|
const field = parenthesizedMatch[1];
|
|
147
|
-
if (field.includes("freq") ||
|
|
148
|
-
field.includes("*") ||
|
|
149
|
-
field.includes("_all")) {
|
|
121
|
+
if (field.includes("freq") || field.includes("*") || field.includes("_all")) {
|
|
150
122
|
return null;
|
|
151
123
|
}
|
|
152
124
|
return field;
|
|
@@ -155,9 +127,7 @@ function extractFieldFromMatchFilter(description) {
|
|
|
155
127
|
const complexMatch = description.match(/match filter: ([a-zA-Z_]+):[^(]+/);
|
|
156
128
|
if (complexMatch) {
|
|
157
129
|
const field = complexMatch[1];
|
|
158
|
-
if (field.includes("freq") ||
|
|
159
|
-
field.includes("*") ||
|
|
160
|
-
field.includes("_all")) {
|
|
130
|
+
if (field.includes("freq") || field.includes("*") || field.includes("_all")) {
|
|
161
131
|
return null;
|
|
162
132
|
}
|
|
163
133
|
return field;
|
|
@@ -220,9 +190,7 @@ function extractFieldNameFromDetails(detail) {
|
|
|
220
190
|
if (match) {
|
|
221
191
|
const field = match[1];
|
|
222
192
|
// Additional filtering for common unwanted patterns
|
|
223
|
-
if (field.includes("freq") ||
|
|
224
|
-
field.includes("*") ||
|
|
225
|
-
field.includes("_all")) {
|
|
193
|
+
if (field.includes("freq") || field.includes("*") || field.includes("_all")) {
|
|
226
194
|
return "unknown";
|
|
227
195
|
}
|
|
228
196
|
return field;
|
|
@@ -231,9 +199,7 @@ function extractFieldNameFromDetails(detail) {
|
|
|
231
199
|
if (fallbackMatch) {
|
|
232
200
|
const field = fallbackMatch[1];
|
|
233
201
|
// Additional filtering for common unwanted patterns
|
|
234
|
-
if (field.includes("freq") ||
|
|
235
|
-
field.includes("*") ||
|
|
236
|
-
field.includes("_all")) {
|
|
202
|
+
if (field.includes("freq") || field.includes("*") || field.includes("_all")) {
|
|
237
203
|
return "unknown";
|
|
238
204
|
}
|
|
239
205
|
return field;
|
|
@@ -261,17 +227,12 @@ function mergeWeights(weights) {
|
|
|
261
227
|
for (const [field, terms] of Object.entries(mergedWeights)) {
|
|
262
228
|
const termArray = Object.values(terms).sort((a, b) => b.weight - a.weight);
|
|
263
229
|
const totalWeight = termArray.reduce((sum, term) => sum + term.weight, 0);
|
|
264
|
-
result.push({
|
|
265
|
-
field,
|
|
266
|
-
weight: totalWeight,
|
|
267
|
-
terms: termArray,
|
|
268
|
-
});
|
|
230
|
+
result.push({ field, weight: totalWeight, terms: termArray });
|
|
269
231
|
}
|
|
270
232
|
return result;
|
|
271
233
|
}
|
|
272
234
|
function formatWeightBreakdown(weights) {
|
|
273
|
-
|
|
274
|
-
const breakdown = weights
|
|
235
|
+
return weights
|
|
275
236
|
.sort((a, b) => b.weight - a.weight)
|
|
276
237
|
.map((weight) => {
|
|
277
238
|
const termBreakdown = weight.terms
|
|
@@ -280,6 +241,5 @@ function formatWeightBreakdown(weights) {
|
|
|
280
241
|
return `${weight.field}: ${weight.weight.toFixed(2)} (${termBreakdown})`;
|
|
281
242
|
})
|
|
282
243
|
.join("\n");
|
|
283
|
-
return `Weight: ${totalWeight.toFixed(2)}\nBreakdown:\n${breakdown}`;
|
|
284
244
|
}
|
|
285
245
|
//# sourceMappingURL=weight.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weight.js","sourceRoot":"","sources":["../../../src/utility/weight.ts"],"names":[],"mappings":";;AAkBA,8BAKC;AAED,sCAQC;AA4TD,sDAgBC;AA3VD,SAAgB,SAAS,CAAC,WAA+B;;IACxD,MAAM,MAAM,GAAG,MAAA,WAAW,CAAC,OAAO,0CAAE,IAAI,CACvC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,CAC5C,CAAC;IACF,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC;AAClD,CAAC;AAED,SAAgB,aAAa,CAC5B,WAA+B;IAE/B,MAAM,YAAY,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;IAExE,OAAO,aAAa,CAAC;AACtB,CAAC;AAED,SAAS,YAAY,CAAC,MAA0B;IAC/C,MAAM,aAAa,GAA0B,EAA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D,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,OAAO,WAAW,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,SAAS,EAAE,CAAC;AACtE,CAAC","sourcesContent":["export type ExplainScoreDetail = {\n\tvalue: number;\n\tdescription: string;\n\tdetails?: ExplainScoreDetail[];\n};\n\nexport type ExplainParsedTerm = {\n\tterm: string;\n\tweight: number;\n\tisSynonym: boolean;\n};\n\nexport type ExplainParsedWeight = {\n\tfield: string;\n\tweight: number;\n\tterms: ExplainParsedTerm[];\n};\n\nexport function getWeight(explanation: ExplainScoreDetail): number {\n\tconst detail = explanation.details?.find(\n\t\t(detail) => detail.description === \"min of:\",\n\t);\n\treturn detail ? detail.value : explanation.value;\n}\n\nexport function explainWeight(\n\texplanation: ExplainScoreDetail,\n): ExplainParsedWeight[] {\n\tconst fieldWeights = parseWeights(explanation);\n\tconst mergedWeights = mergeWeights(fieldWeights);\n\tconst sortedWeights = mergedWeights.sort((a, b) => b.weight - a.weight);\n\n\treturn sortedWeights;\n}\n\nfunction parseWeights(detail: ExplainScoreDetail): ExplainParsedWeight[] {\n\tconst parsedWeights: ExplainParsedWeight[] = [];\n\n\t// Look for min_of score which contains the clean field weights\n\tif (detail.description.includes(\"min of:\")) {\n\t\tif (detail.details) {\n\t\t\tfor (const subDetail of detail.details) {\n\t\t\t\tif (\n\t\t\t\t\tsubDetail.description.includes(\"function score\") &&\n\t\t\t\t\tsubDetail.description.includes(\"product of:\")\n\t\t\t\t) {\n\t\t\t\t\tconst parentWeight = subDetail.value;\n\n\t\t\t\t\tif (subDetail.details) {\n\t\t\t\t\t\tfor (const functionDetail of subDetail.details) {\n\t\t\t\t\t\t\tif (functionDetail.description.includes(\"match filter:\")) {\n\t\t\t\t\t\t\t\tconst fieldTermData = extractFieldWithTerm(\n\t\t\t\t\t\t\t\t\tfunctionDetail.description,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif (fieldTermData) {\n\t\t\t\t\t\t\t\t\tparsedWeights.push({\n\t\t\t\t\t\t\t\t\t\tfield: fieldTermData.field,\n\t\t\t\t\t\t\t\t\t\tweight: 0, // Will be calculated in mergeWeights\n\t\t\t\t\t\t\t\t\t\tterms: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tterm: fieldTermData.term,\n\t\t\t\t\t\t\t\t\t\t\t\tweight: parentWeight,\n\t\t\t\t\t\t\t\t\t\t\t\tisSynonym: fieldTermData.isSynonym,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (functionDetail.description.includes(\"weight\")) {\n\t\t\t\t\t\t\t\tconst field = extractFieldNameFromDetails(functionDetail);\n\t\t\t\t\t\t\t\tif (field && field !== \"unknown\") {\n\t\t\t\t\t\t\t\t\tparsedWeights.push({\n\t\t\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\t\t\tweight: 0, // Will be calculated in mergeWeights\n\t\t\t\t\t\t\t\t\t\tterms: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tterm: \"unknown\",\n\t\t\t\t\t\t\t\t\t\t\t\tweight: parentWeight,\n\t\t\t\t\t\t\t\t\t\t\t\tisSynonym: false,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Fallback to original parsing if min_of is not found\n\tif (parsedWeights.length === 0) {\n\t\tif (\n\t\t\tdetail.description.includes(\"function score\") &&\n\t\t\tdetail.description.includes(\"product of:\")\n\t\t) {\n\t\t\tconst parentWeight = detail.value;\n\n\t\t\tif (detail.details) {\n\t\t\t\tfor (const subDetail of detail.details) {\n\t\t\t\t\tif (subDetail.description.includes(\"match filter:\")) {\n\t\t\t\t\t\tconst fieldTermData = extractFieldWithTerm(subDetail.description);\n\t\t\t\t\t\tif (fieldTermData) {\n\t\t\t\t\t\t\tparsedWeights.push({\n\t\t\t\t\t\t\t\tfield: fieldTermData.field,\n\t\t\t\t\t\t\t\tweight: 0, // Will be calculated in mergeWeights\n\t\t\t\t\t\t\t\tterms: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tterm: fieldTermData.term,\n\t\t\t\t\t\t\t\t\t\tweight: parentWeight,\n\t\t\t\t\t\t\t\t\t\tisSynonym: fieldTermData.isSynonym,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (subDetail.description.includes(\"weight\")) {\n\t\t\t\t\t\tconst field = extractFieldNameFromDetails(subDetail);\n\t\t\t\t\t\tif (field && field !== \"unknown\") {\n\t\t\t\t\t\t\tparsedWeights.push({\n\t\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\t\tweight: 0, // Will be calculated in mergeWeights\n\t\t\t\t\t\t\t\tterms: [\n\t\t\t\t\t\t\t\t\t{ term: \"unknown\", weight: parentWeight, isSynonym: false },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (detail.details) {\n\t\tfor (const subDetail of detail.details) {\n\t\t\tparsedWeights.push(...parseWeights(subDetail));\n\t\t}\n\t}\n\n\treturn parsedWeights;\n}\n\nfunction extractFieldFromMatchFilter(description: string): string | null {\n\tconst lowerDescription = description.toLowerCase();\n\n\t// Filter out undesired values early\n\tif (\n\t\tlowerDescription.includes(\"freq\") ||\n\t\tlowerDescription.includes(\"perfieldsimilarity\") ||\n\t\tlowerDescription.includes(\"*:*\") ||\n\t\tlowerDescription.includes(\"_all\")\n\t) {\n\t\treturn null;\n\t}\n\n\t// Handle synonym queries: +Synonym(tags_colour:atlantic tags_colour:emerald ...) -tags_colour:green\n\tconst synonymMatch = description.match(/\\+Synonym\\(([^:]+):/);\n\tif (synonymMatch) {\n\t\tconst field = synonymMatch[1];\n\t\tif (\n\t\t\tfield.includes(\"freq\") ||\n\t\t\tfield.includes(\"*\") ||\n\t\t\tfield.includes(\"_all\")\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn field;\n\t}\n\n\t// Handle simple match filters: match filter: title:shirt\n\tconst simpleMatch = description.match(/match filter: ([a-zA-Z_]+):/);\n\tif (simpleMatch) {\n\t\tconst field = simpleMatch[1];\n\t\tif (\n\t\t\tfield.includes(\"freq\") ||\n\t\t\tfield.includes(\"*\") ||\n\t\t\tfield.includes(\"_all\")\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn field;\n\t}\n\n\t// Handle parenthesized match filters: match filter: (product_type:shirts)\n\tconst parenthesizedMatch = description.match(/match filter: \\(([^:]+):/);\n\tif (parenthesizedMatch) {\n\t\tconst field = parenthesizedMatch[1];\n\t\tif (\n\t\t\tfield.includes(\"freq\") ||\n\t\t\tfield.includes(\"*\") ||\n\t\t\tfield.includes(\"_all\")\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn field;\n\t}\n\n\t// Handle complex queries with boosts: title:shirt (title:short)^0.8\n\tconst complexMatch = description.match(/match filter: ([a-zA-Z_]+):[^(]+/);\n\tif (complexMatch) {\n\t\tconst field = complexMatch[1];\n\t\tif (\n\t\t\tfield.includes(\"freq\") ||\n\t\t\tfield.includes(\"*\") ||\n\t\t\tfield.includes(\"_all\")\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn field;\n\t}\n\n\treturn null;\n}\n\nfunction extractTermFromFilter(\n\tdescription: string,\n): { term: string; isSynonym: boolean } | null {\n\t// Extract from excluded terms in synonym queries: -field:term\n\tconst excludedMatch = description.match(/-([a-zA-Z_]+):([^)\\s]+)/);\n\tif (excludedMatch) {\n\t\tconst term = excludedMatch[2];\n\t\tif (term.includes(\"freq\") || term.includes(\"*\") || term.includes(\"_all\")) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { term, isSynonym: true };\n\t}\n\n\t// Extract from direct matches: field:term (but not parenthesized synonyms)\n\tconst directMatch = description.match(/match filter: ([a-zA-Z_]+):([^(\\s]+)/);\n\tif (directMatch) {\n\t\tconst term = directMatch[2];\n\t\tif (term.includes(\"freq\") || term.includes(\"*\") || term.includes(\"_all\")) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { term, isSynonym: false };\n\t}\n\n\t// Extract from parenthesized direct matches: (field:term)\n\tconst parenthesizedMatch = description.match(\n\t\t/match filter: \\(([a-zA-Z_]+):([^)\\s]+)/,\n\t);\n\tif (parenthesizedMatch) {\n\t\tconst term = parenthesizedMatch[2];\n\t\tif (term.includes(\"freq\") || term.includes(\"*\") || term.includes(\"_all\")) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { term, isSynonym: false };\n\t}\n\n\treturn null;\n}\n\nfunction extractFieldWithTerm(\n\tdescription: string,\n): { field: string; term: string; isSynonym: boolean } | null {\n\tconst termData = extractTermFromFilter(description);\n\tif (!termData) return null;\n\n\tconst fieldData = extractFieldFromMatchFilter(description);\n\tif (!fieldData) return null;\n\n\treturn {\n\t\tfield: fieldData,\n\t\tterm: termData.term,\n\t\tisSynonym: termData.isSynonym,\n\t};\n}\n\nfunction extractFieldNameFromDetails(detail: ExplainScoreDetail): string {\n\tconst description = detail.description.toLowerCase();\n\n\t// Filter out undesired values\n\tif (\n\t\tdescription.includes(\"freq\") ||\n\t\tdescription.includes(\"perfieldsimilarity\") ||\n\t\tdescription.includes(\"*:*\") ||\n\t\tdescription.includes(\"_all\")\n\t) {\n\t\treturn \"unknown\";\n\t}\n\n\tconst match = description.match(/\\(([^:]+):/);\n\tif (match) {\n\t\tconst field = match[1];\n\t\t// Additional filtering for common unwanted patterns\n\t\tif (\n\t\t\tfield.includes(\"freq\") ||\n\t\t\tfield.includes(\"*\") ||\n\t\t\tfield.includes(\"_all\")\n\t\t) {\n\t\t\treturn \"unknown\";\n\t\t}\n\t\treturn field;\n\t}\n\n\tconst fallbackMatch = description.match(/([a-zA-Z_]+):/);\n\tif (fallbackMatch) {\n\t\tconst field = fallbackMatch[1];\n\t\t// Additional filtering for common unwanted patterns\n\t\tif (\n\t\t\tfield.includes(\"freq\") ||\n\t\t\tfield.includes(\"*\") ||\n\t\t\tfield.includes(\"_all\")\n\t\t) {\n\t\t\treturn \"unknown\";\n\t\t}\n\t\treturn field;\n\t}\n\n\treturn \"unknown\";\n}\n\nfunction mergeWeights(weights: ExplainParsedWeight[]): ExplainParsedWeight[] {\n\tconst mergedWeights: Record<string, Record<string, ExplainParsedTerm>> = {};\n\n\t// Merge by field, then by term\n\tfor (const weight of weights) {\n\t\tfor (const term of weight.terms) {\n\t\t\tif (!mergedWeights[weight.field]) {\n\t\t\t\tmergedWeights[weight.field] = {};\n\t\t\t}\n\n\t\t\tif (mergedWeights[weight.field][term.term]) {\n\t\t\t\tmergedWeights[weight.field][term.term].weight += term.weight;\n\t\t\t} else {\n\t\t\t\tmergedWeights[weight.field][term.term] = { ...term };\n\t\t\t}\n\t\t}\n\t}\n\n\t// Convert back to array format and sort terms by weight\n\tconst result: ExplainParsedWeight[] = [];\n\tfor (const [field, terms] of Object.entries(mergedWeights)) {\n\t\tconst termArray = Object.values(terms).sort((a, b) => b.weight - a.weight);\n\t\tconst totalWeight = termArray.reduce((sum, term) => sum + term.weight, 0);\n\n\t\tresult.push({\n\t\t\tfield,\n\t\t\tweight: totalWeight,\n\t\t\tterms: termArray,\n\t\t});\n\t}\n\n\treturn result;\n}\n\nexport function formatWeightBreakdown(weights: ExplainParsedWeight[]): string {\n\tconst totalWeight = weights.reduce((sum, weight) => sum + weight.weight, 0);\n\tconst breakdown = weights\n\t\t.sort((a, b) => b.weight - a.weight)\n\t\t.map((weight) => {\n\t\t\tconst termBreakdown = weight.terms\n\t\t\t\t.map(\n\t\t\t\t\t(term) =>\n\t\t\t\t\t\t`${term.term}: ${term.weight.toFixed(2)}${term.isSynonym ? \" [synonym]\" : \"\"}`,\n\t\t\t\t)\n\t\t\t\t.join(\", \");\n\t\t\treturn `${weight.field}: ${weight.weight.toFixed(2)} (${termBreakdown})`;\n\t\t})\n\t\t.join(\"\\n\");\n\n\treturn `Weight: ${totalWeight.toFixed(2)}\\nBreakdown:\\n${breakdown}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"weight.js","sourceRoot":"","sources":["../../../src/utility/weight.ts"],"names":[],"mappings":";;AAkBA,8BAGC;AAED,sCAMC;AA6PD,sDAUC;AAlRD,SAAgB,SAAS,CAAC,WAA+B;;IACvD,MAAM,MAAM,GAAG,MAAA,WAAW,CAAC,OAAO,0CAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC;IACvF,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC;AACnD,CAAC;AAED,SAAgB,aAAa,CAAC,WAA+B;IAC3D,MAAM,YAAY,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;IAExE,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,YAAY,CAAC,MAA0B;IAC9C,MAAM,aAAa,GAA0B,EAAE,CAAC;IAEhD,+DAA+D;IAC/D,IAAI,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,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,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QAC3E,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1E,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,qBAAqB,CAAC,OAA8B;IAClE,OAAO,OAAO;SACX,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;SACnC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACd,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK;aAC/B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;aAC7F,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,GAAG,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,aAAa,GAAG,CAAC;IAC3E,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["export type ExplainScoreDetail = {\n value: number;\n description: string;\n details?: ExplainScoreDetail[];\n};\n\nexport type ExplainParsedTerm = {\n term: string;\n weight: number;\n isSynonym: boolean;\n};\n\nexport type ExplainParsedWeight = {\n field: string;\n weight: number;\n terms: ExplainParsedTerm[];\n};\n\nexport function getWeight(explanation: ExplainScoreDetail): number {\n const detail = explanation.details?.find((detail) => detail.description === \"min of:\");\n return detail ? detail.value : explanation.value;\n}\n\nexport function explainWeight(explanation: ExplainScoreDetail): ExplainParsedWeight[] {\n const fieldWeights = parseWeights(explanation);\n const mergedWeights = mergeWeights(fieldWeights);\n const sortedWeights = mergedWeights.sort((a, b) => b.weight - a.weight);\n\n return sortedWeights;\n}\n\nfunction parseWeights(detail: ExplainScoreDetail): ExplainParsedWeight[] {\n const parsedWeights: ExplainParsedWeight[] = [];\n\n // Look for min_of score which contains the clean field weights\n if (detail.description.includes(\"min of:\")) {\n if (detail.details) {\n for (const subDetail of detail.details) {\n if (subDetail.description.includes(\"function score\") && subDetail.description.includes(\"product of:\")) {\n const parentWeight = subDetail.value;\n\n if (subDetail.details) {\n for (const functionDetail of subDetail.details) {\n if (functionDetail.description.includes(\"match filter:\")) {\n const fieldTermData = extractFieldWithTerm(functionDetail.description);\n if (fieldTermData) {\n parsedWeights.push({\n field: fieldTermData.field,\n weight: 0, // Will be calculated in mergeWeights\n terms: [{ term: fieldTermData.term, weight: parentWeight, isSynonym: fieldTermData.isSynonym }],\n });\n }\n }\n\n if (functionDetail.description.includes(\"weight\")) {\n const field = extractFieldNameFromDetails(functionDetail);\n if (field && field !== \"unknown\") {\n parsedWeights.push({\n field,\n weight: 0, // Will be calculated in mergeWeights\n terms: [{ term: \"unknown\", weight: parentWeight, isSynonym: false }],\n });\n }\n }\n }\n }\n }\n }\n }\n }\n\n // Fallback to original parsing if min_of is not found\n if (parsedWeights.length === 0) {\n if (detail.description.includes(\"function score\") && detail.description.includes(\"product of:\")) {\n const parentWeight = detail.value;\n\n if (detail.details) {\n for (const subDetail of detail.details) {\n if (subDetail.description.includes(\"match filter:\")) {\n const fieldTermData = extractFieldWithTerm(subDetail.description);\n if (fieldTermData) {\n parsedWeights.push({\n field: fieldTermData.field,\n weight: 0, // Will be calculated in mergeWeights\n terms: [{ term: fieldTermData.term, weight: parentWeight, isSynonym: fieldTermData.isSynonym }],\n });\n }\n }\n\n if (subDetail.description.includes(\"weight\")) {\n const field = extractFieldNameFromDetails(subDetail);\n if (field && field !== \"unknown\") {\n parsedWeights.push({\n field,\n weight: 0, // Will be calculated in mergeWeights\n terms: [{ term: \"unknown\", weight: parentWeight, isSynonym: false }],\n });\n }\n }\n }\n }\n }\n }\n\n if (detail.details) {\n for (const subDetail of detail.details) {\n parsedWeights.push(...parseWeights(subDetail));\n }\n }\n\n return parsedWeights;\n}\n\nfunction extractFieldFromMatchFilter(description: string): string | null {\n const lowerDescription = description.toLowerCase();\n\n // Filter out undesired values early\n if (\n lowerDescription.includes(\"freq\") ||\n lowerDescription.includes(\"perfieldsimilarity\") ||\n lowerDescription.includes(\"*:*\") ||\n lowerDescription.includes(\"_all\")\n ) {\n return null;\n }\n\n // Handle synonym queries: +Synonym(tags_colour:atlantic tags_colour:emerald ...) -tags_colour:green\n const synonymMatch = description.match(/\\+Synonym\\(([^:]+):/);\n if (synonymMatch) {\n const field = synonymMatch[1];\n if (field.includes(\"freq\") || field.includes(\"*\") || field.includes(\"_all\")) {\n return null;\n }\n return field;\n }\n\n // Handle simple match filters: match filter: title:shirt\n const simpleMatch = description.match(/match filter: ([a-zA-Z_]+):/);\n if (simpleMatch) {\n const field = simpleMatch[1];\n if (field.includes(\"freq\") || field.includes(\"*\") || field.includes(\"_all\")) {\n return null;\n }\n return field;\n }\n\n // Handle parenthesized match filters: match filter: (product_type:shirts)\n const parenthesizedMatch = description.match(/match filter: \\(([^:]+):/);\n if (parenthesizedMatch) {\n const field = parenthesizedMatch[1];\n if (field.includes(\"freq\") || field.includes(\"*\") || field.includes(\"_all\")) {\n return null;\n }\n return field;\n }\n\n // Handle complex queries with boosts: title:shirt (title:short)^0.8\n const complexMatch = description.match(/match filter: ([a-zA-Z_]+):[^(]+/);\n if (complexMatch) {\n const field = complexMatch[1];\n if (field.includes(\"freq\") || field.includes(\"*\") || field.includes(\"_all\")) {\n return null;\n }\n return field;\n }\n\n return null;\n}\n\nfunction extractTermFromFilter(description: string): { term: string; isSynonym: boolean } | null {\n // Extract from excluded terms in synonym queries: -field:term\n const excludedMatch = description.match(/-([a-zA-Z_]+):([^)\\s]+)/);\n if (excludedMatch) {\n const term = excludedMatch[2];\n if (term.includes(\"freq\") || term.includes(\"*\") || term.includes(\"_all\")) {\n return null;\n }\n return { term, isSynonym: true };\n }\n\n // Extract from direct matches: field:term (but not parenthesized synonyms)\n const directMatch = description.match(/match filter: ([a-zA-Z_]+):([^(\\s]+)/);\n if (directMatch) {\n const term = directMatch[2];\n if (term.includes(\"freq\") || term.includes(\"*\") || term.includes(\"_all\")) {\n return null;\n }\n return { term, isSynonym: false };\n }\n\n // Extract from parenthesized direct matches: (field:term)\n const parenthesizedMatch = description.match(/match filter: \\(([a-zA-Z_]+):([^)\\s]+)/);\n if (parenthesizedMatch) {\n const term = parenthesizedMatch[2];\n if (term.includes(\"freq\") || term.includes(\"*\") || term.includes(\"_all\")) {\n return null;\n }\n return { term, isSynonym: false };\n }\n\n return null;\n}\n\nfunction extractFieldWithTerm(description: string): { field: string; term: string; isSynonym: boolean } | null {\n const termData = extractTermFromFilter(description);\n if (!termData) return null;\n\n const fieldData = extractFieldFromMatchFilter(description);\n if (!fieldData) return null;\n\n return {\n field: fieldData,\n term: termData.term,\n isSynonym: termData.isSynonym,\n };\n}\n\nfunction extractFieldNameFromDetails(detail: ExplainScoreDetail): string {\n const description = detail.description.toLowerCase();\n\n // Filter out undesired values\n if (\n description.includes(\"freq\") ||\n description.includes(\"perfieldsimilarity\") ||\n description.includes(\"*:*\") ||\n description.includes(\"_all\")\n ) {\n return \"unknown\";\n }\n\n const match = description.match(/\\(([^:]+):/);\n if (match) {\n const field = match[1];\n // Additional filtering for common unwanted patterns\n if (field.includes(\"freq\") || field.includes(\"*\") || field.includes(\"_all\")) {\n return \"unknown\";\n }\n return field;\n }\n\n const fallbackMatch = description.match(/([a-zA-Z_]+):/);\n if (fallbackMatch) {\n const field = fallbackMatch[1];\n // Additional filtering for common unwanted patterns\n if (field.includes(\"freq\") || field.includes(\"*\") || field.includes(\"_all\")) {\n return \"unknown\";\n }\n return field;\n }\n\n return \"unknown\";\n}\n\nfunction mergeWeights(weights: ExplainParsedWeight[]): ExplainParsedWeight[] {\n const mergedWeights: Record<string, Record<string, ExplainParsedTerm>> = {};\n\n // Merge by field, then by term\n for (const weight of weights) {\n for (const term of weight.terms) {\n if (!mergedWeights[weight.field]) {\n mergedWeights[weight.field] = {};\n }\n\n if (mergedWeights[weight.field][term.term]) {\n mergedWeights[weight.field][term.term].weight += term.weight;\n } else {\n mergedWeights[weight.field][term.term] = { ...term };\n }\n }\n }\n\n // Convert back to array format and sort terms by weight\n const result: ExplainParsedWeight[] = [];\n for (const [field, terms] of Object.entries(mergedWeights)) {\n const termArray = Object.values(terms).sort((a, b) => b.weight - a.weight);\n const totalWeight = termArray.reduce((sum, term) => sum + term.weight, 0);\n result.push({ field, weight: totalWeight, terms: termArray });\n }\n\n return result;\n}\n\nexport function formatWeightBreakdown(weights: ExplainParsedWeight[]): string {\n return weights\n .sort((a, b) => b.weight - a.weight)\n .map((weight) => {\n const termBreakdown = weight.terms\n .map((term) => `${term.term}: ${term.weight.toFixed(2)}${term.isSynonym ? \" [synonym]\" : \"\"}`)\n .join(\", \");\n return `${weight.field}: ${weight.weight.toFixed(2)} (${termBreakdown})`;\n })\n .join(\"\\n\");\n}\n"]}
|