highlighted results are misleading

Author: Wxh16144Created Jul 3, 2025Updated Nov 12, 2025

First, thank you for this library and its rich API. I've spent several days carefully studying the documentation and have implemented most of my desired functionality. However, I'm encountering a confusing highlighting result that I can't resolve.

Minimal Reproduction:

javascript
import { Document, Charset } from "https://cdn.jsdelivr.net/gh/nextapps-de/[email protected]/dist/flexsearch.compact.module.min.js";

const data = [
  { "id": 1, "title": "Carmencita" },
  { "id": 2, "title": "en-US.json" }
];

const index = new Document({
  document: {
    store: true,
    index: [{
      field: "title",
      // tokenize: "full",
      // encoder: Charset.Default
    }]
  }
});

data.forEach(item => index.add(item));

const result = index.search({
  query: 'en',
  enrich: true,
  highlight: { template: "<b>$1</b>" }
});

Actual Result:

json
[
  {
    "field": "title",
    "result": [
      {
        "id": 2,
        "doc": {
          "id": 2,
          "title": "en-US.json"
        },
        "highlight": "<b>e</b>n-US.json"
      }
    ]
  }
]

Expected Behavior:
When searching for "en", I expect the highlight to wrap the entire matched term:
"highlight": "<b>en</b>-US.json"

Troubleshooting Attempted:

  • Adjusted tokenize option (tried "full" and defaults)
  • Tested different encoder settings (including Charset.Default)
  • Verified with multiple term lengths (always highlights only first character)

The issue persists regardless of configuration. Could someone please advise if I'm missing something or if this is a potential bug? Any guidance would be greatly appreciated!