github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/google.golang.org/appengine/search/field.go (about) 1 // Copyright 2014 Google Inc. All rights reserved. 2 // Use of this source code is governed by the Apache 2.0 3 // license that can be found in the LICENSE file. 4 5 package search 6 7 // Field is a name/value pair. A search index's document can be loaded and 8 // saved as a sequence of Fields. 9 type Field struct { 10 // Name is the field name. A valid field name matches /[A-Za-z][A-Za-z0-9_]*/. 11 Name string 12 // Value is the field value. The valid types are: 13 // - string, 14 // - search.Atom, 15 // - search.HTML, 16 // - time.Time (stored with millisecond precision), 17 // - float64, 18 // - GeoPoint. 19 Value interface{} 20 // Language is a two-letter ISO 639-1 code for the field's language, 21 // defaulting to "en" if nothing is specified. It may only be specified for 22 // fields of type string and search.HTML. 23 Language string 24 // Derived marks fields that were calculated as a result of a 25 // FieldExpression provided to Search. This field is ignored when saving a 26 // document. 27 Derived bool 28 } 29 30 // Facet is a name/value pair which is used to add categorical information to a 31 // document. 32 type Facet struct { 33 // Name is the facet name. A valid facet name matches /[A-Za-z][A-Za-z0-9_]*/. 34 // A facet name cannot be longer than 500 characters. 35 Name string 36 // Value is the facet value. 37 // 38 // When being used in documents (for example, in 39 // DocumentMetadata.Facets), the valid types are: 40 // - search.Atom, 41 // - float64. 42 // 43 // When being used in SearchOptions.Refinements or being returned 44 // in FacetResult, the valid types are: 45 // - search.Atom, 46 // - search.Range. 47 Value interface{} 48 } 49 50 // DocumentMetadata is a struct containing information describing a given document. 51 type DocumentMetadata struct { 52 // Rank is an integer specifying the order the document will be returned in 53 // search results. If zero, the rank will be set to the number of seconds since 54 // 2011-01-01 00:00:00 UTC when being Put into an index. 55 Rank int 56 // Facets is the set of facets for this document. 57 Facets []Facet 58 } 59 60 // FieldLoadSaver can be converted from and to a slice of Fields 61 // with additional document metadata. 62 type FieldLoadSaver interface { 63 Load([]Field, *DocumentMetadata) error 64 Save() ([]Field, *DocumentMetadata, error) 65 } 66 67 // FieldList converts a []Field to implement FieldLoadSaver. 68 type FieldList []Field 69 70 // Load loads all of the provided fields into l. 71 // It does not first reset *l to an empty slice. 72 func (l *FieldList) Load(f []Field, _ *DocumentMetadata) error { 73 *l = append(*l, f...) 74 return nil 75 } 76 77 // Save returns all of l's fields as a slice of Fields. 78 func (l *FieldList) Save() ([]Field, *DocumentMetadata, error) { 79 return *l, nil, nil 80 } 81 82 var _ FieldLoadSaver = (*FieldList)(nil)