-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping.go
96 lines (82 loc) · 3.3 KB
/
mapping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"github.com/blevesearch/bleve/v2"
"github.com/blevesearch/bleve/v2/analysis/analyzer/keyword"
"github.com/blevesearch/bleve/v2/analysis/analyzer/simple"
"github.com/blevesearch/bleve/v2/analysis/lang/en"
"github.com/blevesearch/bleve/v2/mapping"
)
func buildIndexMapping() (mapping.IndexMapping, error) {
// a generic reusable mapping for english text
englishTextFieldMapping := bleve.NewTextFieldMapping()
englishTextFieldMapping.Analyzer = en.AnalyzerName
// a generic reusable mapping for keyword text
keywordFieldMapping := bleve.NewTextFieldMapping()
keywordFieldMapping.Analyzer = keyword.Name
// a generic reusable mapping for simple text
simpleFieldMapping := bleve.NewTextFieldMapping()
simpleFieldMapping.Analyzer = simple.Name
// a generic reusable mapping for booleans
booleanFieldMapping := bleve.NewBooleanFieldMapping()
// a generic reusable mapping for numbers
numericFieldMapping := bleve.NewNumericFieldMapping()
//SearchableGroup
sGroupMapping := bleve.NewDocumentMapping()
// Server
sGroupMapping.AddFieldMappingsAt("Server", keywordFieldMapping)
// Members
sGroupMapping.AddFieldMappingsAt("Members", numericFieldMapping)
// Fresh
sGroupMapping.AddFieldMappingsAt("Fresh", booleanFieldMapping)
// Group
groupMapping := bleve.NewDocumentMapping()
// Id
groupMapping.AddFieldMappingsAt("Id", keywordFieldMapping)
// Comment
groupMapping.AddFieldMappingsAt("Comment", englishTextFieldMapping)
// Difficulty
groupMapping.AddFieldMappingsAt("Difficulty", simpleFieldMapping)
// MinLevel
groupMapping.AddFieldMappingsAt("MinimumLevel", numericFieldMapping)
// MaxLevel
groupMapping.AddFieldMappingsAt("MaximumLevel", numericFieldMapping)
// AdventureActive
groupMapping.AddFieldMappingsAt("AdventureActive", numericFieldMapping)
// Leader
// Location
// Name
// Region
// Members
// Location
// Name
// Region
memberMapping := bleve.NewDocumentMapping()
locationMapping := bleve.NewDocumentMapping()
locationMapping.AddFieldMappingsAt("Name", englishTextFieldMapping)
locationMapping.AddFieldMappingsAt("Region", englishTextFieldMapping)
memberMapping.AddSubDocumentMapping("Location", locationMapping)
groupMapping.AddSubDocumentMapping("Leader", memberMapping)
groupMapping.AddSubDocumentMapping("Members", memberMapping)
// Quest
questMapping := bleve.NewDocumentMapping()
// Name
questMapping.AddFieldMappingsAt("Name", englishTextFieldMapping)
// AdventurePack
questMapping.AddFieldMappingsAt("RequiredAdventurePack", englishTextFieldMapping)
// AdventureArea
questMapping.AddFieldMappingsAt("AdventureArea", englishTextFieldMapping)
// QuestJournalGroup
questMapping.AddFieldMappingsAt("QuestJournalGroup", englishTextFieldMapping)
// GroupSize
questMapping.AddFieldMappingsAt("GroupSize", simpleFieldMapping)
// Patron
questMapping.AddFieldMappingsAt("Patron", englishTextFieldMapping)
groupMapping.AddSubDocumentMapping("Quest", questMapping)
sGroupMapping.AddSubDocumentMapping("Group", groupMapping)
indexMapping := bleve.NewIndexMapping()
indexMapping.AddDocumentMapping("SearchableGroup", sGroupMapping)
indexMapping.TypeField = "type"
indexMapping.DefaultAnalyzer = "en"
indexMapping.DefaultMapping = sGroupMapping
return indexMapping, nil
}