Skip to content

Commit 65840eb

Browse files
committed
PR fixes
1 parent 42da7af commit 65840eb

File tree

2 files changed

+51
-45
lines changed

2 files changed

+51
-45
lines changed

Diff for: driver-core/src/main/com/mongodb/client/model/search/SearchOperator.java

+37-31
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,29 @@
1818
import com.mongodb.annotations.Beta;
1919
import com.mongodb.annotations.Reason;
2020
import com.mongodb.annotations.Sealed;
21+
import com.mongodb.assertions.Assertions;
2122
import com.mongodb.client.model.Aggregates;
2223
import com.mongodb.client.model.geojson.Point;
23-
24-
import java.util.UUID;
25-
24+
import org.bson.BsonArray;
25+
import org.bson.BsonBoolean;
2626
import org.bson.BsonType;
27+
import org.bson.BsonValue;
2728
import org.bson.Document;
2829
import org.bson.conversions.Bson;
30+
import org.bson.types.ObjectId;
2931

3032
import java.time.Duration;
3133
import java.time.Instant;
34+
import java.util.ArrayList;
3235
import java.util.Iterator;
33-
34-
import org.bson.types.ObjectId;
36+
import java.util.List;
37+
import java.util.UUID;
3538

3639
import static com.mongodb.assertions.Assertions.isTrueArgument;
40+
import static com.mongodb.assertions.Assertions.notNull;
3741
import static com.mongodb.internal.Iterables.concat;
3842
import static com.mongodb.internal.client.model.Util.combineToBsonValue;
3943
import static java.util.Collections.singleton;
40-
import static com.mongodb.assertions.Assertions.notNull;
4144

