@@ -86,98 +86,136 @@ public MultiValueGeoPointFieldData(String fieldName, int[][] ordinals, double[]
86
86
}
87
87
88
88
@ Override public boolean hasValue (int docId ) {
89
- return ordinals [docId ] != null ;
89
+ for (int [] ordinal : ordinals ) {
90
+ if (ordinal [docId ] != 0 ) {
91
+ return true ;
92
+ }
93
+ }
94
+ return false ;
90
95
}
91
96
92
97
@ Override public void forEachValueInDoc (int docId , StringValueInDocProc proc ) {
93
- int [] docOrders = ordinals [docId ];
94
- if (docOrders == null ) {
95
- return ;
96
- }
97
- for (int docOrder : docOrders ) {
98
- proc .onValue (docId , GeoHashUtils .encode (lat [docOrder ], lon [docOrder ]));
98
+ for (int [] ordinal : ordinals ) {
99
+ int loc = ordinal [docId ];
100
+ if (loc != 0 ) {
101
+ proc .onValue (docId , GeoHashUtils .encode (lat [loc ], lon [loc ]));
102
+ }
99
103
}
100
104
}
101
105
102
106
@ Override public GeoPoint value (int docId ) {
103
- int [] docOrders = ordinals [docId ];
104
- if (docOrders == null ) {
105
- return null ;
106
- }
107
- GeoPoint point = valuesCache .get ().get ();
108
- int loc = docOrders [0 ];
109
- point .latlon (lat [loc ], lon [loc ]);
110
- return point ;
107
+ for (int [] ordinal : ordinals ) {
108
+ int loc = ordinal [docId ];
109
+ if (loc != 0 ) {
110
+ GeoPoint point = valuesCache .get ().get ();
111
+ point .latlon (lat [loc ], lon [loc ]);
112
+ return point ;
113
+ }
114
+ }
115
+ return null ;
111
116
}
112
117
113
118
@ Override public GeoPoint [] values (int docId ) {
114
- int [] docOrders = ordinals [docId ];
115
- if (docOrders == null ) {
119
+ int length = 0 ;
120
+ for (int [] ordinal : ordinals ) {
121
+ if (ordinal [docId ] != 0 ) {
122
+ length ++;
123
+ }
124
+ }
125
+ if (length == 0 ) {
116
126
return EMPTY_ARRAY ;
117
127
}
118
128
GeoPoint [] points ;
119
- if (docOrders .length < VALUE_CACHE_SIZE ) {
120
- points = valuesArrayCache .get ().get ()[docOrders .length ];
121
- for (int i = 0 ; i < docOrders .length ; i ++) {
122
- int loc = docOrders [i ];
123
- points [i ].latlon (lat [loc ], lon [loc ]);
129
+ if (length < VALUE_CACHE_SIZE ) {
130
+ points = valuesArrayCache .get ().get ()[length ];
131
+ int i = 0 ;
132
+ for (int [] ordinal : ordinals ) {
133
+ int loc = ordinal [docId ];
134
+ if (loc != 0 ) {
135
+ points [i ++].latlon (lat [loc ], lon [loc ]);
136
+ }
124
137
}
125
138
} else {
126
- points = new GeoPoint [docOrders .length ];
127
- for (int i = 0 ; i < docOrders .length ; i ++) {
128
- int loc = docOrders [i ];
129
- points [i ] = new GeoPoint (lat [loc ], lon [loc ]);
139
+ points = new GeoPoint [length ];
140
+ int i = 0 ;
141
+ for (int [] ordinal : ordinals ) {
142
+ int loc = ordinal [docId ];
143
+ if (loc != 0 ) {
144
+ points [i ++] = new GeoPoint (lat [loc ], lon [loc ]);
145
+ }
130
146
}
131
147
}
132
148
return points ;
133
149
}
134
150
135
151
@ Override public double latValue (int docId ) {
136
- int [] docOrders = ordinals [docId ];
137
- if (docOrders == null ) {
138
- return 0 ;
152
+ for (int [] ordinal : ordinals ) {
153
+ int loc = ordinal [docId ];
154
+ if (loc != 0 ) {
155
+ return lat [loc ];
156
+ }
139
157
}
140
- return lat [ docOrders [ 0 ]] ;
158
+ return 0 ;
141
159
}
142
160
143
161
@ Override public double lonValue (int docId ) {
144
- int [] docOrders = ordinals [docId ];
145
- if (docOrders == null ) {
146
- return 0 ;
162
+ for (int [] ordinal : ordinals ) {
163
+ int loc = ordinal [docId ];
164
+ if (loc != 0 ) {
165
+ return lon [loc ];
166
+ }
147
167
}
148
- return lon [ docOrders [ 0 ]] ;
168
+ return 0 ;
149
169
}
150
170
151
171
@ Override public double [] latValues (int docId ) {
152
- int [] docOrders = ordinals [docId ];
153
- if (docOrders == null ) {
172
+ int length = 0 ;
173
+ for (int [] ordinal : ordinals ) {
174
+ if (ordinal [docId ] != 0 ) {
175
+ length ++;
176
+ }
177
+ }
178
+ if (length == 0 ) {
154
179
return DoubleFieldData .EMPTY_DOUBLE_ARRAY ;
155
180
}
156
181
double [] doubles ;
157
- if (docOrders . length < VALUE_CACHE_SIZE ) {
158
- doubles = valuesLatCache .get ().get ()[docOrders . length ];
182
+ if (length < VALUE_CACHE_SIZE ) {
183
+ doubles = valuesLatCache .get ().get ()[length ];
159
184
} else {
160
- doubles = new double [docOrders . length ];
185
+ doubles = new double [length ];
161
186
}
162
- for (int i = 0 ; i < docOrders .length ; i ++) {
163
- doubles [i ] = lat [docOrders [i ]];
187
+ int i = 0 ;
188
+ for (int [] ordinal : ordinals ) {
189
+ int loc = ordinal [docId ];
190
+ if (loc != 0 ) {
191
+ doubles [i ++] = lat [loc ];
192
+ }
164
193
}
165
194
return doubles ;
166
195
}
167
196
168
197
@ Override public double [] lonValues (int docId ) {
169
- int [] docOrders = ordinals [docId ];
170
- if (docOrders == null ) {
198
+ int length = 0 ;
199
+ for (int [] ordinal : ordinals ) {
200
+ if (ordinal [docId ] != 0 ) {
201
+ length ++;
202
+ }
203
+ }
204
+ if (length == 0 ) {
171
205
return DoubleFieldData .EMPTY_DOUBLE_ARRAY ;
172
206
}
173
207
double [] doubles ;
174
- if (docOrders . length < VALUE_CACHE_SIZE ) {
175
- doubles = valuesLonCache .get ().get ()[docOrders . length ];
208
+ if (length < VALUE_CACHE_SIZE ) {
209
+ doubles = valuesLonCache .get ().get ()[length ];
176
210
} else {
177
- doubles = new double [docOrders . length ];
211
+ doubles = new double [length ];
178
212
}
179
- for (int i = 0 ; i < docOrders .length ; i ++) {
180
- doubles [i ] = lon [docOrders [i ]];
213
+ int i = 0 ;
214
+ for (int [] ordinal : ordinals ) {
215
+ int loc = ordinal [docId ];
216
+ if (loc != 0 ) {
217
+ doubles [i ++] = lon [loc ];
218
+ }
181
219
}
182
220
return doubles ;
183
221
}
0 commit comments