'FlexSearch TypeScript can't populate index
I cannot get flexsearch to work in an angular app. When trying to add items to the index it'll run but without an error, but won't actually add any items. Then trying to search will return an empty array.
Anyone had any luck with flexsearch and typescript?
export class SearchService {
constructor() { }
search(): Observable<SearchService.TestSearch> {
let index: Index<SearchService.TestSearch> = FlexSearch.create<SearchService.TestSearch>();
index.init({
doc: {
id: 'id',
field: ['title', 'value']
}
});
for (let i=0;i<5;i++) {
index.add(new SearchService.TestSearch(i, `Title ${i}`, `Value ${i}`));
}
let stringIndex: Index<SearchService.TestSearch> = FlexSearch.create<SearchService.TestSearch>();
stringIndex.init({
doc: {
id: 'id',
field: ['title', 'value']
}
});
for (let i=0;i<5;i++) {
stringIndex.add(i, JSON.stringify(new SearchService.TestSearch(i, `Title ${i}`, `Value ${i}`)));
}
console.log(index.info());
console.log(stringIndex.info());
console.log(index.search("Title 1"));
console.log(stringIndex.search("Title 1"));
return services;
}
}
export namespace SearchService {
export class TestSearch {
constructor(
id: number,
title: string,
value: string) { }
}
}
which results in:
{id: 0, items: 0, cache: false, matcher: 0, worker: false, …}
{id: 3, items: 0, cache: false, matcher: 0, worker: false, …}
[]
[]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
