0
0
bleve/search/query/bool_field.go

66 lines
1.6 KiB
Go
Raw Normal View History

2016-01-12 02:18:03 +01: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.
2016-01-12 02:18:03 +01:00
package query
2016-01-12 02:18:03 +01:00
import (
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/mapping"
2016-01-12 02:18:03 +01:00
"github.com/blevesearch/bleve/search"
"github.com/blevesearch/bleve/search/searcher"
2016-01-12 02:18:03 +01:00
)
type BoolFieldQuery struct {
Bool bool `json:"bool"`
Field string `json:"field,omitempty"`
Boost *Boost `json:"boost,omitempty"`
2016-01-12 02:18:03 +01:00
}
// NewBoolFieldQuery creates a new Query for boolean fields
func NewBoolFieldQuery(val bool) *BoolFieldQuery {
return &BoolFieldQuery{
Bool: val,
2016-01-12 02:18:03 +01:00
}
}
func (q *BoolFieldQuery) SetBoost(b float64) {
boost := Boost(b)
q.Boost = &boost
2016-01-12 02:18:03 +01:00
}
func (q *BoolFieldQuery) SetField(f string) {
q.Field = f
2016-01-12 02:18:03 +01:00
}
func (q *BoolFieldQuery) GetField() string{
return q.Field
}
func (q *BoolFieldQuery) GetBoost() float64{
return q.Boost.Value()
}
func (q *BoolFieldQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) {
field := q.Field
if q.Field == "" {
field = m.DefaultSearchField()
2016-01-12 02:18:03 +01:00
}
term := "F"
if q.Bool {
term = "T"
}
return searcher.NewTermSearcher(i, term, field, q.Boost.Value(), explain)
2016-01-12 02:18:03 +01:00
}