2014-07-11 20:49:59 +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-08-29 20:18:36 +02:00
|
|
|
|
2016-09-20 03:12:36 +02:00
|
|
|
package query
|
2014-07-11 20:49:59 +02:00
|
|
|
|
|
|
|
import (
|
2016-04-08 00:20:35 +02:00
|
|
|
"encoding/json"
|
|
|
|
|
2014-09-12 23:21:35 +02:00
|
|
|
"github.com/blevesearch/bleve/index"
|
2016-09-18 15:33:18 +02:00
|
|
|
"github.com/blevesearch/bleve/mapping"
|
2014-08-28 21:38:57 +02:00
|
|
|
"github.com/blevesearch/bleve/search"
|
2016-10-01 23:20:59 +02:00
|
|
|
"github.com/blevesearch/bleve/search/searcher"
|
2014-07-11 20:49:59 +02:00
|
|
|
)
|
|
|
|
|
2016-09-20 03:12:36 +02:00
|
|
|
type MatchAllQuery struct {
|
2016-09-23 01:49:31 +02:00
|
|
|
Boost *Boost `json:"boost,omitempty"`
|
2014-07-30 18:30:38 +02:00
|
|
|
}
|
|
|
|
|
2014-08-31 16:55:22 +02:00
|
|
|
// NewMatchAllQuery creates a Query which will
|
|
|
|
// match all documents in the index.
|
2016-09-20 03:12:36 +02:00
|
|
|
func NewMatchAllQuery() *MatchAllQuery {
|
2016-09-23 01:49:31 +02:00
|
|
|
return &MatchAllQuery{}
|
2014-07-11 20:49:59 +02:00
|
|
|
}
|
|
|
|
|
2016-09-23 01:49:31 +02:00
|
|
|
func (q *MatchAllQuery) SetBoost(b float64) {
|
|
|
|
boost := Boost(b)
|
|
|
|
q.Boost = &boost
|
2014-07-30 18:30:38 +02:00
|
|
|
}
|
|
|
|
|
2016-09-20 03:12:36 +02:00
|
|
|
func (q *MatchAllQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) {
|
2016-10-02 16:29:39 +02:00
|
|
|
return searcher.NewMatchAllSearcher(i, q.Boost.Value(), explain)
|
2014-08-30 00:14:12 +02:00
|
|
|
}
|
2016-04-08 00:20:35 +02:00
|
|
|
|
2016-09-20 03:12:36 +02:00
|
|
|
func (q *MatchAllQuery) MarshalJSON() ([]byte, error) {
|
2016-04-08 00:20:35 +02:00
|
|
|
tmp := map[string]interface{}{
|
2016-09-23 01:49:31 +02:00
|
|
|
"boost": q.Boost,
|
2016-04-08 00:20:35 +02:00
|
|
|
"match_all": map[string]interface{}{},
|
|
|
|
}
|
|
|
|
return json.Marshal(tmp)
|
|
|
|
}
|