Skip to content

Commit

Permalink
Enable searching for any non-space phrase in a chapter title, instead…
Browse files Browse the repository at this point in the history
… of just the start of a word.
  • Loading branch information
johndoknjas committed Feb 10, 2025
1 parent cf7c065 commit 24ae3c1
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions ui/analyse/src/study/studySearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class SearchCtrl {

results = () => {
const q = this.cleanQuery();
return q ? this.chapters.all().filter(this.match(q)) : this.chapters.all();
return q
? this.chapters.all().filter((c: ChapterPreview) => c.name.toLowerCase().includes(q))
: this.chapters.all();
};

setChapter = (id: string) => {
Expand All @@ -38,11 +40,6 @@ export class SearchCtrl {
const c = this.results()[0];
if (c) this.setChapter(c.id);
};

private tokenize = (c: ChapterPreview) => c.name.toLowerCase().split(' ');

private match = (q: string) => (c: ChapterPreview) =>
q.includes(' ') ? c.name.toLowerCase().includes(q) : this.tokenize(c).some(t => t.startsWith(q));
}

const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
Expand Down

0 comments on commit 24ae3c1

Please sign in to comment.