2014-07-31 17:51:27 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-08-28 21:38:57 +02:00
|
|
|
"github.com/blevesearch/bleve"
|
2014-07-31 17:51:27 +02:00
|
|
|
)
|
|
|
|
|
2014-08-25 21:09:05 +02:00
|
|
|
const textFieldAnalyzer = "en"
|
|
|
|
|
2014-07-31 17:51:27 +02:00
|
|
|
func buildIndexMapping() *bleve.IndexMapping {
|
|
|
|
|
|
|
|
nameMapping := bleve.NewDocumentMapping().
|
|
|
|
AddFieldMapping(
|
|
|
|
bleve.NewFieldMapping(
|
2014-08-25 21:09:05 +02:00
|
|
|
"", "text", textFieldAnalyzer,
|
2014-07-31 17:51:27 +02:00
|
|
|
true, true, true, true))
|
|
|
|
|
|
|
|
descMapping := bleve.NewDocumentMapping().
|
|
|
|
AddFieldMapping(
|
|
|
|
bleve.NewFieldMapping(
|
2014-08-25 21:09:05 +02:00
|
|
|
"", "text", textFieldAnalyzer,
|
2014-07-31 17:51:27 +02:00
|
|
|
true, true, true, true)).
|
|
|
|
AddFieldMapping(
|
|
|
|
bleve.NewFieldMapping("descriptionLang", "text", "detect_lang",
|
|
|
|
false, true, false, false))
|
|
|
|
|
2014-08-06 14:25:10 +02:00
|
|
|
typeMapping := bleve.NewDocumentMapping().
|
|
|
|
AddFieldMapping(
|
|
|
|
bleve.NewFieldMapping(
|
|
|
|
"", "text", "keyword",
|
|
|
|
true, true, true, true))
|
|
|
|
|
|
|
|
styleMapping := bleve.NewDocumentMapping().
|
|
|
|
AddFieldMapping(
|
|
|
|
bleve.NewFieldMapping(
|
|
|
|
"", "text", "keyword",
|
|
|
|
true, true, true, true))
|
|
|
|
|
|
|
|
categoryMapping := bleve.NewDocumentMapping().
|
|
|
|
AddFieldMapping(
|
|
|
|
bleve.NewFieldMapping(
|
|
|
|
"", "text", "keyword",
|
|
|
|
true, true, true, true))
|
|
|
|
|
2014-07-31 17:51:27 +02:00
|
|
|
beerMapping := bleve.NewDocumentMapping().
|
|
|
|
AddSubDocumentMapping("name", nameMapping).
|
2014-08-06 14:25:10 +02:00
|
|
|
AddSubDocumentMapping("description", descMapping).
|
|
|
|
AddSubDocumentMapping("type", typeMapping).
|
|
|
|
AddSubDocumentMapping("style", styleMapping).
|
|
|
|
AddSubDocumentMapping("category", categoryMapping)
|
2014-07-31 17:51:27 +02:00
|
|
|
|
|
|
|
breweryMapping := bleve.NewDocumentMapping().
|
|
|
|
AddSubDocumentMapping("name", nameMapping).
|
|
|
|
AddSubDocumentMapping("description", descMapping)
|
|
|
|
|
|
|
|
indexMapping := bleve.NewIndexMapping().
|
|
|
|
AddDocumentMapping("beer", beerMapping).
|
2014-08-30 06:06:16 +02:00
|
|
|
AddDocumentMapping("brewery", breweryMapping)
|
|
|
|
|
|
|
|
indexMapping.TypeField = "type"
|
|
|
|
indexMapping.DefaultAnalyzer = textFieldAnalyzer
|
2014-07-31 17:51:27 +02:00
|
|
|
|
|
|
|
return indexMapping
|
|
|
|
}
|