Threshold not working correctly for multiple content types
Description
When using transliterate: true with threshold: 0.6 (or similar values), the plugin returns irrelevant results that don't contain the search query in their titles for some content types, while working correctly for others with the same configuration.
Environment
- Plugin Version:
4.0.0-beta.1
- Strapi Version:
5.13.1
- fuzzysort Version:
3.1.0
Configuration
All content types have identical configuration:
{
uid: 'api::news-article.news-article',
modelName: 'news-article',
transliterate: true,
fuzzysortOptions: {
characterLimit: 300,
threshold: 0.6,
limit: 10,
keys: [
{
name: 'title',
weight: 1,
},
],
},
}
Same configuration applied to: news-article, doc, job, training, scholarship.
Steps to Reproduce
- Configure multiple content types with
transliterate: true and threshold: 0.6
- Search for a term that exists in some content types but not others (e.g., "premio")
- Observe that
news-article returns only relevant results
- Observe that
doc, job, training, scholarship return results that don't contain the search term in their titles
Expected Behavior
All content types should respect the threshold configuration and only return results that match the search query with a score above the threshold, regardless of whether transliterate is enabled.
Actual Behavior
news-article: Works correctly, only returns relevant results
doc, job, training, scholarship: Return irrelevant results that don't contain the search query in their titles
Example
Search Query: premio
Expected: Only results with "premio" in the title (or transliterated equivalent)
Actual:
news-article: ✅ Returns only relevant results
training: ❌ Returns results like "Curso Pediátrico: Neumología, Alergia y Fibrosis Quística" (doesn't contain "premio")
Code Analysis
Looking at dist/server/index.js, the buildTransliteratedResult function (lines 185-216) has logic that combines results from normal and transliterated searches:
if (!result.total) return transliteratedResult;
const newResults = [...result];
transliteratedResult.forEach((res) => {
const origIndex = newResults.findIndex(
(origRes) => origRes.obj.id === res.obj.id && origRes.score <= res.score
);
if (origIndex >= 0) newResults[origIndex] = res;
});
The threshold is passed to fuzzysort (line 199), so it should filter results. However, when combining results from both searches, the code may be including results that don't meet the threshold requirement.
Additional Context
- The issue might occurs when
transliterate: true is enabled
- All content types have identical configuration
- The threshold is correctly passed to fuzzysort in both
buildResult and buildTransliteratedResult
- This suggests the problem may be in how results are combined when transliteration is active
Threshold not working correctly for multiple content types
Description
When using
transliterate: truewiththreshold: 0.6(or similar values), the plugin returns irrelevant results that don't contain the search query in their titles for some content types, while working correctly for others with the same configuration.Environment
4.0.0-beta.15.13.13.1.0Configuration
All content types have identical configuration:
Same configuration applied to:
news-article,doc,job,training,scholarship.Steps to Reproduce
transliterate: trueandthreshold: 0.6news-articlereturns only relevant resultsdoc,job,training,scholarshipreturn results that don't contain the search term in their titlesExpected Behavior
All content types should respect the
thresholdconfiguration and only return results that match the search query with a score above the threshold, regardless of whethertransliterateis enabled.Actual Behavior
news-article: Works correctly, only returns relevant resultsdoc,job,training,scholarship: Return irrelevant results that don't contain the search query in their titlesExample
Search Query:
premioExpected: Only results with "premio" in the title (or transliterated equivalent)
Actual:
news-article: ✅ Returns only relevant resultstraining: ❌ Returns results like "Curso Pediátrico: Neumología, Alergia y Fibrosis Quística" (doesn't contain "premio")Code Analysis
Looking at
dist/server/index.js, thebuildTransliteratedResultfunction (lines 185-216) has logic that combines results from normal and transliterated searches:The threshold is passed to fuzzysort (line 199), so it should filter results. However, when combining results from both searches, the code may be including results that don't meet the threshold requirement.
Additional Context
transliterate: trueis enabledbuildResultandbuildTransliteratedResult