mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-18 01:37:15 +01:00
Update the format of LexResult
to a more readable one (array to object conversion)
This commit is contained in:
parent
7aa5562a21
commit
6b9b9d212f
1 changed files with 14 additions and 3 deletions
|
@ -22,8 +22,15 @@ const tokenList: Token[] = [
|
||||||
|
|
||||||
export type ParseTerm = (term: string, fuzz: number, boost: number) => AstMatcher;
|
export type ParseTerm = (term: string, fuzz: number, boost: number) => AstMatcher;
|
||||||
|
|
||||||
export type Range = [number, number];
|
export interface Range {
|
||||||
export type TermContext = [Range, string];
|
start: number;
|
||||||
|
end: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TermContext {
|
||||||
|
range: Range;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface LexResult {
|
export interface LexResult {
|
||||||
tokenList: TokenList;
|
tokenList: TokenList;
|
||||||
|
@ -61,7 +68,11 @@ export function generateLexResult(searchStr: string, parseTerm: ParseTerm): LexR
|
||||||
if (searchTerm !== null) {
|
if (searchTerm !== null) {
|
||||||
// Push to stack.
|
// Push to stack.
|
||||||
ret.tokenList.push(parseTerm(searchTerm, fuzz, boost));
|
ret.tokenList.push(parseTerm(searchTerm, fuzz, boost));
|
||||||
ret.termContexts.push([[termIndex, termIndex + searchTerm.length], searchTerm]);
|
|
||||||
|
ret.termContexts.push({
|
||||||
|
range: { start: termIndex, end: termIndex + searchTerm.length },
|
||||||
|
content: searchTerm,
|
||||||
|
});
|
||||||
// Reset term and options data.
|
// Reset term and options data.
|
||||||
boost = 1;
|
boost = 1;
|
||||||
fuzz = 0;
|
fuzz = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue