1//  Copyright (c) 2016 Couchbase, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// 		http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package mapping
16
17import "fmt"
18
19// Examples for Mapping related functions
20
21func ExampleDocumentMapping_AddSubDocumentMapping() {
22	// adds a document mapping for a property in a document
23	// useful for mapping nested documents
24	documentMapping := NewDocumentMapping()
25	subDocumentMapping := NewDocumentMapping()
26	documentMapping.AddSubDocumentMapping("Property", subDocumentMapping)
27
28	fmt.Println(len(documentMapping.Properties))
29	// Output:
30	// 1
31}
32
33func ExampleDocumentMapping_AddFieldMapping() {
34	// you can only add field mapping to those properties which already have a document mapping
35	documentMapping := NewDocumentMapping()
36	subDocumentMapping := NewDocumentMapping()
37	documentMapping.AddSubDocumentMapping("Property", subDocumentMapping)
38
39	fieldMapping := NewTextFieldMapping()
40	fieldMapping.Analyzer = "en"
41	subDocumentMapping.AddFieldMapping(fieldMapping)
42
43	fmt.Println(len(documentMapping.Properties["Property"].Fields))
44	// Output:
45	// 1
46}
47
48func ExampleDocumentMapping_AddFieldMappingsAt() {
49	// you can only add field mapping to those properties which already have a document mapping
50	documentMapping := NewDocumentMapping()
51	subDocumentMapping := NewDocumentMapping()
52	documentMapping.AddSubDocumentMapping("NestedProperty", subDocumentMapping)
53
54	fieldMapping := NewTextFieldMapping()
55	fieldMapping.Analyzer = "en"
56	documentMapping.AddFieldMappingsAt("NestedProperty", fieldMapping)
57
58	fmt.Println(len(documentMapping.Properties["NestedProperty"].Fields))
59	// Output:
60	// 1
61}
62