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.

feat(search): ranked results, gym shorthand and plurals, more typo room, and similar exercises under the results

Duarte Santos9e1f08bdc65e
diff --git a/frontend/src/index.css b/frontend/src/index.css
index 7beee17c9..3b1a7318f 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -2105,3 +2105,4 @@ body.no-tabbar.resting #toast{bottom:calc(100px + var(--sab))}
/* Tight tracking is tuned for Latin; Arabic is a connected script and gets none. */
[dir="rtl"] *{letter-spacing:0}
.exfix-link{display:inline-flex;align-items:center;gap:5px;margin:14px 0 4px;color:var(--label-3);text-decoration:none}
+.list .similar-label{margin:16px 2px 6px;grid-column:1/-1}
diff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.js
index dcf8dc85d..b30f8f584 100644
--- a/frontend/src/lib/exercises.js
+++ b/frontend/src/lib/exercises.js
@@ -1,5 +1,6 @@
import { EXDB, EXALIAS } from './exercises-data.js'
import MUSCLE_MAP from './exercise-muscle-map.json' with { type: 'json' }
+import V13_IDS from './catalogue-v13-ids.json' with { type: 'json' }
import { t, getVersion, exerciseNameSearchText } from './i18n-core.js'
export { EXDB }
@@ -306,29 +307,76 @@ function corpusOf(e) {
// a body part and an equipment word would start matching as one.
// 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) }
+ const entry = { v, s, name, ...joinedOf(name), nameWords: name.split(/[\s\-‐-―()/,]+/).filter(Boolean) }
corpusCache.set(e, entry)
return entry
}
-// Allow one missing, extra or substituted character, or an adjacent transposition, in long
-// query tokens. Short tokens stay exact/substring-only: words such as "row" and "curl" are too
-// common for fuzzy matching to be useful.
+// How many single-character edits (insert, delete, substitute, swap two neighbours) apart two
+// words are, or `max + 1` as soon as it is clear they are further apart than `max`.
+function editDistance(a, b, max) {
+ if (Math.abs(a.length - b.length) > max) return max + 1
+ let prev2 = null, prev = Array.from({ length: b.length + 1 }, (_, j) => j)
+ for (let i = 1; i <= a.length; i++) {
+ const cur = [i]
+ let rowMin = i
+ for (let j = 1; j <= b.length; j++) {
+ let v = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1))
+ if (prev2 && i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) v = Math.min(v, prev2[j - 2] + 1)
+ cur.push(v)
+ if (v < rowMin) rowMin = v
+ }
+ if (rowMin > max) return max + 1
+ prev2 = prev
+ prev = cur
+ }
+ return prev[b.length]
+}
+
+// Typos allowed in a query word against a name word: none below four letters ("row" and "curl"
+// are too common for a neighbour to mean anything), one up to six, two from seven.
+const typosFor = word => (word.length < 4 ? 0 : word.length < 7 ? 1 : 2)
+
+// Allow typos (typosFor) in a query token against one name word, or against its first letters
+// once the token is long enough to be a word in progress ("dumbel" for "dumbbell").
//
// Only the exercise's own name words are ever compared this way. Body part, target and
// equipment words are shared by a whole slice of the catalogue, so one accidental neighbour
// ("wrist" ~ "waist", "power" ~ "lower arms", "drucken" ~ "rucken") would list hundreds of
// unrelated exercises ahead of the real hits (QA C26).
function nearWord(a, b) {
- if (a.length < 5 || Math.abs(a.length - b.length) > 1) return false
- let i = 0
- while (i < a.length && a[i] === b[i]) i++
- if (i === a.length) return b.length - i <= 1
- if (a.length === b.length) {
- return a.slice(i + 1) === b.slice(i + 1) ||
- (a[i] === b[i + 1] && a[i + 1] === b[i] && a.slice(i + 2) === b.slice(i + 2))
- }
- return a.length > b.length ? a.slice(i + 1) === b.slice(i) : a.slice(i) === b.slice(i + 1)
+ const max = typosFor(a)
+ if (!max) return false
+ if (editDistance(a, b, max) <= max) return true
+ return a.length >= 5 && b.length > a.length && editDistance(a, b.slice(0, a.length), max) <= max
+}
+
+// Gym shorthand and spellings people type, each read as the words the catalogue uses. A query
+// token matches when it or any of its expansions does; the expansions are phrases (all words).
+const SYNONYMS = {
+ db: ['dumbbell'], dbs: ['dumbbell'], bb: ['barbell'], kb: ['kettlebell'], kbs: ['kettlebell'],
+ ez: ['ez barbell'], sm: ['smith'], bw: ['body weight'], bodyweight: ['body weight'],
+ ohp: ['overhead press', 'shoulder press', 'military press'], rdl: ['romanian deadlift'],
+ sldl: ['stiff leg deadlift'], dl: ['deadlift'], bp: ['bench press'], skullcrusher: ['lying triceps extension', 'skull crusher'],
+ skullcrushers: ['lying triceps extension', 'skull crusher'], pulldown: ['pull down', 'pulldown'],
+ pullup: ['pull up', 'pull-up'], chinup: ['chin up', 'chin-up'], pushup: ['push up', 'push-up'],
+ pressup: ['push up', 'push-up'], situp: ['sit up', 'sit-up'], flye: ['fly'], flyes: ['fly'], flies: ['fly'],
+ machine: ['lever', 'machine', 'sled'], lever: ['lever', 'machine'], abs: ['crunch', 'abs'],
+ hammy: ['hamstring'], hammies: ['hamstring'], quad: ['quads', 'quadriceps'], tricep: ['triceps'], bicep: ['biceps'],
+ delt: ['delts', 'shoulder'], lat: ['lats', 'latissimus', 'pulldown'], trap: ['traps', 'shrug'],
+ glute: ['glutes', 'gluteus'], calf: ['calf', 'calves'], hip: ['hip'], rope: ['rope'], trx: ['suspension'],
+ ring: ['ring', 'suspension'], rings: ['ring', 'suspension'], kettle: ['kettlebell'], dumbel: ['dumbbell'],
+}
+
+// The forms a token may take: as typed, the shorthand it stands for, and the singular of a plural
+// ("curls" finds "curl", "raises" finds "raise", "presses" finds "press").
+function formsOf(tok) {
+ const out = [tok]
+ for (const s of SYNONYMS[tok] || []) out.push(s)
+ if (tok.length >= 4 && tok.endsWith('es') && !tok.endsWith('ses')) out.push(tok.slice(0, -2), tok.slice(0, -1))
+ else if (tok.length >= 4 && tok.endsWith('ses')) out.push(tok.slice(0, -2))
+ else if (tok.length >= 4 && tok.endsWith('s') && !tok.endsWith('ss')) out.push(tok.slice(0, -1))
+ return [...new Set(out)]
}
const queryTokens = query => normalizeStr(query || '').split(/\s+/).filter(Boolean)
@@ -358,13 +406,14 @@ function joinedHit(entry, tok) {
// 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))
+const literalHit = (entry, tok) => entry.s.includes(tok) || (tok.length >= 4 && joinedHit(entry, tok))
+const hits = (entry, tok) => formsOf(tok).some(form => literalHit(entry, form))
// 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 entry = corpusOf(e)
- return tokens.every(tok => hits(entry, tok) || (fuzzy.has(tok) && entry.nameWords.some(word => nearWord(tok, word))))
+ return tokens.every(tok => hits(entry, tok) || (fuzzy.has(tok) && formsOf(tok).some(f => entry.nameWords.some(word => nearWord(f, word)))))
}
// Single-exercise check, used where the list is filtered one option at a time (the exercise
@@ -386,5 +435,80 @@ export function searchExercises(list, query) {
const tokens = queryTokens(query)
if (!tokens.length) return list
const fuzzy = new Set(tokens.filter(tok => !list.some(e => hits(corpusOf(e), tok))))
- return list.filter(e => matchTokens(e, tokens, fuzzy))
+ return rankByRelevance(list.filter(e => matchTokens(e, tokens, fuzzy)), tokens)
}
+
+// How well one query token sits in an exercise: a whole word of the name beats the start of one,
+// which beats anywhere in the name, the name run together, a typo in the name, and last of all
+// another field (target, equipment, body part, muscles). Zero when it is not there at all.
+function tokenScore(entry, tok) {
+ let best = 0
+ for (const form of formsOf(tok)) {
+ const exact = form === tok ? 0 : 5 // a shorthand or singular counts a little less than typed
+ const words = form.split(' ')
+ if (words.length > 1) {
+ if (entry.name.includes(form)) best = Math.max(best, 90 - exact)
+ else if (entry.s.includes(form)) best = Math.max(best, 20 - exact)
+ continue
+ }
+ if (entry.nameWords.includes(form)) best = Math.max(best, 100 - exact)
+ else if (entry.nameWords.some(w => w.startsWith(form))) best = Math.max(best, 80 - exact)
+ else if (entry.name.includes(form)) best = Math.max(best, 60 - exact)
+ else if (form.length >= 4 && joinedHit(entry, form)) best = Math.max(best, 55 - exact)
+ else if (entry.nameWords.some(w => nearWord(form, w))) best = Math.max(best, 40 - exact)
+ else if (entry.s.includes(form)) best = Math.max(best, 20 - exact)
+ }
+ return best
+}
+
+// Among equally good matches, the one people most likely mean: the familiar core of the
+// catalogue (the exercises openGym shipped before v1.4.0), the common equipment, and a lift
+// before a stretch. Small on purpose: it orders ties, it never beats a better match.
+const CLASSIC = new Set(V13_IDS)
+const EQ_PRIOR = { barbell: 4, dumbbell: 4, cable: 3, 'leverage machine': 3, 'body weight': 3, 'smith machine': 2, kettlebell: 2, 'ez barbell': 2, 'sled machine': 2 }
+const CAT_PRIOR = { strength: 3, calisthenics: 3, olympic: 2, plyometrics: 1, isometric: 1, stretching: -3, mobility: -3, rehab: -4, yoga: -2, pilates: -2 }
+const priorOf = e => (CLASSIC.has(e.id) ? 3 : 0) + (EQ_PRIOR[e.eq] || 0) + (CAT_PRIOR[e.cat] || 0)
+
+// The matches in order of how well they match, shorter names first among equals (the plain
+// "barbell squat" before its six variations), and the list's own order after that: custom
+// exercises, which callers put first, stay first among equal matches.
+function rankByRelevance(found, tokens) {
+ const scored = found.map((e, i) => {
+ const entry = corpusOf(e)
+ return { e, i, score: tokens.reduce((sum, tok) => sum + tokenScore(entry, tok), 0) + priorOf(e), len: entry.nameWords.length }
+ })
+ scored.sort((a, b) => b.score - a.score || a.len - b.len || a.i - b.i)
+ return scored.map(x => x.e)
+}
+
+// Exercises that come close to a query without matching all of it: most of the words found, or
+// the words found with more typos than the exact search allows, or the name of something
+// similar. For the "Similar exercises" section under the results, so a search almost never ends
+// on "No match". `exclude` holds what the exact search already listed. Best first, at most `limit`.
+export function similarExercises(list, query, exclude = [], limit = 30) {
+ const tokens = queryTokens(query)
+ if (!tokens.length) return []
+ const skip = new Set(exclude)
+ const out = []
+ for (let i = 0; i < list.length; i++) {
+ const e = list[i]
+ if (skip.has(e)) continue
+ const entry = corpusOf(e)
+ let score = 0, found = 0
+ for (const tok of tokens) {
+ let best = tokenScore(entry, tok)
+ if (!best) {
+ // One more typo than the exact search allows, name words only.
+ const extra = typosFor(tok) + 1
+ if (tok.length >= 4 && formsOf(tok).some(f => entry.nameWords.some(w => editDistance(f, w, extra) <= extra))) best = 25
+ }
+ if (best) { found++; score += best }
+ }
+ // Half the words at least (one of one, one of two, two of three...), and for a one-word query
+ // a hit in the name, not just a shared body part.
+ if (found * 2 < tokens.length || !found || (tokens.length === 1 && score < 25)) continue
+ out.push({ e, i, score: score + found * 30 + priorOf(e), len: entry.nameWords.length })
+ }
+ out.sort((a, b) => b.score - a.score || a.len - b.len || a.i - b.i)
+ return out.slice(0, limit).map(x => x.e)
+}
\ No newline at end of file
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index f8d8caead..0d1b6d87f 100644
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@ -41,7 +41,7 @@ describe('Brazilian Portuguese locale', () => {
// has to be taught is a number nobody reads. What the numbers stood for is asserted above.
// If the hash fails, review the changed keys and wording before accepting a new one. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('b26830bf6168909344b7c2901d5463cbbd885118ffea665cba1d60bb2d2fdb15')
+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('27bc223129eafceba71df28ed1b4d61c1a5ea62a006e766f590dc6af476431e2')
})
// pt-PT labelled Unpair 'Desfazer': Undo, in Portuguese (it is pt-BR's Undo), on the button that
diff --git a/frontend/src/lib/search-typo.test.js b/frontend/src/lib/search-typo.test.js
index f38ce16bb..e45714d56 100644
--- a/frontend/src/lib/search-typo.test.js
+++ b/frontend/src/lib/search-typo.test.js
@@ -1,5 +1,5 @@
import { expect, it } from 'vitest'
-import { EXDB, matchExercise, normalizeStr, searchExercises } from './exercises.js'
+import { EXDB, matchExercise, normalizeStr, searchExercises, similarExercises } from './exercises.js'
const benchPress = {
n: 'dumbbell bench press', bp: 'chest', tg: 'pectorals', eq: 'dumbbell',
@@ -12,13 +12,26 @@ it('allows one edit or adjacent transposition in long query tokens', () => {
}
})
-it('keeps short tokens and multiple edits out of fuzzy matching', () => {
+it('allows one typo from four letters and two from seven, none in shorter words', () => {
const squat = { n: 'barbell squat', bp: 'legs', eq: 'barbell' }
- for (const [exercise, query] of [[squat, 'sqat'], [squat, 'roww'], [benchPress, 'dunbell'], [benchPress, 'dumbell unrelated'], [benchPress, 'bn ech']]) {
+ for (const [exercise, query] of [[squat, 'sqat'], [squat, 'squta'], [benchPress, 'dunbell'], [benchPress, 'dumbelll prss']]) {
+ expect(matchExercise(exercise, query), query).toBe(true)
+ }
+ for (const [exercise, query] of [[squat, 'roww'], [squat, 'sqt'], [benchPress, 'dmbll'], [benchPress, 'dumbell unrelated'], [benchPress, 'bn ech']]) {
expect(matchExercise(exercise, query), query).toBe(false)
}
})
+it('reads gym shorthand and plurals as the catalogue words', () => {
+ const rdl = { n: 'barbell romanian deadlift', bp: 'upper legs', eq: 'barbell' }
+ const curl = { n: 'dumbbell hammer curl', bp: 'upper arms', eq: 'dumbbell' }
+ expect(matchExercise(rdl, 'rdl')).toBe(true)
+ expect(matchExercise(rdl, 'bb rdl')).toBe(true)
+ expect(matchExercise(curl, 'db curls')).toBe(true)
+ expect(matchExercise(curl, 'hammer curls')).toBe(true)
+ expect(matchExercise(benchPress, 'db bp')).toBe(true)
+})
+
it('keeps existing exact substring and all-token behavior', () => {
expect(matchExercise(benchPress, 'bench pres')).toBe(true)
expect(matchExercise(benchPress, 'press bench')).toBe(true)
@@ -55,7 +68,7 @@ it('searchExercises takes a word literally when it hits anything exactly, and on
expect(names('wirst')).toEqual(['band wrist curl'])
expect(names('bnech press')).toEqual(['dumbbell bench press'])
expect(names('dumbell bench')).toEqual(['dumbbell bench press'])
- expect(names('sqat')).toEqual([])
+ expect(names('sqat')).toEqual(['barbell squat'])
expect(searchExercises(list, ' ')).toBe(list)
})
@@ -88,3 +101,29 @@ it('finds a name typed with its words run together or hyphenated', () => {
expect(matchExercise(highPull, 'highpull')).toBe(true)
expect(matchExercise(highPull, 'deadlift-high')).toBe(true)
})
+
+// v1.4.0: results come best first, and what is close but not exact is offered separately.
+it('ranks the plain, common exercise first among the matches', () => {
+ const first = q => searchExercises(EXDB, q)[0]?.n
+ expect(first('bench press')).toBe('barbell bench press')
+ expect(first('deadlift')).toBe('barbell deadlift')
+ expect(first('benchpres')).toMatch(/bench press$/)
+ expect(first('dumbel curl')).toMatch(/^dumbbell .*curl/)
+})
+
+it('offers similar exercises under the results, never repeating one', () => {
+ const exact = searchExercises(EXDB, 'machine shoulder press')
+ const close = similarExercises(EXDB, 'machine shoulder press', exact)
+ expect(close.length).toBeGreaterThan(0)
+ expect(close.some(e => exact.includes(e))).toBe(false)
+ expect(close.every(e => /shoulder|press/.test(e.n))).toBe(true)
+})
+
+it('finds something close when nothing matches exactly', () => {
+ // Heavy typos alone are still an exact hit now; one word that matches nothing is not.
+ expect(searchExercises(EXDB, 'dumbbellll bicepz curlz').length).toBeGreaterThan(0)
+ expect(searchExercises(EXDB, 'dumbbell curl qwxz')).toEqual([])
+ const close = similarExercises(EXDB, 'dumbbell curl qwxz')
+ expect(close.slice(0, 5).some(e => /dumbbell.*curl/.test(e.n))).toBe(true)
+ expect(similarExercises(EXDB, ' ')).toEqual([])
+})
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index aa4ffb547..7b002676a 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -2210,4 +2210,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} مُقيَّمة · {1} تقديرية من أصل {2} مجموعة',
'Enter the address of the server this token is for': 'أدخل عنوان الخادم الذي يخصّه هذا الرمز',
'Sent only to {0}, never to another server.': 'يُرسل إلى {0} فقط، ولا يُرسل إلى أي خادم آخر.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'تمارين مشابهة',
+ 'No exact match. These come close:': 'لا تطابق تام. هذه قريبة:',
}
diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.js
index 212fe61d5..39745f383 100644
--- a/frontend/src/locales/bn.js
+++ b/frontend/src/locales/bn.js
@@ -2234,4 +2234,7 @@ export default {
'All sets at the same weight.': 'সব সেট একই ওজনে।',
'Enter the address of the server this token is for': 'এই টোকেন যে সার্ভারের, তার ঠিকানা দিন',
'Sent only to {0}, never to another server.': 'শুধু {0}-এ পাঠানো হয়, অন্য কোনো সার্ভারে কখনো নয়।',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'একই ধরনের ব্যায়াম',
+ 'No exact match. These come close:': 'হুবহু মিল নেই। এগুলো কাছাকাছি:',
}
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index 0e0bbeaae..a54996bf8 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -2175,4 +2175,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} bewertet · {1} geschätzt, von {2} Sätzen',
'Enter the address of the server this token is for': 'Trag die Adresse des Servers ein, zu dem dieser Token gehört',
'Sent only to {0}, never to another server.': 'Geht nur an {0}, nie an einen anderen Server.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Ähnliche Übungen',
+ 'No exact match. These come close:': 'Kein genauer Treffer. Die hier kommen nah ran:',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 86675dcbc..fbfa422c9 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} valoradas · {1} estimadas de {2} series',
'Enter the address of the server this token is for': 'Introduce la dirección del servidor al que pertenece este token',
'Sent only to {0}, never to another server.': 'Solo se envía a {0}, nunca a otro servidor.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Ejercicios parecidos',
+ 'No exact match. These come close:': 'Nada exacto. Estos se acercan:',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index 66ac53246..6dd9b5430 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} notées · {1} estimées sur {2} séries',
'Enter the address of the server this token is for': 'Saisis l’adresse du serveur auquel appartient ce jeton',
'Sent only to {0}, never to another server.': 'Envoyé uniquement à {0}, jamais à un autre serveur.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Exercices similaires',
+ 'No exact match. These come close:': 'Rien d’exact. Ceux-ci s’en approchent :',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 4d7501449..57b07f370 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} रेट किए · {1} अनुमानित, कुल {2} सेट में से',
'Enter the address of the server this token is for': 'जिस सर्वर का यह टोकन है, उसका पता डालें',
'Sent only to {0}, never to another server.': 'सिर्फ़ {0} को भेजा जाता है, किसी दूसरे सर्वर को कभी नहीं।',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'मिलते-जुलते व्यायाम',
+ 'No exact match. These come close:': 'सटीक मेल नहीं मिला। ये करीब हैं:',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index 8be1aa86e..a496dfb81 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -2158,4 +2158,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} értékelt · {1} becsült ({2} sorozatból)',
'Enter the address of the server this token is for': 'Add meg annak a szervernek a címét, amelyhez ez a token tartozik',
'Sent only to {0}, never to another server.': 'Csak ide megy: {0}, más szerverre soha.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Hasonló gyakorlatok',
+ 'No exact match. These come close:': 'Nincs pontos találat. Ezek közel állnak:',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 4f1f789ee..8c3d96f6f 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} valutate · {1} stimate su {2} serie',
'Enter the address of the server this token is for': 'Inserisci l\'indirizzo del server a cui appartiene questo token',
'Sent only to {0}, never to another server.': 'Inviato solo a {0}, mai a un altro server.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Esercizi simili',
+ 'No exact match. These come close:': 'Niente di esatto. Questi ci vanno vicino:',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index d16347b8b..c906b2b53 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '총 {2}세트 중 {0}개 평가 · {1}개 추정',
'Enter the address of the server this token is for': '이 토큰을 쓸 서버 주소를 입력하세요',
'Sent only to {0}, never to another server.': '{0}에만 보내고 다른 서버에는 절대 보내지 않아요.',
+ // --- search: similar exercises ---
+ 'Similar exercises': '비슷한 운동',
+ 'No exact match. These come close:': '정확히 일치하는 항목이 없어요. 이건 비슷해요:',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 1a1087091..0525f3041 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': 'Ocenione: {0} · szacowane: {1} z {2} serii',
'Enter the address of the server this token is for': 'Podaj adres serwera, do którego należy ten token',
'Sent only to {0}, never to another server.': 'Wysyłany tylko do {0}, nigdy do innego serwera.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Podobne ćwiczenia',
+ 'No exact match. These come close:': 'Brak dokładnego dopasowania. Te są blisko:',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 994ce5881..9f283b0d1 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1330,6 +1330,7 @@ export const PT_BR_OVERRIDES = {
'Only if your server is behind Cloudflare Access: the service token this phone sends with every request to it. Kept in this phone’s secure storage.': 'Só se o seu servidor estiver atrás do Cloudflare Access: o token de serviço que este celular envia a cada requisição. Fica guardado no armazenamento seguro do celular.',
'Where an exercise is drawn on both figures. Your workouts stay exactly as they are.': 'Que figura mostra um exercício quando está desenhado nas duas. Seus treinos ficam exatamente como estão.',
'Enter the address of the server this token is for': 'Informe o endereço do servidor a que este token pertence',
+ 'No exact match. These come close:': 'Nada exato. Estes chegam perto:',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index b526462cd..31486ba97 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} avaliadas · {1} estimadas de {2} séries',
'Enter the address of the server this token is for': 'Introduz o endereço do servidor a que este token pertence',
'Sent only to {0}, never to another server.': 'Enviado só para {0}, nunca para outro servidor.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Exercícios semelhantes',
+ 'No exact match. These come close:': 'Nada exato. Estes andam perto:',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index c135b672a..9bbf9caa1 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -2159,4 +2159,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} с оценкой · {1} расчётных из {2} подходов',
'Enter the address of the server this token is for': 'Введите адрес сервера, к которому относится этот токен',
'Sent only to {0}, never to another server.': 'Отправляется только на {0} и никогда на другой сервер.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Похожие упражнения',
+ 'No exact match. These come close:': 'Точного совпадения нет. Вот что близко:',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index 0d8f053a0..475397099 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -2166,4 +2166,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': 'ให้คะแนนแล้ว {0} · ประมาณ {1} จาก {2} เซ็ต',
'Enter the address of the server this token is for': 'กรอกที่อยู่ของเซิร์ฟเวอร์ที่โทเค็นนี้ใช้ด้วย',
'Sent only to {0}, never to another server.': 'ส่งไปที่ {0} เท่านั้น ไม่ส่งไปเซิร์ฟเวอร์อื่นเลย',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'ท่าที่คล้ายกัน',
+ 'No exact match. These come close:': 'ไม่พบที่ตรงทั้งหมด ท่าเหล่านี้ใกล้เคียง:',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 85f120fc3..edf569226 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} puanlandı · {1} tahmini, toplam {2} set',
'Enter the address of the server this token is for': 'Bu token’ın ait olduğu sunucunun adresini gir',
'Sent only to {0}, never to another server.': 'Yalnızca {0} adresine gider, asla başka bir sunucuya gitmez.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Benzer egzersizler',
+ 'No exact match. These come close:': 'Tam eşleşme yok. Bunlar yakın:',
}
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 5cb156c16..fad71d4f9 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -2152,4 +2152,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} з оцінкою · {1} орієнтовних із {2} підходів',
'Enter the address of the server this token is for': 'Введи адресу сервера, до якого належить цей токен',
'Sent only to {0}, never to another server.': 'Надсилається лише на {0}, ніколи на інший сервер.',
+ // --- search: similar exercises ---
+ 'Similar exercises': 'Схожі вправи',
+ 'No exact match. These come close:': 'Точного збігу немає. Ось що близько:',
}
diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js
index cafb7cc97..ad7411e1d 100644
--- a/frontend/src/locales/zh-TW.js
+++ b/frontend/src/locales/zh-TW.js
@@ -2148,4 +2148,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} 組已評分 · {1} 組為估算,共 {2} 組',
'Enter the address of the server this token is for': '輸入這個權杖所屬伺服器的位址',
'Sent only to {0}, never to another server.': '只會傳送到 {0},絕不會傳給其他伺服器。',
+ // --- search: similar exercises ---
+ 'Similar exercises': '相似動作',
+ 'No exact match. These come close:': '沒有完全符合,這些比較接近:',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index 8a31351bc..c7b7277d9 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -2155,4 +2155,7 @@ export default {
'{0} rated · {1} estimated of {2} sets': '{0} 组已评分 · {1} 组为估算,共 {2} 组',
'Enter the address of the server this token is for': '输入这个令牌所属服务器的地址',
'Sent only to {0}, never to another server.': '只发送到 {0},绝不会发给其他服务器。',
+ // --- search: similar exercises ---
+ 'Similar exercises': '相似动作',
+ 'No exact match. These come close:': '没有完全匹配,这些比较接近:',
}
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 3ccdbdcfa..66ec8e5d1 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
-import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, searchExercises, exOr, isAssisted, betterWeight, beatsWeight, isCustomEx } from './lib/exercises.js'
+import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, searchExercises, similarExercises, exOr, isAssisted, betterWeight, beatsWeight, isCustomEx } from './lib/exercises.js'
import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile, profileEquipment, ACC_V } from './lib/equipment.js'
import { fmtDate, fmtDateRange, fmtNum, fmtPlate, exerciseNameText, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, setsWorkCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'
import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, sessionSections, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
@@ -1246,6 +1246,23 @@ function ExercisePicker({ onPick, title, close, like }) {
const narrowed = !!(q.trim() || bp || eqOn)
useRevealActiveChip(bpStrip, bp)
useRevealActiveChip(eqStrip, eqOn)
+ // Close but not exact (a typo too many, most of the words, a similar name), listed under the
+ // results once you have scrolled to their end, so a search almost never ends on nothing.
+ const similar = q.trim() && !special && f.length <= shown
+ ? similarExercises((profile && !showAll ? all.filter(e => exAvailable(st, e)) : all).filter(e => bp === SAME || !bp || e.bp === bp), q, f, f.length ? 12 : 30)
+ : []
+ const pickRow = e => <div key={e.id} className="item" {...tappable(() => onPick(e))}>
+ <Thumb ex={e} /><div className="grow"><div className={`tt ${exerciseNameClass(e)}`}>{isFav(st, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}</div></div>
+ {/* Accent tag = already in a routine/log ("Chosen"); the yellow star by the name = favourite. */}
+ {usage[e.id] && <span className="tag acc"><Icon name="starFill" /></span>}
+ {/* A "+" glyph reads as "add this now" — it used to just open the same detail sheet as
+ tapping the row, so it added nothing until you'd scrolled past the sets/reps config
+ and found the real button. Now it does what it looks like: adds with the default
+ config right away. Tapping the row itself still opens the detail/config sheet, for
+ when you want to set sets/reps before adding. */}
+ <button className="iconbtn chev" aria-label={t('Add “{0}”', exerciseNameFor(e))} style={{ padding: 8, margin: -8 }}
+ onClick={ev => { ev.stopPropagation(); onPick(e, true) }}><Icon name="plus" /></button>
+ </div>
if (byMuscle) return <>
<div className="row between" style={{ marginBottom: 10 }}><h3>{title || t('Add exercise')}</h3>
<Button size="sm" variant="ghost" onClick={() => setByMuscle(false)}>{t('All')}</Button>
@@ -1291,20 +1308,11 @@ function ExercisePicker({ onPick, title, close, like }) {
<div className="thumb thumb-x"><Icon name="plusCircle" /></div>
<div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, and a photo or video if you like')}</div></div><Icon name="plus" className="chev" />
</div>}
- {f.slice(0, shown).map(e => <div key={e.id} className="item" {...tappable(() => onPick(e))}>
- <Thumb ex={e} /><div className="grow"><div className={`tt ${exerciseNameClass(e)}`}>{isFav(st, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}</div></div>
- {/* Accent tag = already in a routine/log ("Chosen"); the yellow star by the name = favourite. */}
- {usage[e.id] && <span className="tag acc"><Icon name="starFill" /></span>}
- {/* A "+" glyph reads as "add this now" — it used to just open the same detail sheet as
- tapping the row, so it added nothing until you'd scrolled past the sets/reps config
- and found the real button. Now it does what it looks like: adds with the default
- config right away. Tapping the row itself still opens the detail/config sheet, for
- when you want to set sets/reps before adding. */}
- <button className="iconbtn chev" aria-label={t('Add “{0}”', exerciseNameFor(e))} style={{ padding: 8, margin: -8 }}
- onClick={ev => { ev.stopPropagation(); onPick(e, true) }}><Icon name="plus" /></button>
- </div>)}
+ {f.slice(0, shown).map(pickRow)}
{f.length === 0 && bp === '★' && <div className="empty">{t('Nothing picked yet. Add some exercises and they’ll show up here.')}</div>}
{f.length === 0 && bp === '☆' && <div className="empty">{t('No favourites yet. Tap the star on an exercise to add one.')}</div>}
+ {similar.length > 0 && <h4 className="sec similar-label">{f.length ? t('Similar exercises') : t('No exact match. These come close:')}</h4>}
+ {similar.map(pickRow)}
</div>
{f.length > shown && <><div style={{ height: 8 }} /><Button ref={moreRef} onClick={() => setShown(s => s + 50)}>{t('Show more')}</Button></>}
</>
diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsx
index a5e410884..0bb0db701 100644
--- a/frontend/src/views/Library.jsx
+++ b/frontend/src/views/Library.jsx
@@ -1,7 +1,7 @@
import { useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
-import { EXDB, BODYPARTS, allExercises, equipmentOf, categoriesOf, searchExercises } from '../lib/exercises.js'
+import { EXDB, BODYPARTS, allExercises, equipmentOf, categoriesOf, searchExercises, similarExercises } from '../lib/exercises.js'
import { MUSCLE_NAME } from '../lib/muscles.js'
import { activeProfile, exAvailable } from '../lib/equipment.js'
import { bestWeightFor } from '../lib/history.js'
@@ -49,6 +49,20 @@ export default function Library() {
// A live count at the end of the search field while a search or filter narrows the list
// (idea and first version: GitLab !31) — how many are left, before scrolling to find out.
const narrowed = !!(q.trim() || bp || eqOn || catOn)
+ // Close but not exact (a typo too many, most of the words, a similar name), under the results
+ // once they are all on screen, so a search almost never ends on "No match".
+ const similar = q.trim() && f.length <= shown
+ ? similarExercises(allExercises(S).filter(e => (!bp || e.bp === bp) && (!profile || showAll || exAvailable(S, e))), q, f, f.length ? 12 : 30)
+ : []
+ const row = e => {
+ const best = bestWeightFor(S, e.id)
+ return <div key={e.id} className="item" {...tappable(() => exerciseDetailSheet(e))}>
+ <Thumb ex={e} />
+ <div className="grow"><div className={`tt ${exerciseNameClass(e)}`}>{isFav(S, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}</div></div>
+ {best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
+ <Button size="sm" variant="tinted" icon="plus" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>{t('Plan')}</Button>
+ </div>
+ }
return <>
<div className="hdr lib-hdr"><div><h1>{t('Exercises')}</h1></div>
@@ -89,16 +103,10 @@ export default function Library() {
<div className="thumb thumb-x"><Icon name="plusCircle" /></div>
<div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, and a photo or video if you like')}</div></div><Icon name="plus" className="chev" />
</div>
- {f.slice(0, shown).map(e => {
- const best = bestWeightFor(S, e.id)
- return <div key={e.id} className="item" {...tappable(() => exerciseDetailSheet(e))}>
- <Thumb ex={e} />
- <div className="grow"><div className={`tt ${exerciseNameClass(e)}`}>{isFav(S, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}</div></div>
- {best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
- <Button size="sm" variant="tinted" icon="plus" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>{t('Plan')}</Button>
- </div>
- })}
- {f.length === 0 && <div className="empty"><div className="ico"><Icon name="magnifier" /></div>{t('No match')}</div>}
+ {f.slice(0, shown).map(row)}
+ {f.length === 0 && !similar.length && <div className="empty"><div className="ico"><Icon name="magnifier" /></div>{t('No match')}</div>}
+ {similar.length > 0 && <h4 className="sec similar-label">{f.length ? t('Similar exercises') : t('No exact match. These come close:')}</h4>}
+ {similar.map(row)}
</div>
{f.length > shown && <><div style={{ height: 10 }} /><Button ref={moreRef} onClick={() => setShown(s => s + 40)}>{t('Show more')}</Button></>}
</>