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 (
|
||||
maxSearchResult = 101
|
||||
|
||||
docType = "page"
|
||||
titleField = "title"
|
||||
storeTitleField = "store_title"
|
||||
searchField = "search"
|
||||
)
|
||||
|
||||
type indexPage struct {
|
||||
|
|
@ -110,7 +112,7 @@ func (i *Index) Search(search string) (results []core.Result, err error) {
|
|||
continue
|
||||
}
|
||||
for fragField, frags := range hit.Fragments {
|
||||
if fragField == "title" || fragField == "search" {
|
||||
if fragField == titleField || fragField == searchField {
|
||||
for _, f := range frags {
|
||||
r.HTML += template.HTML(f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,14 +42,14 @@ func createMapping() (m *mapping.IndexMappingImpl, err error) {
|
|||
|
||||
doc := bleve.NewDocumentMapping()
|
||||
ti := bleve.NewTextFieldMapping()
|
||||
ti.Analyzer = "fulltext_ngram"
|
||||
doc.AddFieldMappingsAt("title", ti)
|
||||
ti.Analyzer = ngram
|
||||
doc.AddFieldMappingsAt(titleField, ti)
|
||||
st := bleve.NewTextFieldMapping()
|
||||
st.Analyzer = "fulltext_ngram"
|
||||
doc.AddFieldMappingsAt("store_title", st)
|
||||
st.Analyzer = ngram
|
||||
doc.AddFieldMappingsAt(storeTitleField, st)
|
||||
s := bleve.NewTextFieldMapping()
|
||||
s.Analyzer = "fulltext_ngram"
|
||||
doc.AddFieldMappingsAt("search", s)
|
||||
s.Analyzer = ngram
|
||||
doc.AddFieldMappingsAt(searchField, s)
|
||||
|
||||
m.AddDocumentMapping(docType, doc)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue