0
0

get correct field first, then use it for looking up related

This commit is contained in:
Marty Schoch 2014-09-03 16:09:51 -04:00
parent 8e6c8e5644
commit 7fbd44224d
2 changed files with 12 additions and 13 deletions

View File

@ -55,11 +55,16 @@ func (q *matchQuery) SetField(f string) Query {
func (q *matchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) { func (q *matchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
field := q.FieldVal
if q.FieldVal == "" {
field = i.m.DefaultField
}
analyzerName := "" analyzerName := ""
if q.Analyzer != "" { if q.Analyzer != "" {
analyzerName = q.Analyzer analyzerName = q.Analyzer
} else { } else {
analyzerName = i.m.analyzerNameForPath(q.FieldVal) analyzerName = i.m.analyzerNameForPath(field)
} }
analyzer := i.m.analyzerNamed(analyzerName) analyzer := i.m.analyzerNamed(analyzerName)
@ -67,11 +72,6 @@ func (q *matchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, erro
return nil, fmt.Errorf("no analyzer named '%s' registered", q.Analyzer) return nil, fmt.Errorf("no analyzer named '%s' registered", q.Analyzer)
} }
field := q.FieldVal
if q.FieldVal == "" {
field = i.m.DefaultField
}
tokens := analyzer.Analyze([]byte(q.Match)) tokens := analyzer.Analyze([]byte(q.Match))
if len(tokens) > 0 { if len(tokens) > 0 {

View File

@ -56,22 +56,22 @@ func (q *matchPhraseQuery) SetField(f string) Query {
func (q *matchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) { func (q *matchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
field := q.FieldVal
if q.FieldVal == "" {
field = i.m.DefaultField
}
analyzerName := "" analyzerName := ""
if q.Analyzer != "" { if q.Analyzer != "" {
analyzerName = q.Analyzer analyzerName = q.Analyzer
} else { } else {
analyzerName = i.m.analyzerNameForPath(q.FieldVal) analyzerName = i.m.analyzerNameForPath(field)
} }
analyzer := i.m.analyzerNamed(analyzerName) analyzer := i.m.analyzerNamed(analyzerName)
if analyzer == nil { if analyzer == nil {
return nil, fmt.Errorf("no analyzer named '%s' registered", q.Analyzer) return nil, fmt.Errorf("no analyzer named '%s' registered", q.Analyzer)
} }
field := q.FieldVal
if q.FieldVal == "" {
field = i.m.DefaultField
}
tokens := analyzer.Analyze([]byte(q.MatchPhrase)) tokens := analyzer.Analyze([]byte(q.MatchPhrase))
if len(tokens) > 0 { if len(tokens) > 0 {
ts := make([]string, len(tokens)) ts := make([]string, len(tokens))
@ -80,7 +80,6 @@ func (q *matchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
} }
phraseQuery := NewPhraseQuery(ts, field).SetBoost(q.BoostVal) phraseQuery := NewPhraseQuery(ts, field).SetBoost(q.BoostVal)
return phraseQuery.Searcher(i, explain) return phraseQuery.Searcher(i, explain)
} }
noneQuery := NewMatchNoneQuery() noneQuery := NewMatchNoneQuery()