1//  Copyright (c) 2015 Couchbase, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// 		http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package query
16
17import (
18	"github.com/blevesearch/bleve/index"
19	"github.com/blevesearch/bleve/mapping"
20	"github.com/blevesearch/bleve/search"
21	"github.com/blevesearch/bleve/search/searcher"
22)
23
24type DocIDQuery struct {
25	IDs      []string `json:"ids"`
26	BoostVal *Boost   `json:"boost,omitempty"`
27}
28
29// NewDocIDQuery creates a new Query object returning indexed documents among
30// the specified set. Combine it with ConjunctionQuery to restrict the scope of
31// other queries output.
32func NewDocIDQuery(ids []string) *DocIDQuery {
33	return &DocIDQuery{
34		IDs: ids,
35	}
36}
37
38func (q *DocIDQuery) SetBoost(b float64) {
39	boost := Boost(b)
40	q.BoostVal = &boost
41}
42
43func (q *DocIDQuery) Boost() float64 {
44	return q.BoostVal.Value()
45}
46
47func (q *DocIDQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error) {
48	return searcher.NewDocIDSearcher(i, q.IDs, q.BoostVal.Value(), options)
49}
50