fergiemcdowall / search-index

A persistent, network resilient, full text search library for the browser and Node.js
MIT License
1.39k stars 149 forks source link

WEIGHT selected fields #526

Closed fergiemcdowall closed 2 years ago

fergiemcdowall commented 3 years ago

When conducting SCOREd queries, it should be possible to WEIGHT named fields. Possibly WEIGHT should be a sub-option of SCORE?

// Weight OR queries
QUERY({
  SEARCH: [
    'make:landrover',
    OR: [ 'model:defender', 'model:110', 'model:90' ]
  ]
}, {
  SCORE: {
    WEIGHT: {
      'model:defender': 0.5,  // I'm not that bothered about Defenders
      'model:90': 2           // Im all about the 90s
    }
  }
})
// TODO: weight AND queries
QUERY({
  SEARCH: [ 'london', 'manchester' ]
}, {
  SCORE: {
    WEIGHT: {
      'location': 2  // boost docs that have 'london' or 'manchester' in the location field
    }
  }
})
// TODO: weight AND queries, prefer one token
QUERY({
  SEARCH: [ 'london', 'manchester' ]
}, {
  SCORE: {
    WEIGHT: {
      'location:london': 2  // boost docs that have 'london' OVER 'manchester' in the location field
    }
  }
})
fergiemcdowall commented 3 years ago

Should be able to weight several fields at once

fergiemcdowall commented 2 years ago

Released in v3 see tests and docs