1
0
Fork 0
forked from forgejo/forgejo

Upgrade bleve from v2.0.6 to v2.3.0 (#18132)

This commit is contained in:
Lunny Xiao 2022-01-01 16:26:27 +08:00 committed by GitHub
parent 1a4e2bfcd1
commit 25a290e320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 1283 additions and 660 deletions

View file

@ -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 == "" {