added test for more complex nested conjunction
This commit is contained in:
parent
b6ba2efdef
commit
5de10307d8
|
@ -107,7 +107,7 @@ func (s *TermConjunctionSearcher) Next() (*DocumentMatch, error) {
|
|||
OUTER:
|
||||
for s.currentId != "" {
|
||||
for i, termSearcher := range s.searchers {
|
||||
if s.currs[i].ID != s.currentId {
|
||||
if s.currs[i] != nil && s.currs[i].ID != s.currentId {
|
||||
// this reader doesn't have the currentId, try to advance
|
||||
s.currs[i], err = termSearcher.Advance(s.currentId)
|
||||
if err != nil {
|
||||
|
@ -123,6 +123,9 @@ OUTER:
|
|||
s.currentId = s.currs[i].ID
|
||||
continue OUTER
|
||||
}
|
||||
} else if s.currs[i] == nil {
|
||||
s.currentId = ""
|
||||
continue OUTER
|
||||
}
|
||||
}
|
||||
// if we get here, a doc matched all readers, sum the score and add it
|
||||
|
@ -145,6 +148,13 @@ OUTER:
|
|||
}
|
||||
|
||||
func (s *TermConjunctionSearcher) Advance(ID string) (*DocumentMatch, error) {
|
||||
var err error
|
||||
for i, searcher := range s.searchers {
|
||||
s.currs[i], err = searcher.Advance(ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.currentId = ID
|
||||
return s.Next()
|
||||
}
|
||||
|
|
|
@ -154,22 +154,11 @@ func TestTermConjunctionSearch(t *testing.T) {
|
|||
index: twoDocIndex,
|
||||
query: &TermConjunctionQuery{
|
||||
Terms: []Query{
|
||||
&TermConjunctionQuery{
|
||||
Terms: []Query{
|
||||
&TermQuery{
|
||||
Term: "beer",
|
||||
Field: "desc",
|
||||
BoostVal: 1.0,
|
||||
Explain: true,
|
||||
},
|
||||
&TermQuery{
|
||||
Term: "mister",
|
||||
Field: "title",
|
||||
BoostVal: 5.0,
|
||||
Explain: true,
|
||||
},
|
||||
},
|
||||
Explain: true,
|
||||
&TermQuery{
|
||||
Term: "beer",
|
||||
Field: "desc",
|
||||
BoostVal: 5.0,
|
||||
Explain: true,
|
||||
},
|
||||
&TermConjunctionQuery{
|
||||
Terms: []Query{
|
||||
|
@ -194,7 +183,7 @@ func TestTermConjunctionSearch(t *testing.T) {
|
|||
results: []*DocumentMatch{
|
||||
&DocumentMatch{
|
||||
ID: "2",
|
||||
Score: 2.7073553504667243,
|
||||
Score: 1.754501824953384,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue