meilisearch / meilisearch-js-plugins

The search client to use Meilisearch with InstantSearch.
https://www.meilisearch.com
MIT License
470 stars 57 forks source link

instant-meilisearch: _matchesPosition does not appear in adapted hits #1305

Closed mavcook closed 2 months ago

mavcook commented 3 months ago

Description

When using showMatchesPosition=true, the _matchesPosition field does not appear in the instantsearch hits.

I believe I narrowed this down and is due to the _matchesPosition not being assigned to the adapted hit here.

Reproducing

  1. Setup: Modify the vanillajs playground to use showMatchesPosition:
    
    const search = instantsearch({
    indexName: 'steam-video-games',
    searchClient: instantMeiliSearch(
    'https://ms-adf78ae33284-106.lon.meilisearch.io',
    'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303',
    {
      finitePagination: true,
      meiliSearchParams: {showMatchesPosition: true},
    }
    ).searchClient,
    })

... // add transformItems so we can log for debugging instantsearch.widgets.hits({ container: '#hits', transformItems(items) { console.log('Here are the results', items) return items }, ...

2. Search 'half' in the playground

### Expected behavior
Searching 'half' in the vanillajs playground should give this as the first hit

Note the `_matchesPosition` field in the json below
<details>
<summary>Expected first result</summary>

```json
{
  "name": [
      {
          "start": 0,
          "length": 4
      }
  ],
  "description": "Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences.",
  "id": "50",
  "price": "4.99 $",
  "image": "http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813",
  "releaseDate": "Nov 1 1999",
  "recommendationCount": 2934,
  "platforms": [
      "MacOS",
      "Linux",
      "Windows"
  ],
  "players": [
      "Single player",
      "Multiplayer"
  ],
  "genres": [
      "Action"
  ],
  "misc": [],
  "_highlightResult": {
      "name": {
          "value": "<mark>Half</mark>-Life: Opposing Force"
      },
      "description": {
          "value": "Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences."
      },
      "id": {
          "value": "50"
      },
      "price": {
          "value": "4.99 $"
      },
      "image": {
          "value": "http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813"
      },
      "releaseDate": {
          "value": "Nov 1 1999"
      },
      "recommendationCount": {
          "value": "2934"
      },
      "platforms": [
          {
              "value": "MacOS"
          },
          {
              "value": "Linux"
          },
          {
              "value": "Windows"
          }
      ],
      "players": [
          {
              "value": "Single player"
          },
          {
              "value": "Multiplayer"
          }
      ],
      "genres": [
          {
              "value": "Action"
          }
      ],
      "misc": []
  },
  "_snippetResult": {
      "name": {
          "value": "<mark>Half</mark>-Life: Opposing Force"
      },
      "description": {
          "value": "Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences."
      },
      "id": {
          "value": "50"
      },
      "price": {
          "value": "4.99 $"
      },
      "image": {
          "value": "http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813"
      },
      "releaseDate": {
          "value": "Nov 1 1999"
      },
      "recommendationCount": {
          "value": "2934"
      },
      "platforms": [
          {
              "value": "MacOS"
          },
          {
              "value": "Linux"
          },
          {
              "value": "Windows"
          }
      ],
      "players": [
          {
              "value": "Single player"
          },
          {
              "value": "Multiplayer"
          }
      ],
      "genres": [
          {
              "value": "Action"
          }
      ],
      "misc": []
  },
  "_matchesPosition": {
      "name": [
          {
              "start": 0,
              "length": 4
          }
      ]
  },
  "__position": 1
}

Current behavior

No _matchesPosition field in first result for 'half' query

Current first result ```json { "name": [ { "start": 0, "length": 4 } ], "description": "Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences.", "id": "50", "price": "4.99 $", "image": "http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813", "releaseDate": "Nov 1 1999", "recommendationCount": 2934, "platforms": [ "MacOS", "Linux", "Windows" ], "players": [ "Single player", "Multiplayer" ], "genres": [ "Action" ], "misc": [], "_highlightResult": { "name": { "value": "Half-Life: Opposing Force" }, "description": { "value": "Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences." }, "id": { "value": "50" }, "price": { "value": "4.99 $" }, "image": { "value": "http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813" }, "releaseDate": { "value": "Nov 1 1999" }, "recommendationCount": { "value": "2934" }, "platforms": [ { "value": "MacOS" }, { "value": "Linux" }, { "value": "Windows" } ], "players": [ { "value": "Single player" }, { "value": "Multiplayer" } ], "genres": [ { "value": "Action" } ], "misc": [] }, "_snippetResult": { "name": { "value": "Half-Life: Opposing Force" }, "description": { "value": "Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences." }, "id": { "value": "50" }, "price": { "value": "4.99 $" }, "image": { "value": "http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813" }, "releaseDate": { "value": "Nov 1 1999" }, "recommendationCount": { "value": "2934" }, "platforms": [ { "value": "MacOS" }, { "value": "Linux" }, { "value": "Windows" } ], "players": [ { "value": "Single player" }, { "value": "Multiplayer" } ], "genres": [ { "value": "Action" } ], "misc": [] }, "__position": 1 } ```

Environment:

curquiza commented 3 months ago

Thank you @mavcook for the report

For anyone: any PR is welcome ❤️