2014-07-11 20:49:59 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2014-09-02 16:54:50 +02:00
|
|
|
|
2014-09-01 17:15:38 +02:00
|
|
|
package searchers
|
2014-07-11 20:49:59 +02:00
|
|
|
|
|
|
|
import (
|
2014-08-28 21:38:57 +02:00
|
|
|
"github.com/blevesearch/bleve/index"
|
2014-09-01 17:15:38 +02:00
|
|
|
"github.com/blevesearch/bleve/search"
|
|
|
|
"github.com/blevesearch/bleve/search/scorers"
|
2014-07-11 20:49:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type MatchAllSearcher struct {
|
2014-09-12 23:21:35 +02:00
|
|
|
indexReader index.IndexReader
|
|
|
|
reader index.DocIDReader
|
|
|
|
scorer *scorers.ConstantScorer
|
2014-07-11 20:49:59 +02:00
|
|
|
}
|
|
|
|
|
2014-09-12 23:21:35 +02:00
|
|
|
func NewMatchAllSearcher(indexReader index.IndexReader, boost float64, explain bool) (*MatchAllSearcher, error) {
|
|
|
|
reader, err := indexReader.DocIDReader("", "")
|
2014-07-11 20:49:59 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-09-01 17:15:38 +02:00
|
|
|
scorer := scorers.NewConstantScorer(1.0, boost, explain)
|
2014-07-11 20:49:59 +02:00
|
|
|
return &MatchAllSearcher{
|
2014-09-12 23:21:35 +02:00
|
|
|
indexReader: indexReader,
|
|
|
|
reader: reader,
|
|
|
|
scorer: scorer,
|
2014-07-11 20:49:59 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MatchAllSearcher) Count() uint64 {
|
2014-09-12 23:21:35 +02:00
|
|
|
return s.indexReader.DocCount()
|
2014-07-11 20:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MatchAllSearcher) Weight() float64 {
|
|
|
|
return s.scorer.Weight()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MatchAllSearcher) SetQueryNorm(qnorm float64) {
|
|
|
|
s.scorer.SetQueryNorm(qnorm)
|
|
|
|
}
|
|
|
|
|
2016-07-21 01:29:20 +02:00
|
|
|
func (s *MatchAllSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
|
2014-07-11 20:49:59 +02:00
|
|
|
id, err := s.reader.Next()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// score match
|
|
|
|
docMatch := s.scorer.Score(id)
|
|
|
|
// return doc match
|
|
|
|
return docMatch, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-29 23:14:58 +02:00
|
|
|
func (s *MatchAllSearcher) Advance(ID string, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
|
2014-07-11 20:49:59 +02:00
|
|
|
id, err := s.reader.Advance(ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// score match
|
|
|
|
docMatch := s.scorer.Score(id)
|
|
|
|
|
|
|
|
// return doc match
|
|
|
|
return docMatch, nil
|
|
|
|
}
|
|
|
|
|
2015-03-06 20:46:29 +01:00
|
|
|
func (s *MatchAllSearcher) Close() error {
|
|
|
|
return s.reader.Close()
|
2014-07-11 20:49:59 +02:00
|
|
|
}
|
2014-08-30 00:14:12 +02:00
|
|
|
|
|
|
|
func (s *MatchAllSearcher) Min() int {
|
|
|
|
return 0
|
|
|
|
}
|