Skip to content

Add search result metadata to returned collection, expose scores #5

@andymerskin

Description

@andymerskin

It would be cool if the filtered collection provided metadata for the search results, like scores for each result, or keywords that were matched.

Use cases:

  • Create heatmaps from scores in results
  • Bundle or group results based on score ranges
  • Pass results to another library or plugin to be parsed or filtered further
  • Display UI indicators when keywords match (or don't match)

Example:

search.query('red button up shirts with pocket')

Return value:

{
  keywords: {
    feature: {
      hasMatch: true,
      matches: ['pocket', 'button up'] // matched keyword queries
    },
    color: {
      hasMatch: false,
      matches: ['red']
    }
  },

  results: [
    {
      ...result, // result item data from collection
      score: 9.16,
      fields: {
        productName: {
          score: 0.92,
          boost: 9
        },
        productDescription: {
          score: 0.11,
          boost: 8
        }
      }
    }
  ]
}

Questions

  • Is performance a concern? Maybe this data should only be surfaced when an option is passed, and by default, the results array is the only output.
    • Return value should always be an object, where the results array can be extracted in any case.
    search.query('red button up shirts with pocket', {
      metadata: true
    })

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions