Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
fix(search): a run-together name only matches from the start of a word
Duarte Santos07d44366fa9f
diff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.jsindex 7d9c7da08..580084114 100644--- a/frontend/src/lib/exercises.js+++ b/frontend/src/lib/exercises.js@@ -276,7 +276,9 @@ function corpusOf(e) {// The name run together, so "benchpress" or "bench-press" finds "bench press" the way "pullup"// already found the names that spell it that way (QA 1.3.9). Name only: joined across fields,// a body part and an equipment word would start matching as one.- const entry = { v, s, joined: joinWords(name), nameWords: name.split(/\s+/).filter(Boolean) }+ // The joined form only counts from the start of a name word, or "thigh" would find "sumo+ // deadlift high pull" through "deadlifthighpull".+ const entry = { v, s, ...joinedOf(name), nameWords: name.split(/\s+/).filter(Boolean) }corpusCache.set(e, entry)return entry}@@ -302,10 +304,33 @@ function nearWord(a, b) {}const queryTokens = query => normalizeStr(query || '').split(/\s+/).filter(Boolean)+const SEPARATOR = /[\s\-‐-―]/+const WORD_CHAR = /[\p{L}\p{N}]/uconst joinWords = str => str.replace(/[\s\-‐-―]+/g, '')-// A token appears in the corpus as typed, or in the name with its spaces and hyphens left out.-const hits = (entry, tok) => entry.s.includes(tok) || (tok.length >= 4 && entry.joined.includes(joinWords(tok)))+// The name with its spaces and hyphens left out, and where each of its words starts in that.+function joinedOf(name) {+ let joined = ''+ const starts = new Set()+ for (let i = 0; i < name.length; i++) {+ if (SEPARATOR.test(name[i])) continue+ if (i === 0 || !WORD_CHAR.test(name[i - 1])) starts.add(joined.length)+ joined += name[i]+ }+ return { joined, starts }+}++function joinedHit(entry, tok) {+ const needle = joinWords(tok)+ for (let at = entry.joined.indexOf(needle); at !== -1; at = entry.joined.indexOf(needle, at + 1)) {+ if (entry.starts.has(at)) return true+ }+ return false+}++// A token appears in the corpus as typed, or in the name with its spaces and hyphens left out,+// starting at a word.+const hits = (entry, tok) => entry.s.includes(tok) || (tok.length >= 4 && joinedHit(entry, tok))// Every token has to appear in the corpus; a token listed in `fuzzy` may instead be one edit// away from a name word.diff --git a/frontend/src/lib/search-typo.test.js b/frontend/src/lib/search-typo.test.jsindex d4472a660..f38ce16bb 100644--- a/frontend/src/lib/search-typo.test.js+++ b/frontend/src/lib/search-typo.test.js@@ -66,7 +66,8 @@ it('searchExercises over the real catalogue returns only exact hits for correctlexpect(got.length, q).toBe(EXDB.filter(e => plain(e, q)).length)expect(got.every(e => plain(e, q)), q).toBe(true)}- expect(searchExercises(EXDB, 'wrist')[0].n).toBe('band reverse wrist curl')+ const wrist = searchExercises(EXDB, 'wrist')+ expect(wrist.map(e => e.n)).toContain('band reverse wrist curl')})// QA 1.3.9: "pullup" found the pull-ups while "benchpress" found nothing — words typed together@@ -80,4 +81,10 @@ it('finds a name typed with its words run together or hyphenated', () => {expect(matchExercise(benchPress, 'dumbbellbenchpress')).toBe(true)// Only the name is run together: a body part and equipment word do not fuse into one.expect(matchExercise(benchPress, 'chestdumbbell')).toBe(false)+ // And the run-together form starts at a word: "deadlifthighpull" holds "thigh" mid-word.+ const highPull = { n: 'sumo deadlift high pull', bp: 'upper legs', eq: 'barbell' }+ const adductor = { n: 'inner thigh squeeze', bp: 'upper legs', eq: 'body weight' }+ expect(searchExercises([highPull, adductor], 'thigh')).toEqual([adductor])+ expect(matchExercise(highPull, 'highpull')).toBe(true)+ expect(matchExercise(highPull, 'deadlift-high')).toBe(true)})