@@ -42,14 +42,14 @@ public class SuggestBuilder extends ToXContentToBytes {
42
42
public SuggestBuilder () {
43
43
this .name = null ;
44
44
}
45
-
45
+
46
46
public SuggestBuilder (String name ) {
47
47
this .name = name ;
48
48
}
49
-
49
+
50
50
/**
51
51
* Sets the text to provide suggestions for. The suggest text is a required option that needs
52
- * to be set either via this setter or via the {@link org.elasticsearch.search.suggest.SuggestBuilder. SuggestionBuilder#setText (String)} method.
52
+ * to be set either via this setter or via the {@link org.elasticsearch.search.suggest.SuggestionBuilder#text (String)} method.
53
53
* <p>
54
54
* The suggest text gets analyzed by the suggest analyzer or the suggest field search analyzer.
55
55
* For each analyzed token, suggested terms are suggested if possible.
@@ -67,7 +67,7 @@ public SuggestBuilder addSuggestion(SuggestionBuilder<?> suggestion) {
67
67
suggestions .add (suggestion );
68
68
return this ;
69
69
}
70
-
70
+
71
71
/**
72
72
* Returns all suggestions with the defined names.
73
73
*/
@@ -82,7 +82,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
82
82
} else {
83
83
builder .startObject (name );
84
84
}
85
-
85
+
86
86
if (globalText != null ) {
87
87
builder .field ("text" , globalText );
88
88
}
@@ -92,125 +92,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
92
92
builder .endObject ();
93
93
return builder ;
94
94
}
95
-
96
- public static abstract class SuggestionBuilder <T > extends ToXContentToBytes {
97
-
98
- private String name ;
99
- private String suggester ;
100
- private String text ;
101
- private String prefix ;
102
- private String regex ;
103
- private String field ;
104
- private String analyzer ;
105
- private Integer size ;
106
- private Integer shardSize ;
107
-
108
- public SuggestionBuilder (String name , String suggester ) {
109
- this .name = name ;
110
- this .suggester = suggester ;
111
- }
112
-
113
- /**
114
- * Same as in {@link SuggestBuilder#setText(String)}, but in the suggestion scope.
115
- */
116
- @ SuppressWarnings ("unchecked" )
117
- public T text (String text ) {
118
- this .text = text ;
119
- return (T ) this ;
120
- }
121
-
122
- protected void setPrefix (String prefix ) {
123
- this .prefix = prefix ;
124
- }
125
-
126
- protected void setRegex (String regex ) {
127
- this .regex = regex ;
128
- }
129
-
130
- @ Override
131
- public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
132
- builder .startObject (name );
133
- if (text != null ) {
134
- builder .field ("text" , text );
135
- }
136
- if (prefix != null ) {
137
- builder .field ("prefix" , prefix );
138
- }
139
- if (regex != null ) {
140
- builder .field ("regex" , regex );
141
- }
142
- builder .startObject (suggester );
143
- if (analyzer != null ) {
144
- builder .field ("analyzer" , analyzer );
145
- }
146
- if (field != null ) {
147
- builder .field ("field" , field );
148
- }
149
- if (size != null ) {
150
- builder .field ("size" , size );
151
- }
152
- if (shardSize != null ) {
153
- builder .field ("shard_size" , shardSize );
154
- }
155
-
156
- builder = innerToXContent (builder , params );
157
- builder .endObject ();
158
- builder .endObject ();
159
- return builder ;
160
- }
161
-
162
- protected abstract XContentBuilder innerToXContent (XContentBuilder builder , Params params ) throws IOException ;
163
-
164
- /**
165
- * Sets from what field to fetch the candidate suggestions from. This is an
166
- * required option and needs to be set via this setter or
167
- * {@link org.elasticsearch.search.suggest.term.TermSuggestionBuilder#field(String)}
168
- * method
169
- */
170
- @ SuppressWarnings ("unchecked" )
171
- public T field (String field ) {
172
- this .field = field ;
173
- return (T )this ;
174
- }
175
-
176
- /**
177
- * Sets the analyzer to analyse to suggest text with. Defaults to the search
178
- * analyzer of the suggest field.
179
- */
180
- @ SuppressWarnings ("unchecked" )
181
- public T analyzer (String analyzer ) {
182
- this .analyzer = analyzer ;
183
- return (T )this ;
184
- }
185
-
186
- /**
187
- * Sets the maximum suggestions to be returned per suggest text term.
188
- */
189
- @ SuppressWarnings ("unchecked" )
190
- public T size (int size ) {
191
- if (size <= 0 ) {
192
- throw new IllegalArgumentException ("Size must be positive" );
193
- }
194
- this .size = size ;
195
- return (T )this ;
196
- }
197
-
198
- /**
199
- * Sets the maximum number of suggested term to be retrieved from each
200
- * individual shard. During the reduce phase the only the top N suggestions
201
- * are returned based on the <code>size</code> option. Defaults to the
202
- * <code>size</code> option.
203
- * <p>
204
- * Setting this to a value higher than the `size` can be useful in order to
205
- * get a more accurate document frequency for suggested terms. Due to the
206
- * fact that terms are partitioned amongst shards, the shard level document
207
- * frequencies of suggestions may not be precise. Increasing this will make
208
- * these document frequencies more precise.
209
- */
210
- @ SuppressWarnings ("unchecked" )
211
- public T shardSize (Integer shardSize ) {
212
- this .shardSize = shardSize ;
213
- return (T )this ;
214
- }
215
- }
216
95
}
0 commit comments