Skip to content

Commit

Permalink
Allow searching by score
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed May 6, 2024
1 parent 0336d05 commit c778ec4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ import {
// keep an own cache for entries
var cache: CachedEntry[] = [];

const RE_TRAITS = ['id', 'user', 'scope', 'head', 'body', 'date'] as const;
const RE_TRAITS = [
'id',
'user',
'scope',
'head',
'body',
'date',
'score',
] as const;
type Trait = (typeof RE_TRAITS)[number];

type ReCache = Record<Trait, Record<string, (entry: CachedEntry) => boolean>>;
Expand Down Expand Up @@ -196,9 +204,9 @@ function make_re(trait: Trait, s: string): (entry: CachedEntry) => boolean {
.replace(/V/g, '[aeıiouy]');

let regexp = new RegExp(`^${s}\$`, 'iu');
return entry => regexp.test(entry.$[trait]);
return entry => regexp.test(String(entry.$[trait]));
} catch (_) {
return entry => s === entry.$[trait];
return entry => s === String(entry.$[trait]);
}
}

Expand Down

0 comments on commit c778ec4

Please sign in to comment.