diff --git a/index_test.go b/index_test.go index 7fb3abf0c..df663c0cb 100644 --- a/index_test.go +++ b/index_test.go @@ -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 diff --git a/mapping/index.go b/mapping/index.go index 6399bef20..70b333e86 100644 --- a/mapping/index.go +++ b/mapping/index.go @@ -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 diff --git a/search/scorer/scorer_term.go b/search/scorer/scorer_term.go index 7c4d6fab9..5521e83ac 100644 --- a/search/scorer/scorer_term.go +++ b/search/scorer/scorer_term.go @@ -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}, }