mirror of
https://github.com/Choices-js/Choices.git
synced 2026-03-14 14:45:47 +01:00
Merge pull request #1364 from Choices-js/fix-kmp-not-returning-results-as-expected
Fix kmp not returning results as expected
This commit is contained in:
commit
907efec520
2 changed files with 19 additions and 2 deletions
|
|
@ -73,11 +73,12 @@ export class SearchByKMP<T extends object> implements Searcher<T> {
|
|||
const field = this._fields[k];
|
||||
if (field in obj && kmpSearch(needle, (obj[field] as string).toLowerCase()) !== -1) {
|
||||
results.push({
|
||||
item: obj[field],
|
||||
item: obj,
|
||||
score: count,
|
||||
rank: count + 1,
|
||||
});
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,15 @@ describe('search', () => {
|
|||
});
|
||||
it('label suffix', () => {
|
||||
const results = searcher.search(`${haystack.length - 1}`);
|
||||
expect(results.length).eq(2);
|
||||
expect(results.length).eq(1);
|
||||
});
|
||||
it('search order', () => {
|
||||
const results = searcher.search('label');
|
||||
|
||||
expect(results.length).eq(haystack.length);
|
||||
haystack.forEach((value, index) => {
|
||||
expect(results[index].item.value).eq(value.value);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -141,5 +149,13 @@ describe('search', () => {
|
|||
const results = searcher.search(`${haystack.length - 1}`);
|
||||
expect(results.length).eq(0);
|
||||
});
|
||||
it('search order', () => {
|
||||
const results = searcher.search('label');
|
||||
|
||||
expect(results.length).eq(haystack.length);
|
||||
haystack.forEach((value, index) => {
|
||||
expect(results[index].item.value).eq(value.value);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue