-
-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modernize codebase #343
Draft
ignatiusmb
wants to merge
3
commits into
nextapps-de:master
Choose a base branch
from
devmauss:modernize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
modernize codebase #343
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,147 +1,71 @@ | ||
declare module "flexsearch" { | ||
export interface Index<T> { | ||
readonly id: string; | ||
readonly index: string; | ||
readonly length: number; | ||
|
||
init(options?: CreateOptions): this; | ||
info(): { | ||
id: any; | ||
items: any; | ||
cache: any; | ||
matcher: number; | ||
worker: any; | ||
threshold: any; | ||
depth: any; | ||
resolution: any; | ||
contextual: boolean; | ||
}; | ||
add(o: T): this; | ||
add(id: number, o: string): this; | ||
|
||
// Result without pagination -> T[] | ||
search( | ||
query: string, | ||
options: number | SearchOptions, | ||
callback: (results: T[]) => void | ||
): void; | ||
search(query: string, options?: number | SearchOptions): Promise<T[]>; | ||
search( | ||
options: SearchOptions & { query: string }, | ||
callback: (results: T[]) => void | ||
): void; | ||
search(options: SearchOptions & { query: string }): Promise<T[]>; | ||
|
||
// Result with pagination -> SearchResults<T> | ||
search( | ||
query: string, | ||
options: number | (SearchOptions & { page?: boolean | Cursor }), | ||
callback: (results: SearchResults<T>) => void | ||
): void; | ||
search( | ||
query: string, | ||
options?: number | (SearchOptions & { page?: boolean | Cursor }) | ||
): Promise<SearchResults<T>>; | ||
search( | ||
options: SearchOptions & { query: string; page?: boolean | Cursor }, | ||
callback: (results: SearchResults<T>) => void | ||
): void; | ||
search( | ||
options: SearchOptions & { query: string; page?: boolean | Cursor } | ||
): Promise<SearchResults<T>>; | ||
|
||
update(id: number, o: T): this; | ||
remove(id: number): this; | ||
clear(): this; | ||
destroy(): this; | ||
addMatcher(matcher: Matcher): this; | ||
|
||
where(whereObj: { [key: string]: string } | ((o: T) => boolean)): T[]; | ||
encode(str: string): string; | ||
export( | ||
callback: (key: string, data: any) => any, | ||
self?: this, | ||
field?: string, | ||
index_doc?: Number, | ||
index?: Number | ||
): Promise<boolean>; | ||
import(exported: string): this; | ||
} | ||
interface SearchOptions { | ||
limit?: number; | ||
suggest?: boolean; | ||
where?: { [key: string]: string }; | ||
field?: string | string[]; | ||
bool?: 'and' | 'or' | 'not'; | ||
} | ||
|
||
interface SearchOptions { | ||
limit?: number; | ||
suggest?: boolean; | ||
where?: { [key: string]: string }; | ||
field?: string | string[]; | ||
bool?: "and" | "or" | "not"; | ||
//TODO: Sorting | ||
} | ||
interface SearchResults<T> { | ||
page?: string; | ||
next?: string; | ||
result: T[]; | ||
} | ||
|
||
interface SearchResults<T> { | ||
page?: Cursor; | ||
next?: Cursor; | ||
result: T[]; | ||
} | ||
type DefaultEncoder = 'icase' | 'simple' | 'advanced' | 'extra' | 'balance'; | ||
type DefaultTokenizer = 'strict' | 'forward' | 'reverse' | 'full'; | ||
type EncoderFunction = (str: string) => string; | ||
type FilterFunction = (str: string) => boolean; | ||
type TokenizerFunction = (str: string) => string[]; | ||
|
||
interface Document { | ||
id: string; | ||
field: any; | ||
} | ||
export interface CreateOptions { | ||
async?: boolean; | ||
boost?: any; // TODO: what? | ||
cache?: number | boolean; | ||
charset?: string; | ||
context?: { | ||
bidirectional?: boolean; | ||
depth?: number; | ||
resolution?: any; // TODO: what? | ||
}; | ||
depth?: number | false; | ||
doc?: { id: string; field: any }; | ||
encode?: false | DefaultEncoder | ((input: string | number) => ThisType); | ||
fastupdate?: any; // TODO: what? | ||
filter?: string | false | FilterFunction; | ||
lang?: string; // TODO: define lang | ||
matcher?: any; // TODO: what? | ||
minlength?: number; | ||
optimize?: boolean; | ||
profile?: 'memory' | 'speed' | 'match' | 'score' | 'balance' | 'fast'; | ||
resolution?: number; | ||
rtl?: boolean; | ||
split?: RegExp; | ||
stemmer?: string | false | { [key: string]: string }; | ||
threshold?: number | false; | ||
tokenize?: DefaultTokenizer | TokenizerFunction; | ||
worker?: number | false; | ||
} | ||
|
||
export type CreateOptions = { | ||
profile?: IndexProfile; | ||
tokenize?: DefaultTokenizer | TokenizerFn; | ||
split?: RegExp; | ||
encode?: DefaultEncoder | EncoderFn | false; | ||
cache?: boolean | number; | ||
async?: boolean; | ||
worker?: false | number; | ||
depth?: false | number; | ||
threshold?: false | number; | ||
resolution?: number; | ||
stemmer?: Stemmer | string | false; | ||
filter?: FilterFn | string | false; | ||
rtl?: boolean; | ||
doc?: Document; | ||
}; | ||
export default class FlexSearch { | ||
constructor(options?: CreateOptions); | ||
|
||
// limit number Sets the limit of results. | ||
// suggest true, false Enables suggestions in results. | ||
// where object Use a where-clause for non-indexed fields. | ||
// field string, Array<string> Sets the document fields which should be searched. When no field is set, all fields will be searched. Custom options per field are also supported. | ||
// bool "and", "or" Sets the used logical operator when searching through multiple fields. | ||
// page true, false, cursor Enables paginated results. | ||
readonly id: string; | ||
readonly index: string; | ||
readonly length: number; | ||
|
||
type IndexProfile = | ||
| "memory" | ||
| "speed" | ||
| "match" | ||
| "score" | ||
| "balance" | ||
| "fast"; | ||
type DefaultTokenizer = "strict" | "forward" | "reverse" | "full"; | ||
type TokenizerFn = (str: string) => string[]; | ||
type DefaultEncoder = "icase" | "simple" | "advanced" | "extra" | "balance"; | ||
type EncoderFn = (str: string) => string; | ||
type Stemmer = { [key: string]: string }; | ||
type Matcher = { [key: string]: string }; | ||
type FilterFn = (str: string) => boolean; | ||
type Cursor = string; | ||
static encode(name: string, str: string): string; | ||
static registerLanguage( | ||
lang: string, | ||
options: { | ||
stemmer?: { [key: string]: string }; | ||
filter?: string[]; | ||
} | ||
): typeof FlexSearch; | ||
|
||
export default class FlexSearch { | ||
static create<T>(options?: CreateOptions): Index<T>; | ||
static registerMatcher(matcher: Matcher): typeof FlexSearch; | ||
static registerEncoder(name: string, encoder: EncoderFn): typeof FlexSearch; | ||
static registerLanguage( | ||
lang: string, | ||
options: { stemmer?: Stemmer; filter?: string[] } | ||
): typeof FlexSearch; | ||
static encode(name: string, str: string): string; | ||
} | ||
add(id: number, content: string): this; | ||
append(id: number, content: string): this; | ||
remove(id: number): this; | ||
search(query: string, limit: number, options: SearchOptions): this; | ||
update(id: number, content: string): this; | ||
} | ||
|
||
// FlexSearch.create(<options>) | ||
// FlexSearch.registerMatcher({KEY: VALUE}) | ||
// FlexSearch.registerEncoder(name, encoder) | ||
// FlexSearch.registerLanguage(lang, {stemmer:{}, filter:[]}) | ||
// FlexSearch.encode(name, string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this file so much smaller now? Is it just because of formatting? It's hard to tell what changed