2014-08-07 19:45:39 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
2016-10-02 16:13:14 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2016-10-02 16:29:39 +02:00
|
|
|
package searcher
|
2014-08-07 19:45:39 +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"
|
2014-08-07 19:45:39 +02:00
|
|
|
)
|
|
|
|
|
2017-03-31 22:58:06 +02:00
|
|
|
func NewTermPrefixSearcher(indexReader index.IndexReader, prefix string,
|
|
|
|
field string, boost float64, options search.SearcherOptions) (
|
|
|
|
search.Searcher, error) {
|
2014-08-07 19:45:39 +02:00
|
|
|
// find the terms with this prefix
|
2015-03-10 21:22:19 +01:00
|
|
|
fieldDict, err := indexReader.FieldDictPrefix(field, []byte(prefix))
|
2016-10-11 00:35:54 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-08-07 19:45:39 +02:00
|
|
|
|
2017-03-31 22:58:06 +02:00
|
|
|
var terms []string
|
2015-03-10 21:22:19 +01:00
|
|
|
tfd, err := fieldDict.Next()
|
2014-08-07 19:45:39 +02:00
|
|
|
for err == nil && tfd != nil {
|
2017-03-31 22:58:06 +02:00
|
|
|
terms = append(terms, tfd.Term)
|
2015-03-10 21:22:19 +01:00
|
|
|
tfd, err = fieldDict.Next()
|
2014-08-07 19:45:39 +02:00
|
|
|
}
|
2016-02-20 21:41:12 +01:00
|
|
|
|
2017-04-04 16:46:57 +02:00
|
|
|
return NewMultiTermSearcher(indexReader, terms, field, boost, options, true)
|
2016-08-09 04:21:47 +02:00
|
|
|
}
|