Documentation
¶
Index ¶
- type BM25F
- func (bm *BM25F) MarshalJSON() ([]byte, error)
- func (bm *BM25F) Score(corpus *Corpus, query []string) []Result
- func (bm *BM25F) SetB(field string, b float64) error
- func (bm *BM25F) SetK1(k1 float64) error
- func (bm *BM25F) SetWeight(field string, weight float64) error
- func (bm *BM25F) UnmarshalJSON(data []byte) error
- type Corpus
- type Document
- func (d *Document) Count(field, term string) int
- func (d *Document) FieldLen(field string) int
- func (d *Document) FieldNames() []string
- func (d *Document) MarshalJSON() ([]byte, error)
- func (d *Document) Metadata(name string) (string, bool)
- func (d *Document) SetField(name string, tokens []string)
- func (d *Document) SetMetadata(name string, text string)
- func (d *Document) UnmarshalJSON(data []byte) error
- type DocumentOption
- type Field
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BM25F ¶
type BM25F struct {
// contains filtered or unexported fields
}
func (*BM25F) MarshalJSON ¶ added in v0.3.0
func (*BM25F) Score ¶
Score calculates how well each document matches the query. The results include every document and are unsorted—to remove non-matches and sort the results, use Rank or do it yourself.
func (*BM25F) SetB ¶
SetB sets the `b` parameter of the BM25F algorithm. It controls the strength of field length normalizations. With a value of 0, field lengths are not taken into consideration. With a value of 1, field lengths are fully normalized. For most corpora, a value between 0.5 and 0.8 is good. The default is 0.72.
An error is returned if the value is less than 0 or greater than 1.
func (*BM25F) SetK1 ¶
SetK1 sets the `k1` parameter of the BM25F algorithm. It controls the impact of frequent terms on the scores. With lower values, frequent terms affect the score less. With higher values, frequent terms affect the score more. For most corpora, a value between 1.2 and 2 is good. The default is 1.2.
An error is returned if the value is less than or equal to 0.
func (*BM25F) SetWeight ¶
SetWeight sets the relative weight of the field. The field with the bulk of the content should be 1.0. The default is 1.0
An error is returned if the value is less than 0.
func (*BM25F) UnmarshalJSON ¶ added in v0.3.0
type Corpus ¶
type Corpus struct {
// contains filtered or unexported fields
}
func (*Corpus) MarshalJSON ¶ added in v0.3.0
func (*Corpus) UnmarshalJSON ¶ added in v0.3.0
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a searchable entity in the corpus. It can have multiple independently configured fields that contribute to its search ranking.
func NewDocument ¶ added in v0.3.0
func NewDocument(opts ...DocumentOption) *Document
func (*Document) Count ¶ added in v0.3.0
Count returns the number of times a term appears in a field.
func (*Document) FieldNames ¶ added in v0.3.0
FieldNames returns the names of all document fields in lexicographic order.
func (*Document) MarshalJSON ¶ added in v0.3.0
func (*Document) Metadata ¶ added in v0.3.0
Metadata gets a metadata entry associated with the document. It is the same value previously passed to SetMetadata.
func (*Document) SetField ¶ added in v0.3.0
SetField sets a document field to represent the given tokens.
func (*Document) SetMetadata ¶ added in v0.3.0
SetMetadata sets data that is not parsed or used by BM25F, but it is included in results from BM25F.Score.
func (*Document) UnmarshalJSON ¶ added in v0.3.0
type DocumentOption ¶ added in v0.3.0
type DocumentOption func(d *Document)
func WithField ¶ added in v0.3.0
func WithField(name string, tokens []string) DocumentOption
func WithMetadata ¶ added in v0.3.0
func WithMetadata(name string, text string) DocumentOption
type Field ¶ added in v0.3.0
type Field struct {
// contains filtered or unexported fields
}
Field is a part of a document, such as the title, byline, or body.
Use Document.SetField to set a field value for a document.
func (*Field) MarshalJSON ¶ added in v0.3.0
func (*Field) UnmarshalJSON ¶ added in v0.3.0
type Result ¶
type Result struct {
ID string
// Score indicates how well the document matches the query.
//
// A value of 0 indicates no match.
// Other values are meaningless except in comparison to other results:
// a higher value indicates a better match.
Score float64
// contains filtered or unexported fields
}