-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocument.go
116 lines (89 loc) · 3.19 KB
/
document.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2015 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 index
import "time"
type Document interface {
ID() string
Size() int
VisitFields(visitor FieldVisitor)
VisitComposite(visitor CompositeFieldVisitor)
HasComposite() bool
NumPlainTextBytes() uint64
AddIDField()
StoredFieldsBytes() uint64
}
type FieldVisitor func(Field)
type Field interface {
Name() string
Value() []byte
ArrayPositions() []uint64
EncodedFieldType() byte
Analyze()
Options() FieldIndexingOptions
AnalyzedLength() int
AnalyzedTokenFrequencies() TokenFrequencies
NumPlainTextBytes() uint64
}
type CompositeFieldVisitor func(field CompositeField)
type CompositeField interface {
Field
Compose(field string, length int, freq TokenFrequencies)
}
type TextField interface {
Text() string
}
type NumericField interface {
Number() (float64, error)
}
type DateTimeField interface {
DateTime() (time.Time, string, error)
}
type BooleanField interface {
Boolean() (bool, error)
}
type GeoPointField interface {
Lon() (float64, error)
Lat() (float64, error)
}
type GeoShapeField interface {
GeoShape() (GeoJSON, error)
}
// TokenizableSpatialField is an optional interface for fields that
// supports pluggable custom hierarchial spatial token generation.
type TokenizableSpatialField interface {
// SetSpatialAnalyzerPlugin lets the index implementations to
// initialise relevant spatial analyzer plugins for the field
// to override the spatial token generations during the analysis phase.
SetSpatialAnalyzerPlugin(SpatialAnalyzerPlugin)
}
// SynonymField represents a field that contains a list of synonyms for a set of terms.
// Each SynonymField is generated from a single synonym definition, and its name corresponds
// to the synonym source to which the synonym definition belongs.
type SynonymField interface {
Field
// IterateSynonyms iterates over the synonyms for the term in the field.
// The provided visitor function is called with each term and its corresponding synonyms.
IterateSynonyms(visitor func(term string, synonyms []string))
}
// SynonymFieldVisitor is a function type used to visit a SynonymField within a document.
type SynonymFieldVisitor func(SynonymField)
// SynonymDocument represents a special type of document that contains synonym fields.
// Each SynonymField is a field with a list of synonyms for a set of terms.
// These fields are derived from synonym definitions, and their names correspond to the synonym sources.
type SynonymDocument interface {
Document
// VisitSynonymFields allows iteration over all synonym fields in the document.
// The provided visitor function is called for each synonym field.
VisitSynonymFields(visitor SynonymFieldVisitor)
}