Skip to content

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.

Exercise search: words typed together or hyphenated find the name that spells them apart (benchpress)

Duarte Santos282e65972a11
diff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.js
index 7c7c67e12..a341b903d 100644
--- a/frontend/src/lib/exercises.js
+++ b/frontend/src/lib/exercises.js
@@ -238,7 +238,10 @@ function corpusOf(e) {
...sm, ...sm.map(m => t(m)),
e?.desc || ''
].join(' '))
- const entry = { v, s, nameWords: name.split(/\s+/).filter(Boolean) }
+ // 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) }
corpusCache.set(e, entry)
return entry
}
@@ -264,12 +267,16 @@ function nearWord(a, b) {
}
const queryTokens = query => normalizeStr(query || '').split(/\s+/).filter(Boolean)
+const 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)))
// Every token has to appear in the corpus; a token listed in `fuzzy` may instead be one edit
// away from a name word.
const matchTokens = (e, tokens, fuzzy) => {
- const { s, nameWords } = corpusOf(e)
- return tokens.every(tok => s.includes(tok) || (fuzzy.has(tok) && nameWords.some(word => nearWord(tok, word))))
+ const entry = corpusOf(e)
+ return tokens.every(tok => hits(entry, tok) || (fuzzy.has(tok) && entry.nameWords.some(word => nearWord(tok, word))))
}
// Single-exercise check, used where the list is filtered one option at a time (the exercise
@@ -290,6 +297,6 @@ export function matchExercise(e, query) {
export function searchExercises(list, query) {
const tokens = queryTokens(query)
if (!tokens.length) return list
- const fuzzy = new Set(tokens.filter(tok => !list.some(e => corpusOf(e).s.includes(tok))))
+ const fuzzy = new Set(tokens.filter(tok => !list.some(e => hits(corpusOf(e), tok))))
return list.filter(e => matchTokens(e, tokens, fuzzy))
}
diff --git a/frontend/src/lib/search-typo.test.js b/frontend/src/lib/search-typo.test.js
index 18838c4ef..d4472a660 100644
--- a/frontend/src/lib/search-typo.test.js
+++ b/frontend/src/lib/search-typo.test.js
@@ -68,3 +68,16 @@ it('searchExercises over the real catalogue returns only exact hits for correctl
}
expect(searchExercises(EXDB, 'wrist')[0].n).toBe('band reverse wrist curl')
})
+
+// QA 1.3.9: "pullup" found the pull-ups while "benchpress" found nothing — words typed together
+// (or hyphenated) match a name that spells them apart.
+it('finds a name typed with its words run together or hyphenated', () => {
+ const named = searchExercises(EXDB, 'bench press').filter(e => /bench press/.test(e.n)).map(e => e.id)
+ expect(named.length).toBeGreaterThan(0)
+ for (const q of ['benchpress', 'bench-press', 'Benchpress']) {
+ expect(searchExercises(EXDB, q).map(e => e.id), q).toEqual(expect.arrayContaining(named))
+ }
+ 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)
+})