4245
/**
4346
* The core part of the {@link Aggregates#search(SearchOperator, SearchOptions) $search} pipeline stage of an aggregation pipeline.
@@ -298,22 +301,29 @@ static GeoNearSearchOperator near(final Point origin, final Number pivot, final
298301
}
299302

300303
/**
301-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
302-
* the field equals any value in the specified array.
304+
* Returns a {@link SearchOperator} that searches for documents where the
305+
* value or array of values at a given path contains any of the specified values
303306
*
304307
* @param path The indexed field to be searched.
305308
* @param value The boolean value to search for.
306309
* @param values More fields to be searched.
307310
* @return The requested {@link SearchOperator}.
308311
* @mongodb.atlas.manual atlas-search/in/ in operator
309312
*/
310-
static InSearchOperator in(final FieldSearchPath path, final Boolean value, final Boolean... values) {
311-
return in(notNull("path", path), concat(notNull("value", value), values));
313+
static InSearchOperator in(final FieldSearchPath path, final boolean value, final boolean... values) {
314+
Assertions.notNull("values", values);
315+
List<BsonValue> list = new ArrayList<>();
316+
list.add(new BsonBoolean(value));
317+
for (boolean n : values) {
318+
list.add(new BsonBoolean(n));
319+
}
320+
BsonArray bsonArray = new BsonArray(list);
321+
return in(notNull("path", path), bsonArray);
312322
}
313323

314324
/**
315-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
316-
* the field equals any value in the specified array.
325+
* Returns a {@link SearchOperator} that searches for documents where the
326+
* value or array of values at a given path contains any of the specified values
317327
*
318328
* @param path The indexed field to be searched.
319329
* @param value The objectId value to search for.
@@ -326,8 +336,8 @@ static InSearchOperator in(final FieldSearchPath path, final ObjectId value, fin
326336
}
327337

328338
/**
329-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
330-
* the field equals any value in the specified array.
339+
* Returns a {@link SearchOperator} that searches for documents where the
340+
* value or array of values at a given path contains any of the specified values
331341
*
332342
* @param path The indexed field to be searched.
333343
* @param value The number value to search for.
@@ -340,8 +350,8 @@ static InSearchOperator in(final FieldSearchPath path, final Number value, final
340350
}
341351

342352
/**
343-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
344-
* the field equals any value in the specified array.
353+
* Returns a {@link SearchOperator} that searches for documents where the
354+
* value or array of values at a given path contains any of the specified values
345355
*
346356
* @param path The indexed field to be searched.
347357
* @param value The instant date value to search for.
@@ -354,8 +364,8 @@ static InSearchOperator in(final FieldSearchPath path, final Instant value, fina
354364
}
355365

356366
/**
357-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
358-
* the field equals any value in the specified array.
367+
* Returns a {@link SearchOperator} that searches for documents where the
368+
* value or array of values at a given path contains any of the specified values
359369
*
360370
* @param path The indexed field to be searched.
361371
* @param value The uuid value to search for.
@@ -368,8 +378,8 @@ static InSearchOperator in(final FieldSearchPath path, final UUID value, final U
368378
}
369379

370380
/**
371-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
372-
* the field equals any value in the specified array.
381+
* Returns a {@link SearchOperator} that searches for documents where the
382+
* value or array of values at a given path contains any of the specified values
373383
*
374384
* @param path The indexed field to be searched.
375385
* @param value The string value to search for.
@@ -382,27 +392,23 @@ static InSearchOperator in(final FieldSearchPath path, final String value, final
382392
}
383393

384394
/**
385-
* Returns a {@link SearchOperator} that searches for an array of values at the given path and returns documents where the value of
386-
* the field equals any value in the specified array.
395+
* Returns a {@link SearchOperator} that searches for documents where the
396+
* value or array of values at a given path contains any of the specified values
387397
*
388398
* @param path The indexed field to be searched.
389399
* @param values The non-empty values to search for. Value can be either a single value or an array of values of only one of the supported BSON types and can't be a mix of different types.
390400
* @return The requested {@link SearchOperator}.
391401
* @mongodb.atlas.manual atlas-search/in/ in operator
392402
*/
393403
static <T> InSearchOperator in(final FieldSearchPath path, final Iterable<? extends T> values) {
404+
notNull("path", path);
394405
Iterator<T> valueIterator = (Iterator<T>) notNull("values", values).iterator();
395406
isTrueArgument("values must not be empty", valueIterator.hasNext());
396407
T firstValue = valueIterator.next();
397-
398-
Iterator<T> typeIterator = (Iterator<T>) notNull("values", values).iterator();
399-
while (typeIterator.hasNext()) {
400-
Object element = typeIterator.next();
401-
isTrueArgument("values must be of same type", firstValue.getClass().isInstance(element));
402-
}
403-
404-
return new SearchConstructibleBsonElement("in", new Document("path", notNull("path", path).toValue())
405-
.append("value", valueIterator.hasNext() ? values : firstValue));
408+
boolean hasMore = valueIterator.hasNext();
409+
return new SearchConstructibleBsonElement("in", new Document()
410+
.append("path", path.toValue())
411+
.append("value", hasMore ? values : firstValue));
406412
}
407413

408414
/**

Diff for: driver-scala/src/main/scala/org/mongodb/scala/model/search/SearchOperator.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ object SearchOperator {
237237
JSearchOperator.near(origin, pivot, paths.asJava)
238238

239239
/**
240-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
241-
* the field equals any value in the specified array.
240+
* Returns a `SearchOperator` that searches for documents where the value
241+
* or array of values at a given path contains any of the specified values
242242
*
243243
* @param path The indexed field to be searched.
244244
* @param value The boolean value to search for.
@@ -250,8 +250,8 @@ object SearchOperator {
250250
JSearchOperator.in(path, value, values: _*)
251251

252252
/**
253-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
254-
* the field equals any value in the specified array.
253+
* Returns a `SearchOperator` that searches for documents where the value
254+
* or array of values at a given path contains any of the specified values
255255
*
256256
* @param path The indexed field to be searched.
257257
* @param value The objectId value to search for.
@@ -263,8 +263,8 @@ object SearchOperator {
263263
JSearchOperator.in(path, value, values: _*)
264264

265265
/**
266-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
267-
* the field equals any value in the specified array.
266+
* Returns a `SearchOperator` that searches for documents where the value
267+
* or array of values at a given path contains any of the specified values
268268
*
269269
* @param path The indexed field to be searched.
270270
* @param value The number value to search for.
@@ -276,8 +276,8 @@ object SearchOperator {
276276
JSearchOperator.in(path, value, values: _*)
277277

278278
/**
279-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
280-
* the field equals any value in the specified array.
279+
* Returns a `SearchOperator` that searches for documents where the value
280+
* or array of values at a given path contains any of the specified values
281281
*
282282
* @param path The indexed field to be searched.
283283
* @param value The instant date value to search for.
@@ -289,8 +289,8 @@ object SearchOperator {
289289
JSearchOperator.in(path, value, values: _*)
290290

291291
/**
292-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
293-
* the field equals any value in the specified array.
292+
* Returns a `SearchOperator` that searches for documents where the value
293+
* or array of values at a given path contains any of the specified values
294294
*
295295
* @param path The indexed field to be searched.
296296
* @param value The uuid value to search for.
@@ -302,8 +302,8 @@ object SearchOperator {
302302
JSearchOperator.in(path, value, values: _*)
303303

304304
/**
305-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
306-
* the field equals any value in the specified array.
305+
* Returns a `SearchOperator` that searches for documents where the value
306+
* or array of values at a given path contains any of the specified values
307307
*
308308
* @param path The indexed field to be searched.
309309
* @param value The string value to search for.
@@ -315,8 +315,8 @@ object SearchOperator {
315315
JSearchOperator.in(path, value, values: _*)
316316

317317
/**
318-
* Returns a `SearchOperator` that searches for an array of values at the given path and returns documents where the value of
319-
* the field equals any value in the specified array.
318+
* Returns a `SearchOperator` that searches for documents where the value
319+
* or array of values at a given path contains any of the specified values
320320
*
321321
* @param path The indexed field to be searched.
322322
* @param values The non-empty values to search for. Value can be either a single value or an array of values of only one of the supported BSON types and can't be a mix of different types.

0 commit comments

Comments
 (0)