move index mapping to const variables
This commit is contained in:
parent
1cf4c7cd77
commit
f599483aab
2 changed files with 24 additions and 19 deletions
|
|
@ -11,10 +11,15 @@ import (
|
|||
"github.com/blevesearch/bleve/mapping"
|
||||
)
|
||||
|
||||
const (
|
||||
bigram = "bigram_tokenfilter"
|
||||
ngram = "fulltext_ngram"
|
||||
)
|
||||
|
||||
func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
||||
m = bleve.NewIndexMapping()
|
||||
|
||||
err = m.AddCustomTokenFilter("bigram_tokenfilter", map[string]interface{}{
|
||||
err = m.AddCustomTokenFilter(bigram, map[string]interface{}{
|
||||
"type": edgengram.Name,
|
||||
"side": edgengram.FRONT,
|
||||
"min": 3.0,
|
||||
|
|
@ -23,12 +28,12 @@ func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = m.AddCustomAnalyzer("fulltext_ngram", map[string]interface{}{
|
||||
err = m.AddCustomAnalyzer(ngram, map[string]interface{}{
|
||||
"type": custom.Name,
|
||||
"tokenizer": unicode.Name,
|
||||
"token_filters": []string{
|
||||
lowercase.Name,
|
||||
"bigram_tokenfilter",
|
||||
bigram,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
@ -37,12 +42,12 @@ func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
|||
|
||||
doc := bleve.NewDocumentMapping()
|
||||
tm := bleve.NewTextFieldMapping()
|
||||
tm.Analyzer = "fulltext_ngram"
|
||||
doc.AddFieldMappingsAt("text", tm)
|
||||
km := bleve.NewTextFieldMapping()
|
||||
doc.AddFieldMappingsAt("keyword", km)
|
||||
tm.Analyzer = ngram
|
||||
doc.AddFieldMappingsAt(textField, tm)
|
||||
tagm := bleve.NewTextFieldMapping()
|
||||
doc.AddFieldMappingsAt(tagsField, tagm)
|
||||
cm := bleve.NewDateTimeFieldMapping()
|
||||
doc.AddFieldMappingsAt("created", cm)
|
||||
doc.AddFieldMappingsAt(createdField, cm)
|
||||
|
||||
m.AddDocumentMapping(docType, doc)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue