move index mapping to const variables
This commit is contained in:
parent
9ecaf33d86
commit
d29ec19abc
2 changed files with 19 additions and 12 deletions
|
|
@ -15,8 +15,10 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxSearchResult = 101
|
maxSearchResult = 101
|
||||||
|
docType = "page"
|
||||||
docType = "page"
|
titleField = "title"
|
||||||
|
storeTitleField = "store_title"
|
||||||
|
searchField = "search"
|
||||||
)
|
)
|
||||||
|
|
||||||
type indexPage struct {
|
type indexPage struct {
|
||||||
|
|
@ -110,7 +112,7 @@ func (i *Index) Search(search string) (results []core.Result, err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for fragField, frags := range hit.Fragments {
|
for fragField, frags := range hit.Fragments {
|
||||||
if fragField == "title" || fragField == "search" {
|
if fragField == titleField || fragField == searchField {
|
||||||
for _, f := range frags {
|
for _, f := range frags {
|
||||||
r.HTML += template.HTML(f)
|
r.HTML += template.HTML(f)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,15 @@ import (
|
||||||
"github.com/blevesearch/bleve/mapping"
|
"github.com/blevesearch/bleve/mapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
bigram = "bigram_tokenfilter"
|
||||||
|
ngram = "fulltext_ngram"
|
||||||
|
)
|
||||||
|
|
||||||
func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
||||||
m = bleve.NewIndexMapping()
|
m = bleve.NewIndexMapping()
|
||||||
|
|
||||||
err = m.AddCustomTokenFilter("bigram_tokenfilter", map[string]interface{}{
|
err = m.AddCustomTokenFilter(bigram, map[string]interface{}{
|
||||||
"type": edgengram.Name,
|
"type": edgengram.Name,
|
||||||
"side": edgengram.FRONT,
|
"side": edgengram.FRONT,
|
||||||
"min": 3.0,
|
"min": 3.0,
|
||||||
|
|
@ -23,12 +28,12 @@ func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = m.AddCustomAnalyzer("fulltext_ngram", map[string]interface{}{
|
err = m.AddCustomAnalyzer(ngram, map[string]interface{}{
|
||||||
"type": custom.Name,
|
"type": custom.Name,
|
||||||
"tokenizer": unicode.Name,
|
"tokenizer": unicode.Name,
|
||||||
"token_filters": []string{
|
"token_filters": []string{
|
||||||
lowercase.Name,
|
lowercase.Name,
|
||||||
"bigram_tokenfilter",
|
bigram,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -37,14 +42,14 @@ func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
||||||
|
|
||||||
doc := bleve.NewDocumentMapping()
|
doc := bleve.NewDocumentMapping()
|
||||||
ti := bleve.NewTextFieldMapping()
|
ti := bleve.NewTextFieldMapping()
|
||||||
ti.Analyzer = "fulltext_ngram"
|
ti.Analyzer = ngram
|
||||||
doc.AddFieldMappingsAt("title", ti)
|
doc.AddFieldMappingsAt(titleField, ti)
|
||||||
st := bleve.NewTextFieldMapping()
|
st := bleve.NewTextFieldMapping()
|
||||||
st.Analyzer = "fulltext_ngram"
|
st.Analyzer = ngram
|
||||||
doc.AddFieldMappingsAt("store_title", st)
|
doc.AddFieldMappingsAt(storeTitleField, st)
|
||||||
s := bleve.NewTextFieldMapping()
|
s := bleve.NewTextFieldMapping()
|
||||||
s.Analyzer = "fulltext_ngram"
|
s.Analyzer = ngram
|
||||||
doc.AddFieldMappingsAt("search", s)
|
doc.AddFieldMappingsAt(searchField, s)
|
||||||
|
|
||||||
m.AddDocumentMapping(docType, doc)
|
m.AddDocumentMapping(docType, doc)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue