MM-40537: Bump bleve dependency to fix Sentry crash (#19194)

* MM-40537: Bump bleve dependency to fix Sentry crash

We observed a sentry crash, which is now fixed upstream.
So we bump the dependency accordingly.

```release-note
NONE
```

* Fix vendor/modules.txt

```release-note
NONE
```

* New fix

```release-note
NONE
```

* Trigger CI
```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2021-12-20 14:48:24 +05:30
коммит произвёл GitHub
родитель 87bf8fb9e9
Коммит b836edba40
54 изменённых файлов: 2544 добавлений и 350 удалений

1
vendor/github.com/blevesearch/bleve/v2/.gitignore сгенерированный поставляемый
Просмотреть файл

@@ -17,3 +17,4 @@ vendor/**
/search/query/y.output
*.test
tags
go.sum

1
vendor/github.com/blevesearch/bleve/v2/analysis/type.go сгенерированный поставляемый
Просмотреть файл

@@ -34,6 +34,7 @@ const (
Single
Double
Boolean
IP
)
// Token represents one occurrence of a term at a particular location in a

1
vendor/github.com/blevesearch/bleve/v2/config_app.go сгенерированный поставляемый
Просмотреть файл

@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build appengine || appenginevm
// +build appengine appenginevm
package bleve

1
vendor/github.com/blevesearch/bleve/v2/config_disk.go сгенерированный поставляемый
Просмотреть файл

@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !appengine && !appenginevm
// +build !appengine,!appenginevm
package bleve

132
vendor/github.com/blevesearch/bleve/v2/document/field_ip.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,132 @@
// Copyright (c) 2021 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.
package document
import (
"fmt"
"net"
"reflect"
"github.com/blevesearch/bleve/v2/analysis"
"github.com/blevesearch/bleve/v2/size"
index "github.com/blevesearch/bleve_index_api"
)
var reflectStaticSizeIPField int
func init() {
var f IPField
reflectStaticSizeIPField = int(reflect.TypeOf(f).Size())
}
const DefaultIPIndexingOptions = index.StoreField | index.IndexField | index.DocValues | index.IncludeTermVectors
type IPField struct {
name string
arrayPositions []uint64
options index.FieldIndexingOptions
value net.IP
numPlainTextBytes uint64
length int
frequencies index.TokenFrequencies
}
func (b *IPField) Size() int {
return reflectStaticSizeIPField + size.SizeOfPtr +
len(b.name) +
len(b.arrayPositions)*size.SizeOfUint64 +
len(b.value)
}
func (b *IPField) Name() string {
return b.name
}
func (b *IPField) ArrayPositions() []uint64 {
return b.arrayPositions
}
func (b *IPField) Options() index.FieldIndexingOptions {
return b.options
}
func (n *IPField) EncodedFieldType() byte {
return 'i'
}
func (n *IPField) AnalyzedLength() int {
return n.length
}
func (n *IPField) AnalyzedTokenFrequencies() index.TokenFrequencies {
return n.frequencies
}
func (b *IPField) Analyze() {
tokens := analysis.TokenStream{
&analysis.Token{
Start: 0,
End: len(b.value),
Term: b.value,
Position: 1,
Type: analysis.IP,
},
}
b.length = 1
b.frequencies = analysis.TokenFrequency(tokens, b.arrayPositions, b.options)
}
func (b *IPField) Value() []byte {
return b.value
}
func (b *IPField) IP() (net.IP, error) {
return net.IP(b.value), nil
}
func (b *IPField) GoString() string {
return fmt.Sprintf("&document.IPField{Name:%s, Options: %s, Value: %s}", b.name, b.options, net.IP(b.value))
}
func (b *IPField) NumPlainTextBytes() uint64 {
return b.numPlainTextBytes
}
func NewIPFieldFromBytes(name string, arrayPositions []uint64, value []byte) *IPField {
return &IPField{
name: name,
arrayPositions: arrayPositions,
value: value,
options: DefaultNumericIndexingOptions,
numPlainTextBytes: uint64(len(value)),
}
}
func NewIPField(name string, arrayPositions []uint64, v net.IP) *IPField {
return NewIPFieldWithIndexingOptions(name, arrayPositions, v, DefaultIPIndexingOptions)
}
func NewIPFieldWithIndexingOptions(name string, arrayPositions []uint64, b net.IP, options index.FieldIndexingOptions) *IPField {
v := b.To16()
return &IPField{
name: name,
arrayPositions: arrayPositions,
value: v,
options: options,
numPlainTextBytes: net.IPv6len,
}
}

14
vendor/github.com/blevesearch/bleve/v2/go.mod сгенерированный поставляемый
Просмотреть файл

@@ -12,12 +12,12 @@ require (
github.com/blevesearch/snowballstem v0.9.0
github.com/blevesearch/upsidedown_store_api v1.0.1
github.com/blevesearch/vellum v1.0.7
github.com/blevesearch/zapx/v11 v11.3.1
github.com/blevesearch/zapx/v12 v12.3.1
github.com/blevesearch/zapx/v13 v13.3.1
github.com/blevesearch/zapx/v14 v14.3.1
github.com/blevesearch/zapx/v15 v15.3.1
github.com/couchbase/moss v0.1.0
github.com/blevesearch/zapx/v11 v11.3.2
github.com/blevesearch/zapx/v12 v12.3.2
github.com/blevesearch/zapx/v13 v13.3.2
github.com/blevesearch/zapx/v14 v14.3.2
github.com/blevesearch/zapx/v15 v15.3.2
github.com/couchbase/moss v0.2.0
github.com/golang/protobuf v1.3.2
github.com/kljensen/snowball v0.6.0
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563
@@ -25,5 +25,5 @@ require (
github.com/steveyen/gtreap v0.1.0
github.com/syndtr/goleveldb v1.0.0
go.etcd.io/bbolt v1.3.5
golang.org/x/text v0.3.0
golang.org/x/text v0.3.7
)

28
vendor/github.com/blevesearch/bleve/v2/go.sum сгенерированный поставляемый
Просмотреть файл

@@ -21,23 +21,23 @@ github.com/blevesearch/upsidedown_store_api v1.0.1 h1:1SYRwyoFLwG3sj0ed89RLtM15a
github.com/blevesearch/upsidedown_store_api v1.0.1/go.mod h1:MQDVGpHZrpe3Uy26zJBf/a8h0FZY6xJbthIMm8myH2Q=
github.com/blevesearch/vellum v1.0.7 h1:+vn8rfyCRHxKVRgDLeR0FAXej2+6mEb5Q15aQE/XESQ=
github.com/blevesearch/vellum v1.0.7/go.mod h1:doBZpmRhwTsASB4QdUZANlJvqVAUdUyX0ZK7QJCTeBE=
github.com/blevesearch/zapx/v11 v11.3.1 h1:X88o7rxOK4bTB2SSwvSWMc6dFhFtQoF3n06q5h/Vhps=
github.com/blevesearch/zapx/v11 v11.3.1/go.mod h1:YzTfUm4kS3e8OmTXDHVV8OzC5MWPO/VPJZQgPNVb4Lc=
github.com/blevesearch/zapx/v12 v12.3.1 h1:SNG60aOBXQ64d3rPiUFuxWsyHTW6h9jKlBKSKMUdxdc=
github.com/blevesearch/zapx/v12 v12.3.1/go.mod h1:RMl6lOZqF+sTxKvhQDJ5yK2LT3Mu7E2p/jGdjAaiRxs=
github.com/blevesearch/zapx/v13 v13.3.1 h1:Aj5iQBXJ7xaGZLxwdueadC/s6vJ5/Jo3klKJfFDjpio=
github.com/blevesearch/zapx/v13 v13.3.1/go.mod h1:eppobNM35U4C22yDvTuxV9xPqo10pwfP/jugL4INWG4=
github.com/blevesearch/zapx/v14 v14.3.1 h1:UyCe63mk9ZcEqgxyMS3Ab3ZC3lhDp1UJktvp31U5KA8=
github.com/blevesearch/zapx/v14 v14.3.1/go.mod h1:zXNcVzukh0AvG57oUtT1T0ndi09H0kELNaNmekEy0jw=
github.com/blevesearch/zapx/v15 v15.3.1 h1:TWm6h55pzmLCbKSFb/dgUVSg98LlYUPqtI/MhTHmZAA=
github.com/blevesearch/zapx/v15 v15.3.1/go.mod h1:C+f/97ZzTzK6vt/7sVlZdzZxKu+5+j4SrGCvr9dJzaY=
github.com/blevesearch/zapx/v11 v11.3.2 h1:TDdcbaA0Yz3Y5zpTrpvyW1AeicqWTJL3g8D5g48RiHM=
github.com/blevesearch/zapx/v11 v11.3.2/go.mod h1:YzTfUm4kS3e8OmTXDHVV8OzC5MWPO/VPJZQgPNVb4Lc=
github.com/blevesearch/zapx/v12 v12.3.2 h1:XB09XMg/3ibeIJRCm2zjkaVwrtAuk6c55YRSmVlwUDk=
github.com/blevesearch/zapx/v12 v12.3.2/go.mod h1:RMl6lOZqF+sTxKvhQDJ5yK2LT3Mu7E2p/jGdjAaiRxs=
github.com/blevesearch/zapx/v13 v13.3.2 h1:mTvALh6oayreac07VRAv94FLvTHeSBM9sZ1gmVt0N2k=
github.com/blevesearch/zapx/v13 v13.3.2/go.mod h1:eppobNM35U4C22yDvTuxV9xPqo10pwfP/jugL4INWG4=
github.com/blevesearch/zapx/v14 v14.3.2 h1:oW36JVaZDzrzmBa1X5jdTIYzdhkOQnr/ie13Cb2X7MQ=
github.com/blevesearch/zapx/v14 v14.3.2/go.mod h1:zXNcVzukh0AvG57oUtT1T0ndi09H0kELNaNmekEy0jw=
github.com/blevesearch/zapx/v15 v15.3.2 h1:OZNE4CQ9hQhnB21ySC7x2/9Q35U3WtRXLAh5L2gdCXc=
github.com/blevesearch/zapx/v15 v15.3.2/go.mod h1:C+f/97ZzTzK6vt/7sVlZdzZxKu+5+j4SrGCvr9dJzaY=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/couchbase/ghistogram v0.1.0 h1:b95QcQTCzjTUocDXp/uMgSNQi8oj1tGwnJ4bODWZnps=
github.com/couchbase/ghistogram v0.1.0/go.mod h1:s1Jhy76zqfEecpNWJfWUiKZookAFaiGOEoyzgHt9i7k=
github.com/couchbase/moss v0.1.0 h1:HCL+xxHUwmOaL44kMM/gU08OW6QGCui1WVFO58bjhNI=
github.com/couchbase/moss v0.1.0/go.mod h1:9MaHIaRuy9pvLPUJxB8sh8OrLfyDczECVL37grCIubs=
github.com/couchbase/moss v0.2.0 h1:VCYrMzFwEryyhRSeI+/b3tRBSeTpi/8gn5Kf6dxqn+o=
github.com/couchbase/moss v0.2.0/go.mod h1:9MaHIaRuy9pvLPUJxB8sh8OrLfyDczECVL37grCIubs=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -104,8 +104,10 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=

2
vendor/github.com/blevesearch/bleve/v2/index/scorch/snapshot_index.go сгенерированный поставляемый
Просмотреть файл

@@ -429,6 +429,8 @@ func (i *IndexSnapshot) Document(id string) (rv index.Document, err error) {
rvd.AddField(document.NewTextField(name, arrayPos, value))
case 'n':
rvd.AddField(document.NewNumericFieldFromBytes(name, arrayPos, value))
case 'i':
rvd.AddField(document.NewIPFieldFromBytes(name, arrayPos, value))
case 'd':
rvd.AddField(document.NewDateTimeFieldFromBytes(name, arrayPos, value))
case 'b':

2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/upsidedown.go сгенерированный поставляемый
Просмотреть файл

@@ -727,6 +727,8 @@ func decodeFieldType(typ byte, name string, pos []uint64, value []byte) document
return document.NewBooleanFieldFromBytes(name, pos, value)
case 'g':
return document.NewGeoPointFieldFromBytes(name, pos, value)
case 'i':
return document.NewIPFieldFromBytes(name, pos, value)
}
return nil
}

10
vendor/github.com/blevesearch/bleve/v2/mapping.go сгенерированный поставляемый
Просмотреть файл

@@ -45,6 +45,12 @@ func NewTextFieldMapping() *mapping.FieldMapping {
return mapping.NewTextFieldMapping()
}
// NewKeywordFieldMapping returns a field mapping for text using the keyword
// analyzer, which essentially doesn't apply any specific text analysis.
func NewKeywordFieldMapping() *mapping.FieldMapping {
return mapping.NewKeywordFieldMapping()
}
// NewNumericFieldMapping returns a default field mapping for numbers
func NewNumericFieldMapping() *mapping.FieldMapping {
return mapping.NewNumericFieldMapping()
@@ -63,3 +69,7 @@ func NewBooleanFieldMapping() *mapping.FieldMapping {
func NewGeoPointFieldMapping() *mapping.FieldMapping {
return mapping.NewGeoPointFieldMapping()
}
func NewIPFieldMapping() *mapping.FieldMapping {
return mapping.NewIPFieldMapping()
}

13
vendor/github.com/blevesearch/bleve/v2/mapping/document.go сгенерированный поставляемый
Просмотреть файл

@@ -18,6 +18,7 @@ import (
"encoding"
"encoding/json"
"fmt"
"net"
"reflect"
"time"
@@ -76,7 +77,7 @@ func (dm *DocumentMapping) Validate(cache *registry.Cache) error {
}
}
switch field.Type {
case "text", "datetime", "number", "boolean", "geopoint":
case "text", "datetime", "number", "boolean", "geopoint", "IP":
default:
return fmt.Errorf("unknown field type: '%s'", field.Type)
}
@@ -517,8 +518,14 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
case reflect.Map, reflect.Slice:
if subDocMapping != nil {
for _, fieldMapping := range subDocMapping.Fields {
if fieldMapping.Type == "geopoint" {
switch fieldMapping.Type {
case "geopoint":
fieldMapping.processGeoPoint(property, pathString, path, indexes, context)
case "IP":
ip, ok := property.(net.IP)
if ok {
fieldMapping.processIP(ip, pathString, path, indexes, context)
}
}
}
}
@@ -528,7 +535,7 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
switch property := property.(type) {
case encoding.TextMarshaler:
// ONLY process TextMarshaler if there is an explicit mapping
// AND all of the fiels are of type text
// AND all of the fields are of type text
// OTHERWISE process field without TextMarshaler
if subDocMapping != nil {
allFieldsText := true

41
vendor/github.com/blevesearch/bleve/v2/mapping/field.go сгенерированный поставляемый
Просмотреть файл

@@ -17,8 +17,10 @@ package mapping
import (
"encoding/json"
"fmt"
"net"
"time"
"github.com/blevesearch/bleve/v2/analysis/analyzer/keyword"
index "github.com/blevesearch/bleve_index_api"
"github.com/blevesearch/bleve/v2/analysis"
@@ -89,6 +91,19 @@ func newTextFieldMappingDynamic(im *IndexMappingImpl) *FieldMapping {
return rv
}
// NewKeyworFieldMapping returns a default field mapping for text with analyzer "keyword".
func NewKeywordFieldMapping() *FieldMapping {
return &FieldMapping{
Type: "text",
Analyzer: keyword.Name,
Store: true,
Index: true,
IncludeTermVectors: true,
IncludeInAll: true,
DocValues: true,
}
}
// NewNumericFieldMapping returns a default field mapping for numbers
func NewNumericFieldMapping() *FieldMapping {
return &FieldMapping{
@@ -157,6 +172,16 @@ func NewGeoPointFieldMapping() *FieldMapping {
}
}
// NewIPFieldMapping returns a default field mapping for IP points
func NewIPFieldMapping() *FieldMapping {
return &FieldMapping{
Type: "IP",
Store: true,
Index: true,
IncludeInAll: true,
}
}
// Options returns the indexing options for this field.
func (fm *FieldMapping) Options() index.FieldIndexingOptions {
var rv index.FieldIndexingOptions
@@ -201,6 +226,11 @@ func (fm *FieldMapping) processString(propertyValueString string, pathString str
fm.processTime(parsedDateTime, pathString, path, indexes, context)
}
}
} else if fm.Type == "IP" {
ip := net.ParseIP(propertyValueString)
if ip != nil {
fm.processIP(ip, pathString, path, indexes, context)
}
}
}
@@ -261,6 +291,17 @@ func (fm *FieldMapping) processGeoPoint(propertyMightBeGeoPoint interface{}, pat
}
}
func (fm *FieldMapping) processIP(ip net.IP, pathString string, path []string, indexes []uint64, context *walkContext) {
fieldName := getFieldName(pathString, path, fm)
options := fm.Options()
field := document.NewIPFieldWithIndexingOptions(fieldName, indexes, ip, options)
context.doc.AddField(field)
if !fm.IncludeInAll {
context.excludedFromAll = append(context.excludedFromAll, fieldName)
}
}
func (fm *FieldMapping) analyzerForField(path []string, context *walkContext) *analysis.Analyzer {
analyzerName := fm.Analyzer
if analyzerName == "" {

9
vendor/github.com/blevesearch/bleve/v2/query.go сгенерированный поставляемый
Просмотреть файл

@@ -216,3 +216,12 @@ func NewGeoBoundingBoxQuery(topLeftLon, topLeftLat, bottomRightLon, bottomRightL
func NewGeoDistanceQuery(lon, lat float64, distance string) *query.GeoDistanceQuery {
return query.NewGeoDistanceQuery(lon, lat, distance)
}
// NewIPRangeQuery creates a new Query for matching IP addresses.
// If the argument is in CIDR format, then the query will match all
// IP addresses in the network specified. If the argument is an IP address,
// then the query will return documents which contain that IP.
// Both ipv4 and ipv6 are supported.
func NewIPRangeQuery(cidr string) *query.IPRangeQuery {
return query.NewIPRangeQuery(cidr)
}

2
vendor/github.com/blevesearch/bleve/v2/search.go сгенерированный поставляемый
Просмотреть файл

@@ -543,7 +543,7 @@ func (sr *SearchResult) String() string {
rv += fmt.Sprintf("Facets:\n")
for fn, f := range sr.Facets {
rv += fmt.Sprintf("%s(%d)\n", fn, f.Total)
for _, t := range f.Terms {
for _, t := range f.Terms.Terms() {
rv += fmt.Sprintf("\t%s(%d)\n", t.Term, t.Count)
}
if f.Other != 0 {

30
vendor/github.com/blevesearch/bleve/v2/search/facet/facet_builder_datetime.go сгенерированный поставляемый
Просмотреть файл

@@ -87,23 +87,21 @@ func (fb *DateTimeFacetBuilder) Field() string {
return fb.field
}
func (fb *DateTimeFacetBuilder) UpdateVisitor(field string, term []byte) {
if field == fb.field {
fb.sawValue = true
// only consider the values which are shifted 0
prefixCoded := numeric.PrefixCoded(term)
shift, err := prefixCoded.Shift()
if err == nil && shift == 0 {
i64, err := prefixCoded.Int64()
if err == nil {
t := time.Unix(0, i64)
func (fb *DateTimeFacetBuilder) UpdateVisitor(term []byte) {
fb.sawValue = true
// only consider the values which are shifted 0
prefixCoded := numeric.PrefixCoded(term)
shift, err := prefixCoded.Shift()
if err == nil && shift == 0 {
i64, err := prefixCoded.Int64()
if err == nil {
t := time.Unix(0, i64)
// look at each of the ranges for a match
for rangeName, r := range fb.ranges {
if (r.start.IsZero() || t.After(r.start) || t.Equal(r.start)) && (r.end.IsZero() || t.Before(r.end)) {
fb.termsCount[rangeName] = fb.termsCount[rangeName] + 1
fb.total++
}
// look at each of the ranges for a match
for rangeName, r := range fb.ranges {
if (r.start.IsZero() || t.After(r.start) || t.Equal(r.start)) && (r.end.IsZero() || t.Before(r.end)) {
fb.termsCount[rangeName] = fb.termsCount[rangeName] + 1
fb.total++
}
}
}

30
vendor/github.com/blevesearch/bleve/v2/search/facet/facet_builder_numeric.go сгенерированный поставляемый
Просмотреть файл

@@ -86,23 +86,21 @@ func (fb *NumericFacetBuilder) Field() string {
return fb.field
}
func (fb *NumericFacetBuilder) UpdateVisitor(field string, term []byte) {
if field == fb.field {
fb.sawValue = true
// only consider the values which are shifted 0
prefixCoded := numeric.PrefixCoded(term)
shift, err := prefixCoded.Shift()
if err == nil && shift == 0 {
i64, err := prefixCoded.Int64()
if err == nil {
f64 := numeric.Int64ToFloat64(i64)
func (fb *NumericFacetBuilder) UpdateVisitor(term []byte) {
fb.sawValue = true
// only consider the values which are shifted 0
prefixCoded := numeric.PrefixCoded(term)
shift, err := prefixCoded.Shift()
if err == nil && shift == 0 {
i64, err := prefixCoded.Int64()
if err == nil {
f64 := numeric.Int64ToFloat64(i64)
// look at each of the ranges for a match
for rangeName, r := range fb.ranges {
if (r.min == nil || f64 >= *r.min) && (r.max == nil || f64 < *r.max) {
fb.termsCount[rangeName] = fb.termsCount[rangeName] + 1
fb.total++
}
// look at each of the ranges for a match
for rangeName, r := range fb.ranges {
if (r.min == nil || f64 >= *r.min) && (r.max == nil || f64 < *r.max) {
fb.termsCount[rangeName] = fb.termsCount[rangeName] + 1
fb.total++
}
}
}

22
vendor/github.com/blevesearch/bleve/v2/search/facet/facet_builder_terms.go сгенерированный поставляемый
Просмотреть файл

@@ -62,12 +62,10 @@ func (fb *TermsFacetBuilder) Field() string {
return fb.field
}
func (fb *TermsFacetBuilder) UpdateVisitor(field string, term []byte) {
if field == fb.field {
fb.sawValue = true
fb.termsCount[string(term)] = fb.termsCount[string(term)] + 1
fb.total++
}
func (fb *TermsFacetBuilder) UpdateVisitor(term []byte) {
fb.sawValue = true
fb.termsCount[string(term)] = fb.termsCount[string(term)] + 1
fb.total++
}
func (fb *TermsFacetBuilder) StartDoc() {
@@ -87,7 +85,7 @@ func (fb *TermsFacetBuilder) Result() *search.FacetResult {
Missing: fb.missing,
}
rv.Terms = make([]*search.TermFacet, 0, len(fb.termsCount))
rv.Terms = &search.TermFacets{}
for term, count := range fb.termsCount {
tf := &search.TermFacet{
@@ -95,20 +93,20 @@ func (fb *TermsFacetBuilder) Result() *search.FacetResult {
Count: count,
}
rv.Terms = append(rv.Terms, tf)
rv.Terms.Add(tf)
}
sort.Sort(rv.Terms)
// we now have the list of the top N facets
trimTopN := fb.size
if trimTopN > len(rv.Terms) {
trimTopN = len(rv.Terms)
if trimTopN > rv.Terms.Len() {
trimTopN = rv.Terms.Len()
}
rv.Terms = rv.Terms[:trimTopN]
rv.Terms.TrimToTopN(trimTopN)
notOther := 0
for _, tf := range rv.Terms {
for _, tf := range rv.Terms.Terms() {
notOther += tf.Count
}
rv.Other = fb.total - notOther

119
vendor/github.com/blevesearch/bleve/v2/search/facets_builder.go сгенерированный поставляемый
Просмотреть файл

@@ -15,6 +15,7 @@
package search
import (
"encoding/json"
"reflect"
"sort"
@@ -43,7 +44,7 @@ func init() {
type FacetBuilder interface {
StartDoc()
UpdateVisitor(field string, term []byte)
UpdateVisitor(term []byte)
EndDoc()
Result() *FacetResult
@@ -53,10 +54,11 @@ type FacetBuilder interface {
}
type FacetsBuilder struct {
indexReader index.IndexReader
facetNames []string
facets []FacetBuilder
fields []string
indexReader index.IndexReader
facetNames []string
facets []FacetBuilder
facetsByField map[string][]FacetBuilder
fields []string
}
func NewFacetsBuilder(indexReader index.IndexReader) *FacetsBuilder {
@@ -80,8 +82,13 @@ func (fb *FacetsBuilder) Size() int {
}
func (fb *FacetsBuilder) Add(name string, facetBuilder FacetBuilder) {
if fb.facetsByField == nil {
fb.facetsByField = map[string][]FacetBuilder{}
}
fb.facetNames = append(fb.facetNames, name)
fb.facets = append(fb.facets, facetBuilder)
fb.facetsByField[facetBuilder.Field()] = append(fb.facetsByField[facetBuilder.Field()], facetBuilder)
fb.fields = append(fb.fields, facetBuilder.Field())
}
@@ -102,8 +109,10 @@ func (fb *FacetsBuilder) EndDoc() {
}
func (fb *FacetsBuilder) UpdateVisitor(field string, term []byte) {
for _, facetBuilder := range fb.facets {
facetBuilder.UpdateVisitor(field, term)
if facetBuilders, ok := fb.facetsByField[field]; ok {
for _, facetBuilder := range facetBuilders {
facetBuilder.UpdateVisitor(term)
}
}
}
@@ -112,27 +121,73 @@ type TermFacet struct {
Count int `json:"count"`
}
type TermFacets []*TermFacet
func (tf TermFacets) Add(termFacet *TermFacet) TermFacets {
for _, existingTerm := range tf {
if termFacet.Term == existingTerm.Term {
existingTerm.Count += termFacet.Count
return tf
}
}
// if we got here it wasn't already in the existing terms
tf = append(tf, termFacet)
return tf
type TermFacets struct {
termFacets []*TermFacet
termLookup map[string]*TermFacet
}
func (tf TermFacets) Len() int { return len(tf) }
func (tf TermFacets) Swap(i, j int) { tf[i], tf[j] = tf[j], tf[i] }
func (tf TermFacets) Less(i, j int) bool {
if tf[i].Count == tf[j].Count {
return tf[i].Term < tf[j].Term
func (tf *TermFacets) Terms() []*TermFacet {
return tf.termFacets
}
func (tf *TermFacets) TrimToTopN(n int) {
tf.termFacets = tf.termFacets[:n]
}
func (tf *TermFacets) Add(termFacets ...*TermFacet) {
for _, termFacet := range termFacets {
if tf.termLookup == nil {
tf.termLookup = map[string]*TermFacet{}
}
if term, ok := tf.termLookup[termFacet.Term]; ok {
term.Count += termFacet.Count
return
}
// if we got here it wasn't already in the existing terms
tf.termFacets = append(tf.termFacets, termFacet)
tf.termLookup[termFacet.Term] = termFacet
}
return tf[i].Count > tf[j].Count
}
func (tf *TermFacets) Len() int {
// Handle case where *TermFacets is not fully initialized in index_impl.go.init()
if tf == nil {
return 0
}
return len(tf.termFacets)
}
func (tf *TermFacets) Swap(i, j int) {
tf.termFacets[i], tf.termFacets[j] = tf.termFacets[j], tf.termFacets[i]
}
func (tf *TermFacets) Less(i, j int) bool {
if tf.termFacets[i].Count == tf.termFacets[j].Count {
return tf.termFacets[i].Term < tf.termFacets[j].Term
}
return tf.termFacets[i].Count > tf.termFacets[j].Count
}
// TermFacets used to be a type alias for []*TermFacet.
// To maintain backwards compatibility, we have to implement custom
// JSON marshalling.
func (tf *TermFacets) MarshalJSON() ([]byte, error) {
return json.Marshal(tf.termFacets)
}
func (tf *TermFacets) UnmarshalJSON(b []byte) error {
termFacets := []*TermFacet{}
err := json.Unmarshal(b, &termFacets)
if err != nil {
return err
}
for _, termFacet := range termFacets {
tf.Add(termFacet)
}
return nil
}
type NumericRangeFacet struct {
@@ -246,7 +301,7 @@ type FacetResult struct {
Total int `json:"total"`
Missing int `json:"missing"`
Other int `json:"other"`
Terms TermFacets `json:"terms,omitempty"`
Terms *TermFacets `json:"terms,omitempty"`
NumericRanges NumericRangeFacets `json:"numeric_ranges,omitempty"`
DateRanges DateRangeFacets `json:"date_ranges,omitempty"`
}
@@ -254,7 +309,7 @@ type FacetResult struct {
func (fr *FacetResult) Size() int {
return reflectStaticSizeFacetResult + size.SizeOfPtr +
len(fr.Field) +
len(fr.Terms)*(reflectStaticSizeTermFacet+size.SizeOfPtr) +
fr.Terms.Len()*(reflectStaticSizeTermFacet+size.SizeOfPtr) +
len(fr.NumericRanges)*(reflectStaticSizeNumericRangeFacet+size.SizeOfPtr) +
len(fr.DateRanges)*(reflectStaticSizeDateRangeFacet+size.SizeOfPtr)
}
@@ -264,8 +319,8 @@ func (fr *FacetResult) Merge(other *FacetResult) {
fr.Missing += other.Missing
fr.Other += other.Other
if fr.Terms != nil && other.Terms != nil {
for _, term := range other.Terms {
fr.Terms = fr.Terms.Add(term)
for _, term := range other.Terms.termFacets {
fr.Terms.Add(term)
}
}
if fr.NumericRanges != nil && other.NumericRanges != nil {
@@ -283,12 +338,12 @@ func (fr *FacetResult) Merge(other *FacetResult) {
func (fr *FacetResult) Fixup(size int) {
if fr.Terms != nil {
sort.Sort(fr.Terms)
if len(fr.Terms) > size {
moveToOther := fr.Terms[size:]
if fr.Terms.Len() > size {
moveToOther := fr.Terms.termFacets[size:]
for _, mto := range moveToOther {
fr.Other += mto.Count
}
fr.Terms = fr.Terms[0:size]
fr.Terms.termFacets = fr.Terms.termFacets[0:size]
}
} else if fr.NumericRanges != nil {
sort.Sort(fr.NumericRanges)

12
vendor/github.com/blevesearch/bleve/v2/search/highlight/fragmenter/simple/simple.go сгенерированный поставляемый
Просмотреть файл

@@ -123,9 +123,15 @@ OUTER:
// if there were no terms to highlight
// produce a single fragment from the beginning
start := 0
end := start + s.fragmentSize
if end > len(orig) {
end = len(orig)
end := start
used := 0
for end < len(orig) && used < s.fragmentSize {
r, size := utf8.DecodeRune(orig[end:])
if r == utf8.RuneError {
break
}
end += size
used++
}
rv = append(rv, &highlight.Fragment{Orig: orig, Start: start, End: end})
}

84
vendor/github.com/blevesearch/bleve/v2/search/query/ip_range.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,84 @@
// Copyright (c) 2021 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.
package query
import (
"fmt"
"net"
"github.com/blevesearch/bleve/v2/mapping"
"github.com/blevesearch/bleve/v2/search"
"github.com/blevesearch/bleve/v2/search/searcher"
index "github.com/blevesearch/bleve_index_api"
)
type IPRangeQuery struct {
CIDR string `json:"cidr, omitempty"`
FieldVal string `json:"field,omitempty"`
BoostVal *Boost `json:"boost,omitempty"`
}
func NewIPRangeQuery(cidr string) *IPRangeQuery {
return &IPRangeQuery{
CIDR: cidr,
}
}
func (q *IPRangeQuery) SetBoost(b float64) {
boost := Boost(b)
q.BoostVal = &boost
}
func (q *IPRangeQuery) Boost() float64 {
return q.BoostVal.Value()
}
func (q *IPRangeQuery) SetField(f string) {
q.FieldVal = f
}
func (q *IPRangeQuery) Field() string {
return q.FieldVal
}
func (q *IPRangeQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error) {
field := q.FieldVal
if q.FieldVal == "" {
field = m.DefaultSearchField()
}
_, ipNet, err := net.ParseCIDR(q.CIDR)
if err != nil {
ip := net.ParseIP(q.CIDR)
if ip == nil {
return nil, err
}
// If we are searching for a specific ip rather than members of a network, just use a term search.
return searcher.NewTermSearcherBytes(i, ip.To16(), field, q.BoostVal.Value(), options)
}
return searcher.NewIPRangeSearcher(i, ipNet, field, q.BoostVal.Value(), options)
}
func (q *IPRangeQuery) Validate() error {
_, _, err := net.ParseCIDR(q.CIDR)
if err == nil {
return nil
}
// We also allow search for a specific IP.
ip := net.ParseIP(q.CIDR)
if ip != nil {
return nil // we have a valid ip
}
return fmt.Errorf("IPRangeQuery must be for an network or ip address, %q", q.CIDR)
}

14
vendor/github.com/blevesearch/bleve/v2/search/query/query_string_lex.go сгенерированный поставляемый
Просмотреть файл

@@ -248,8 +248,8 @@ func inTildeState(l *queryStringLex, next rune, eof bool) (lexState, bool) {
}
func inNumOrStrState(l *queryStringLex, next rune, eof bool) (lexState, bool) {
// only a non-escaped space ends the tilde (or eof)
if eof || (!l.inEscape && next == ' ') {
// end on non-escaped space, colon, tilde, boost (or eof)
if eof || (!l.inEscape && (next == ' ' || next == ':' || next == '^' || next == '~')) {
// end number
l.nextTokenType = tNUMBER
l.nextToken = &yySymType{
@@ -257,7 +257,13 @@ func inNumOrStrState(l *queryStringLex, next rune, eof bool) (lexState, bool) {
}
logDebugTokens("NUMBER - '%s'", l.nextToken.s)
l.reset()
return startState, true
consumed := true
if !eof && (next == ':' || next == '^' || next == '~') {
consumed = false
}
return startState, consumed
} else if !l.inEscape && next == '\\' {
l.inEscape = true
return inNumOrStrState, true
@@ -287,7 +293,7 @@ func inNumOrStrState(l *queryStringLex, next rune, eof bool) (lexState, bool) {
}
func inStrState(l *queryStringLex, next rune, eof bool) (lexState, bool) {
// end on non-escped space, colon, tilde, boost (or eof)
// end on non-escaped space, colon, tilde, boost (or eof)
if eof || (!l.inEscape && (next == ' ' || next == ':' || next == '^' || next == '~')) {
// end string
l.nextTokenType = tSTRING

67
vendor/github.com/blevesearch/bleve/v2/search/searcher/search_ip_range.go сгенерированный поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,67 @@
// 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.
package searcher
import (
"net"
"github.com/blevesearch/bleve/v2/search"
index "github.com/blevesearch/bleve_index_api"
)
// netLimits returns the lo and hi bounds inside the network.
func netLimits(n *net.IPNet) (lo net.IP, hi net.IP) {
ones, bits := n.Mask.Size()
netNum := n.IP
if bits == net.IPv4len*8 {
netNum = netNum.To16()
ones += 8 * (net.IPv6len - net.IPv4len)
}
mask := net.CIDRMask(ones, 8*net.IPv6len)
lo = make(net.IP, net.IPv6len)
hi = make(net.IP, net.IPv6len)
for i := 0; i < net.IPv6len; i++ {
lo[i] = netNum[i] & mask[i]
hi[i] = lo[i] | ^mask[i]
}
return lo, hi
}
func NewIPRangeSearcher(indexReader index.IndexReader, ipNet *net.IPNet,
field string, boost float64, options search.SearcherOptions) (
search.Searcher, error) {
lo, hi := netLimits(ipNet)
fieldDict, err := indexReader.FieldDictRange(field, lo, hi)
if err != nil {
return nil, err
}
defer fieldDict.Close()
var terms []string
tfd, err := fieldDict.Next()
for err == nil && tfd != nil {
terms = append(terms, tfd.Term)
if tooManyClauses(len(terms)) {
return nil, tooManyClausesErr(field, len(terms))
}
tfd, err = fieldDict.Next()
}
if err != nil {
return nil, err
}
return NewMultiTermSearcher(indexReader, terms, field, boost, options, true)
}

13
vendor/github.com/blevesearch/zapx/v11/posting.go сгенерированный поставляемый
Просмотреть файл

@@ -657,13 +657,18 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
return 0, false, nil
}
if i.postings == nil || i.postings.postings == i.ActualBM {
if i.postings == nil || i.postings == emptyPostingsList {
// couldn't find anything
return 0, false, nil
}
if i.postings.postings == i.ActualBM {
return i.nextDocNumAtOrAfterClean(atOrAfter)
}
i.Actual.AdvanceIfNeeded(uint32(atOrAfter))
if !i.Actual.HasNext() {
if !i.Actual.HasNext() || !i.all.HasNext() {
// couldn't find anything
return 0, false, nil
}
@@ -688,6 +693,10 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
}
}
if !i.all.HasNext() {
return 0, false, nil
}
allN = i.all.Next()
}

13
vendor/github.com/blevesearch/zapx/v12/posting.go сгенерированный поставляемый
Просмотреть файл

@@ -536,13 +536,18 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
return 0, false, nil
}
if i.postings == nil || i.postings.postings == i.ActualBM {
if i.postings == nil || i.postings == emptyPostingsList {
// couldn't find anything
return 0, false, nil
}
if i.postings.postings == i.ActualBM {
return i.nextDocNumAtOrAfterClean(atOrAfter)
}
i.Actual.AdvanceIfNeeded(uint32(atOrAfter))
if !i.Actual.HasNext() {
if !i.Actual.HasNext() || !i.all.HasNext() {
// couldn't find anything
return 0, false, nil
}
@@ -571,6 +576,10 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
}
}
if !i.all.HasNext() {
return 0, false, nil
}
allN = i.all.Next()
}

13
vendor/github.com/blevesearch/zapx/v13/posting.go сгенерированный поставляемый
Просмотреть файл

@@ -536,13 +536,18 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
return 0, false, nil
}
if i.postings == nil || i.postings.postings == i.ActualBM {
if i.postings == nil || i.postings == emptyPostingsList {
// couldn't find anything
return 0, false, nil
}
if i.postings.postings == i.ActualBM {
return i.nextDocNumAtOrAfterClean(atOrAfter)
}
i.Actual.AdvanceIfNeeded(uint32(atOrAfter))
if !i.Actual.HasNext() {
if !i.Actual.HasNext() || !i.all.HasNext() {
// couldn't find anything
return 0, false, nil
}
@@ -571,6 +576,10 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
}
}
if !i.all.HasNext() {
return 0, false, nil
}
allN = i.all.Next()
}

13
vendor/github.com/blevesearch/zapx/v14/posting.go сгенерированный поставляемый
Просмотреть файл

@@ -544,13 +544,18 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
return 0, false, nil
}
if i.postings == nil || i.postings.postings == i.ActualBM {
if i.postings == nil || i.postings == emptyPostingsList {
// couldn't find anything
return 0, false, nil
}
if i.postings.postings == i.ActualBM {
return i.nextDocNumAtOrAfterClean(atOrAfter)
}
i.Actual.AdvanceIfNeeded(uint32(atOrAfter))
if !i.Actual.HasNext() {
if !i.Actual.HasNext() || !i.all.HasNext() {
// couldn't find anything
return 0, false, nil
}
@@ -574,6 +579,10 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
}
}
if !i.all.HasNext() {
return 0, false, nil
}
allN = i.all.Next()
}

13
vendor/github.com/blevesearch/zapx/v15/posting.go сгенерированный поставляемый
Просмотреть файл

@@ -562,13 +562,18 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
return 0, false, nil
}
if i.postings == nil || i.postings.postings == i.ActualBM {
if i.postings == nil || i.postings == emptyPostingsList {
// couldn't find anything
return 0, false, nil
}
if i.postings.postings == i.ActualBM {
return i.nextDocNumAtOrAfterClean(atOrAfter)
}
i.Actual.AdvanceIfNeeded(uint32(atOrAfter))
if !i.Actual.HasNext() {
if !i.Actual.HasNext() || !i.all.HasNext() {
// couldn't find anything
return 0, false, nil
}
@@ -592,6 +597,10 @@ func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool,
}
}
if !i.all.HasNext() {
return 0, false, nil
}
allN = i.all.Next()
}