Skip to content

Commit

Permalink
default similarity config for an index
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejas-bhat committed Jan 6, 2025
1 parent 36db386 commit e83cca0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ func TestBM25(t *testing.T) {
indexMapping := NewIndexMapping()
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = "en"
indexMapping.DefaultSimilarity = index.BM25Similarity
documentMapping := NewDocumentMapping()
indexMapping.AddDocumentMapping("hotel", documentMapping)
indexMapping.StoreDynamic = false
Expand Down
9 changes: 8 additions & 1 deletion mapping/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,14 @@ func (im *IndexMappingImpl) FieldMappingForPath(path string) FieldMapping {
return *fm
}

return FieldMapping{}
// the edge case where there are no field mapping defined for a path, just
// return all the field specific defaults from the index mapping.
fm = &FieldMapping{
Analyzer: im.DefaultAnalyzer,
Similarity: im.DefaultSimilarity,
SynonymSource: im.DefaultSynonymSource,
}
return *fm
}

// wrapper to satisfy new interface
Expand Down
2 changes: 1 addition & 1 deletion search/scorer/scorer_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *TermQueryScorer) scoreExplanation(tf float64, termMatch *index.TermFiel
saturationExplanation := &search.Explanation{
Value: k1 / (tf + k1*fieldNormVal),
Message: fmt.Sprintf("saturation(term:%s), k1=%f/(tf=%f + k1*fieldNorm=%f))",
termMatch.Term, tf, k1, fieldNormVal),
termMatch.Term, k1, tf, fieldNormVal),
Children: []*search.Explanation{fieldNormalizeExplanation},
}

Expand Down

0 comments on commit e83cca0

Please sign in to comment.