Skip to content

Threshold not working correctly for multiple content types #226

Description

@RaulJMCD

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

  1. Configure multiple content types with transliterate: true and threshold: 0.6
  2. Search for a term that exists in some content types but not others (e.g., "premio")
  3. Observe that news-article returns only relevant results
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions