go mod and vendor/ update
This commit is contained in:
parent
9d332bbda4
commit
14e0611f06
704 changed files with 157354 additions and 39113 deletions
163
vendor/github.com/blevesearch/bleve/search.go
generated
vendored
163
vendor/github.com/blevesearch/bleve/search.go
generated
vendored
|
|
@ -1,11 +1,16 @@
|
|||
// Copyright (c) 2014 Couchbase, Inc.
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
|
||||
package bleve
|
||||
|
||||
|
|
@ -15,9 +20,16 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve/analysis"
|
||||
"github.com/blevesearch/bleve/analysis/datetime/optional"
|
||||
"github.com/blevesearch/bleve/registry"
|
||||
"github.com/blevesearch/bleve/search"
|
||||
"github.com/blevesearch/bleve/search/query"
|
||||
)
|
||||
|
||||
var cache = registry.NewCache()
|
||||
|
||||
const defaultDateTimeParser = optional.Name
|
||||
|
||||
type numericRange struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
|
|
@ -32,19 +44,22 @@ type dateTimeRange struct {
|
|||
endString *string
|
||||
}
|
||||
|
||||
func (dr *dateTimeRange) ParseDates(dateTimeParser analysis.DateTimeParser) {
|
||||
func (dr *dateTimeRange) ParseDates(dateTimeParser analysis.DateTimeParser) (start, end time.Time) {
|
||||
start = dr.Start
|
||||
if dr.Start.IsZero() && dr.startString != nil {
|
||||
start, err := dateTimeParser.ParseDateTime(*dr.startString)
|
||||
s, err := dateTimeParser.ParseDateTime(*dr.startString)
|
||||
if err == nil {
|
||||
dr.Start = start
|
||||
start = s
|
||||
}
|
||||
}
|
||||
end = dr.End
|
||||
if dr.End.IsZero() && dr.endString != nil {
|
||||
end, err := dateTimeParser.ParseDateTime(*dr.endString)
|
||||
e, err := dateTimeParser.ParseDateTime(*dr.endString)
|
||||
if err == nil {
|
||||
dr.End = end
|
||||
end = e
|
||||
}
|
||||
}
|
||||
return start, end
|
||||
}
|
||||
|
||||
func (dr *dateTimeRange) UnmarshalJSON(input []byte) error {
|
||||
|
|
@ -70,6 +85,21 @@ func (dr *dateTimeRange) UnmarshalJSON(input []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (dr *dateTimeRange) MarshalJSON() ([]byte, error) {
|
||||
rv := map[string]interface{}{
|
||||
"name": dr.Name,
|
||||
"start": dr.Start,
|
||||
"end": dr.End,
|
||||
}
|
||||
if dr.Start.IsZero() && dr.startString != nil {
|
||||
rv["start"] = dr.startString
|
||||
}
|
||||
if dr.End.IsZero() && dr.endString != nil {
|
||||
rv["end"] = dr.endString
|
||||
}
|
||||
return json.Marshal(rv)
|
||||
}
|
||||
|
||||
// A FacetRequest describes a facet or aggregation
|
||||
// of the result document set you would like to be
|
||||
// built.
|
||||
|
|
@ -81,26 +111,41 @@ type FacetRequest struct {
|
|||
}
|
||||
|
||||
func (fr *FacetRequest) Validate() error {
|
||||
if len(fr.NumericRanges) > 0 && len(fr.DateTimeRanges) > 0 {
|
||||
nrCount := len(fr.NumericRanges)
|
||||
drCount := len(fr.DateTimeRanges)
|
||||
if nrCount > 0 && drCount > 0 {
|
||||
return fmt.Errorf("facet can only conain numeric ranges or date ranges, not both")
|
||||
}
|
||||
|
||||
nrNames := map[string]interface{}{}
|
||||
for _, nr := range fr.NumericRanges {
|
||||
if _, ok := nrNames[nr.Name]; ok {
|
||||
return fmt.Errorf("numeric ranges contains duplicate name '%s'", nr.Name)
|
||||
if nrCount > 0 {
|
||||
nrNames := map[string]interface{}{}
|
||||
for _, nr := range fr.NumericRanges {
|
||||
if _, ok := nrNames[nr.Name]; ok {
|
||||
return fmt.Errorf("numeric ranges contains duplicate name '%s'", nr.Name)
|
||||
}
|
||||
nrNames[nr.Name] = struct{}{}
|
||||
if nr.Min == nil && nr.Max == nil {
|
||||
return fmt.Errorf("numeric range query must specify either min, max or both for range name '%s'", nr.Name)
|
||||
}
|
||||
}
|
||||
nrNames[nr.Name] = struct{}{}
|
||||
}
|
||||
|
||||
drNames := map[string]interface{}{}
|
||||
for _, dr := range fr.DateTimeRanges {
|
||||
if _, ok := drNames[dr.Name]; ok {
|
||||
return fmt.Errorf("date ranges contains duplicate name '%s'", dr.Name)
|
||||
} else {
|
||||
dateTimeParser, err := cache.DateTimeParserNamed(defaultDateTimeParser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
drNames := map[string]interface{}{}
|
||||
for _, dr := range fr.DateTimeRanges {
|
||||
if _, ok := drNames[dr.Name]; ok {
|
||||
return fmt.Errorf("date ranges contains duplicate name '%s'", dr.Name)
|
||||
}
|
||||
drNames[dr.Name] = struct{}{}
|
||||
start, end := dr.ParseDates(dateTimeParser)
|
||||
if start.IsZero() && end.IsZero() {
|
||||
return fmt.Errorf("date range query must specify either start, end or both for range name '%s'", dr.Name)
|
||||
}
|
||||
}
|
||||
drNames[dr.Name] = struct{}{}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +170,16 @@ func (fr *FacetRequest) AddDateTimeRange(name string, start, end time.Time) {
|
|||
fr.DateTimeRanges = append(fr.DateTimeRanges, &dateTimeRange{Name: name, Start: start, End: end})
|
||||
}
|
||||
|
||||
// AddDateTimeRangeString adds a bucket to a field
|
||||
// containing date values.
|
||||
func (fr *FacetRequest) AddDateTimeRangeString(name string, start, end *string) {
|
||||
if fr.DateTimeRanges == nil {
|
||||
fr.DateTimeRanges = make([]*dateTimeRange, 0, 1)
|
||||
}
|
||||
fr.DateTimeRanges = append(fr.DateTimeRanges,
|
||||
&dateTimeRange{Name: name, startString: start, endString: end})
|
||||
}
|
||||
|
||||
// AddNumericRange adds a bucket to a field
|
||||
// containing numeric values. Documents with a
|
||||
// numeric value falling into this range are
|
||||
|
|
@ -195,23 +250,26 @@ func (h *HighlightRequest) AddField(field string) {
|
|||
//
|
||||
// A special field named "*" can be used to return all fields.
|
||||
type SearchRequest struct {
|
||||
Query Query `json:"query"`
|
||||
Size int `json:"size"`
|
||||
From int `json:"from"`
|
||||
Highlight *HighlightRequest `json:"highlight"`
|
||||
Fields []string `json:"fields"`
|
||||
Facets FacetsRequest `json:"facets"`
|
||||
Explain bool `json:"explain"`
|
||||
Sort search.SortOrder `json:"sort"`
|
||||
Query query.Query `json:"query"`
|
||||
Size int `json:"size"`
|
||||
From int `json:"from"`
|
||||
Highlight *HighlightRequest `json:"highlight"`
|
||||
Fields []string `json:"fields"`
|
||||
Facets FacetsRequest `json:"facets"`
|
||||
Explain bool `json:"explain"`
|
||||
Sort search.SortOrder `json:"sort"`
|
||||
IncludeLocations bool `json:"includeLocations"`
|
||||
}
|
||||
|
||||
func (sr *SearchRequest) Validate() error {
|
||||
err := sr.Query.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
func (r *SearchRequest) Validate() error {
|
||||
if srq, ok := r.Query.(query.ValidatableQuery); ok {
|
||||
err := srq.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return sr.Facets.Validate()
|
||||
return r.Facets.Validate()
|
||||
}
|
||||
|
||||
// AddFacet adds a FacetRequest to this SearchRequest
|
||||
|
|
@ -241,14 +299,15 @@ func (r *SearchRequest) SortByCustom(order search.SortOrder) {
|
|||
// a SearchRequest
|
||||
func (r *SearchRequest) UnmarshalJSON(input []byte) error {
|
||||
var temp struct {
|
||||
Q json.RawMessage `json:"query"`
|
||||
Size *int `json:"size"`
|
||||
From int `json:"from"`
|
||||
Highlight *HighlightRequest `json:"highlight"`
|
||||
Fields []string `json:"fields"`
|
||||
Facets FacetsRequest `json:"facets"`
|
||||
Explain bool `json:"explain"`
|
||||
Sort []json.RawMessage `json:"sort"`
|
||||
Q json.RawMessage `json:"query"`
|
||||
Size *int `json:"size"`
|
||||
From int `json:"from"`
|
||||
Highlight *HighlightRequest `json:"highlight"`
|
||||
Fields []string `json:"fields"`
|
||||
Facets FacetsRequest `json:"facets"`
|
||||
Explain bool `json:"explain"`
|
||||
Sort []json.RawMessage `json:"sort"`
|
||||
IncludeLocations bool `json:"includeLocations"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(input, &temp)
|
||||
|
|
@ -274,7 +333,8 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error {
|
|||
r.Highlight = temp.Highlight
|
||||
r.Fields = temp.Fields
|
||||
r.Facets = temp.Facets
|
||||
r.Query, err = ParseQuery(temp.Q)
|
||||
r.IncludeLocations = temp.IncludeLocations
|
||||
r.Query, err = query.ParseQuery(temp.Q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -293,7 +353,7 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error {
|
|||
// NewSearchRequest creates a new SearchRequest
|
||||
// for the Query, using default values for all
|
||||
// other search parameters.
|
||||
func NewSearchRequest(q Query) *SearchRequest {
|
||||
func NewSearchRequest(q query.Query) *SearchRequest {
|
||||
return NewSearchRequestOptions(q, 10, 0, false)
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +361,7 @@ func NewSearchRequest(q Query) *SearchRequest {
|
|||
// for the Query, with the requested size, from
|
||||
// and explanation search parameters.
|
||||
// By default results are ordered by score, descending.
|
||||
func NewSearchRequestOptions(q Query, size, from int, explain bool) *SearchRequest {
|
||||
func NewSearchRequestOptions(q query.Query, size, from int, explain bool) *SearchRequest {
|
||||
return &SearchRequest{
|
||||
Query: q,
|
||||
Size: size,
|
||||
|
|
@ -421,5 +481,10 @@ func (sr *SearchResult) Merge(other *SearchResult) {
|
|||
if other.MaxScore > sr.MaxScore {
|
||||
sr.MaxScore = other.MaxScore
|
||||
}
|
||||
if sr.Facets == nil && len(other.Facets) != 0 {
|
||||
sr.Facets = other.Facets
|
||||
return
|
||||
}
|
||||
|
||||
sr.Facets.Merge(other.Facets)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue