Files
discord-decomp/lib/search/EnglishAnalyzer.tsx
T
2026-11-01 12:12:55 +02:00

117 lines
3.5 KiB
TypeScript

// Metro module 15547 (f15548).
import Module12 from "../../_bundle/Module12";
import { snowballStem } from "./snowballStemmer";
import { SEARCH_PARTIAL_NAME_MATCH_MIN_QUERY_LENGTH, SEARCH_PARTIAL_NAME_MATCH_MAX_QUERY_LENGTH } from "../../_bundle/Module15550";
let c11074_3, lowercase, isStopWord, isBlank, shouldHighlight, highlightAST;
const stripPossessive = function stripPossessive(a0) {
return a0.replace(/('|\u2019|\uFF07)(s|S)$/, "");
};
lowercase = function lowercase(a0) {
return a0.toLowerCase();
};
isStopWord = function isStopWord(a0) {
return c11074_3.has(a0);
};
isBlank = function isBlank(a0) {
return a0.length === 0;
};
shouldHighlight = function shouldHighlight(a0, a1, r0 = false) {
const r19 = lowercase(stripPossessive(a0));
if (isBlank(r19)) {
return false;
}
if (isStopWord(r19)) {
return false;
}
const r29 = snowballStem(r19);
if (!r0) {
return a1.has(r29);
}
for (const item of a1.values()) {
if (!r29.includes(item)) {
continue;
}
return true;
}
return false;
};
highlightAST = function highlightAST(a0, a1, a2) {
let c22142_0, c22142_1, c22142_2, content;
L14: {
c22142_0 = a1;
c22142_1 = a2;
if (Array.isArray(a0)) {
a0.forEach((item) => {
highlightAST(item, c22142_0, c22142_1);
return item;
});
} else if (a0.type === "list") {
a0.items.forEach((item) => {
highlightAST(item, c22142_0, c22142_1);
return item;
});
} else {
if (typeof a0.content === "string" && a0.type !== "codeBlock") {
const content2 = [];
c22142_2 = content2;
content = "";
a0.content.split(/(\W+)/g).forEach((item) => {
const shouldHighlight2 = shouldHighlight(item, c22142_0, c22142_1);
if (shouldHighlight2) {
if (content.length > 0) {
c22142_2.push({
type: "text",
content
});
}
c22142_2.push({
type: "highlight",
content: item
});
content = "";
} else {
content = content + item;
}
});
if (!(content2.length > 0)) {
break L14;
}
if (content.length > 0) {
content2.push({
type: "text",
content
});
}
if (a0.type === "text") {
a0.content = content2;
break L14;
}
a0.content = [{
type: "text",
content: content2
}];
break L14;
}
if (a0.content != null) {
highlightAST(a0.content, a1, a2);
}
}
}
return a0;
};
c11074_3 = new Set(["a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]);
export function analyze(a0) {
return Module12(a0.split(/\W+/)).map(stripPossessive).reject(isBlank).map(lowercase).reject(isStopWord).map(snowballStem).value();
}
export { shouldHighlight };
export { highlightAST };
export function createASTHighlighter(a0, r4 = false) {
let c22143_0 = r4;
let c22143_1 = a0.length >= SEARCH_PARTIAL_NAME_MATCH_MIN_QUERY_LENGTH && a0.length <= SEARCH_PARTIAL_NAME_MATCH_MAX_QUERY_LENGTH;
let c22143_2 = new Set(Module12(a0.split(/\W+/)).map(stripPossessive).reject(isBlank).map(lowercase).reject(isStopWord).map(snowballStem).value());
return (a0) => {
highlightAST(a0, c22143_2, c22143_1 && c22143_0);
return a0;
};
}