github.com/m3db/m3@v1.5.0/src/m3ninx/search/types.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package search
    22  
    23  import (
    24  	"fmt"
    25  
    26  	"github.com/m3db/m3/src/m3ninx/doc"
    27  	"github.com/m3db/m3/src/m3ninx/generated/proto/querypb"
    28  	"github.com/m3db/m3/src/m3ninx/index"
    29  	"github.com/m3db/m3/src/m3ninx/postings"
    30  	"github.com/m3db/m3/src/x/context"
    31  )
    32  
    33  // Executor is responsible for executing queries over a snapshot.
    34  type Executor interface {
    35  	// Execute executes a query over the Executor's snapshot.
    36  	Execute(ctx context.Context, q Query) (doc.QueryDocIterator, error)
    37  
    38  	// Close closes the iterator.
    39  	Close() error
    40  }
    41  
    42  // Query is a search query for documents.
    43  type Query interface {
    44  	fmt.Stringer
    45  
    46  	// Searcher returns a Searcher for executing the query.
    47  	Searcher() (Searcher, error)
    48  
    49  	// Equal reports whether two queries are equivalent.
    50  	Equal(q Query) bool
    51  
    52  	// ToProto returns the Protobuf query struct corresponding to this query.
    53  	ToProto() *querypb.Query
    54  }
    55  
    56  // Searcher executes a query against a given Reader. It returns the postings lists
    57  // of the documents it matches for the given segment.
    58  type Searcher interface {
    59  	// Search executes a configured query against the given Reader.
    60  	Search(index.Reader) (postings.List, error)
    61  }
    62  
    63  // Searchers is a slice of Searcher.
    64  type Searchers []Searcher
    65  
    66  // ReadThroughSegmentSearcher searches a read through segment
    67  // and potentially caches the result.
    68  type ReadThroughSegmentSearcher interface {
    69  	Search(query Query, searcher Searcher) (postings.List, error)
    70  }