0
0
Fork 0

simplify FieldMapping.analyzerForField()

I stumbled onto that while trying to understand how analyzers are
resolved. The new code looks simpler to me and removes useless calls to
DocumentMapping.defaultAnalyzerName() when an analyzer is set at
FieldMapping level.

The slight change to TestStoredFieldPreserved avoids a stacktrace when
the test fails.
This commit is contained in:
Patrick Mezard 2015-10-02 15:35:48 +02:00
parent 21473509b2
commit 498e4a0de7
2 changed files with 6 additions and 6 deletions

View File

@ -433,7 +433,7 @@ func TestStoredFieldPreserved(t *testing.T) {
}
if len(res.Hits) != 1 {
t.Errorf("expected 1 hit, got %d", len(res.Hits))
t.Fatalf("expected 1 hit, got %d", len(res.Hits))
}
if res.Hits[0].Fields["name"] != "Marty" {

View File

@ -132,12 +132,12 @@ func (fm *FieldMapping) processTime(propertyValueTime time.Time, pathString stri
}
func (fm *FieldMapping) analyzerForField(path []string, context *walkContext) *analysis.Analyzer {
analyzerName := context.dm.defaultAnalyzerName(path)
analyzerName := fm.Analyzer
if analyzerName == "" {
analyzerName = context.im.DefaultAnalyzer
}
if fm.Analyzer != "" {
analyzerName = fm.Analyzer
analyzerName = context.dm.defaultAnalyzerName(path)
if analyzerName == "" {
analyzerName = context.im.DefaultAnalyzer
}
}
return context.im.analyzerNamed(analyzerName)
}