Skip to content

Commit

Permalink
docs: add description for fieldNormWeight
Browse files Browse the repository at this point in the history
Fixes #603
  • Loading branch information
krisk committed Dec 23, 2021
1 parent af78b2e commit 36bada4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions docs/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,11 @@ When `true`, the calculation for the relevance score (used for sorting) will ign
The only time it makes sense to set `ignoreFieldNorm` to `true` is when it does not matter how many terms there are, but only that the query term exists.
:::

### `fieldNormWeight`

- Type: `number`
- Default: `1`

Determines how much the [field-length norm](/concepts/scoring-theory.html#field-length-norm) affects scoring. A value of `0` is equivalent to ignoring the field-length norm. A value of `0.5` will greatly reduce the effect of field-length norm, while a value of `2.0` will greatly increase it.

<Donate />
2 changes: 1 addition & 1 deletion docs/concepts/scoring-theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ User inputted weight of the key. The higher the weight, the higher its relevance
The shorter the field, the higher its relevance. If a pattern matches a short field (such as a `title` field) it is likely to be more relevant than the same pattern matched with a bigger field. This is calculated at index time.

::: tip
You can ignore the field-length norm by setting `ignoreFieldNorm` to `true`.
You can ignore the field-length norm by setting `ignoreFieldNorm` to `true`. Alternatively, you can configure how much the field-length norm affects your scoring by setting `fieldNormWeight` to a value other than 1 (the default).
:::

<Donate />
16 changes: 13 additions & 3 deletions src/tools/FuseIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import normGenerator from './norm'
import { createKey } from './KeyStore'

export default class FuseIndex {
constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
constructor({
getFn = Config.getFn,
fieldNormWeight = Config.fieldNormWeight
} = {}) {
this.norm = normGenerator(fieldNormWeight, 3)
this.getFn = getFn
this.isCreated = false
Expand Down Expand Up @@ -147,15 +150,22 @@ export default class FuseIndex {
}
}

export function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
export function createIndex(
keys,
docs,
{ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}
) {
const myIndex = new FuseIndex({ getFn, fieldNormWeight })
myIndex.setKeys(keys.map(createKey))
myIndex.setSources(docs)
myIndex.create()
return myIndex
}

export function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
export function parseIndex(
data,
{ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}
) {
const { keys, records } = data
const myIndex = new FuseIndex({ getFn, fieldNormWeight })
myIndex.setKeys(keys)
Expand Down

0 comments on commit 36bada4

Please sign in to comment.