Skip to content

highlighted results are misleading #514

@Wxh16144

Description

@Wxh16144

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:

import { Document, Charset } from "https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.8.2/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:

[
  {
    "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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions