Skip to content

Commit b0ceebb

Browse files
authored
Fix of $search-related methods that are supposed to produce a BSON element but instead produce a BSON document (#964)
JAVA-4190
1 parent 18cb299 commit b0ceebb

16 files changed

+267
-77
lines changed

driver-core/src/main/com/mongodb/client/model/search/DateRangeConstructibleBsonElement.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ final class DateRangeConstructibleBsonElement extends RangeConstructibleBsonElem
2525
super(name, value);
2626
}
2727

28+
private DateRangeConstructibleBsonElement(final Bson baseElement, final Bson appendedElementValue) {
29+
super(baseElement, appendedElementValue);
30+
}
31+
2832
@Override
29-
protected DateRangeConstructibleBsonElement newSelf(final String name, final Bson value) {
30-
return new DateRangeConstructibleBsonElement(name, value);
33+
protected DateRangeConstructibleBsonElement newSelf(final Bson baseElement, final Bson appendedElementValue) {
34+
return new DateRangeConstructibleBsonElement(baseElement, appendedElementValue);
3135
}
3236

3337
@Override

driver-core/src/main/com/mongodb/client/model/search/NumberRangeConstructibleBsonElement.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ final class NumberRangeConstructibleBsonElement extends RangeConstructibleBsonEl
2323
super(name, value);
2424
}
2525

26+
private NumberRangeConstructibleBsonElement(final Bson baseElement, final Bson appendedElementValue) {
27+
super(baseElement, appendedElementValue);
28+
}
29+
2630
@Override
27-
protected NumberRangeConstructibleBsonElement newSelf(final String name, final Bson value) {
28-
return new NumberRangeConstructibleBsonElement(name, value);
31+
protected NumberRangeConstructibleBsonElement newSelf(final Bson baseElement, final Bson appendedElementValue) {
32+
return new NumberRangeConstructibleBsonElement(baseElement, appendedElementValue);
2933
}
3034

3135
@Override

driver-core/src/main/com/mongodb/client/model/search/RangeConstructibleBsonElement.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ abstract class RangeConstructibleBsonElement<T, S extends RangeConstructibleBson
2727
super(name, value);
2828
}
2929

30+
RangeConstructibleBsonElement(final Bson baseElement, final Bson appendedElementValue) {
31+
super(baseElement, appendedElementValue);
32+
}
33+
3034
public final S score(final SearchScore modifier) {
3135
return newWithAppendedValue("score", notNull("modifier", modifier));
3236
}

driver-core/src/main/com/mongodb/client/model/search/SearchCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ static FacetSearchCollector facet(final SearchOperator operator, final Iterable<
8989
* @return The requested {@link SearchCollector}.
9090
*/
9191
static SearchCollector of(final Bson collector) {
92-
return new SearchConstructibleBson(notNull("collector", collector));
92+
return new SearchConstructibleBsonElement(notNull("collector", collector));
9393
}
9494
}

driver-core/src/main/com/mongodb/client/model/search/SearchConstructibleBson.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@
2727
import static com.mongodb.assertions.Assertions.notNull;
2828

2929
final class SearchConstructibleBson extends AbstractConstructibleBson<SearchConstructibleBson> implements
30-
SearchOperator,
31-
SearchScore,
3230
RelevanceSearchScoreExpression, ConstantSearchScoreExpression, LogSearchScoreExpression, Log1pSearchScoreExpression,
3331
AddSearchScoreExpression, MultiplySearchScoreExpression,
34-
SearchCollector,
3532
SearchOptions,
3633
SearchHighlight,
3734
TotalSearchCount, LowerBoundSearchCount,
3835
SearchFuzzy,
39-
FieldSearchPath, WildcardSearchPath,
40-
SearchFacet {
36+
FieldSearchPath, WildcardSearchPath {
4137
/**
42-
* An {@linkplain Immutable immutable} empty instance.
38+
* An {@linkplain Immutable immutable} {@link BsonDocument#isEmpty() empty} instance.
4339
*/
44-
static final SearchConstructibleBson EMPTY = new SearchConstructibleBson(new BsonDocument());
40+
static final SearchConstructibleBson EMPTY_IMMUTABLE = new SearchConstructibleBson(AbstractConstructibleBson.EMPTY_IMMUTABLE);
4541

4642
SearchConstructibleBson(final Bson base) {
4743
super(base);
@@ -115,9 +111,4 @@ public SearchFuzzy maxExpansions(final int maxExpansions) {
115111
public FieldSearchPath multi(final String analyzerName) {
116112
return newAppended("multi", new BsonString(notNull("analyzerName", analyzerName)));
117113
}
118-
119-
@Override
120-
public SearchOperator score(final SearchScore modifier) {
121-
return newAppended("score", notNull("modifier", modifier));
122-
}
123114
}

driver-core/src/main/com/mongodb/client/model/search/SearchConstructibleBsonElement.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
import java.util.stream.StreamSupport;
2525

2626
import static com.mongodb.assertions.Assertions.isTrueArgument;
27-
import static com.mongodb.internal.client.model.Util.sizeAtLeast;
2827
import static com.mongodb.assertions.Assertions.notNull;
28+
import static com.mongodb.internal.client.model.Util.sizeAtLeast;
2929

3030
final class SearchConstructibleBsonElement extends AbstractConstructibleBsonElement<SearchConstructibleBsonElement> implements
3131
CompoundSearchOperatorBase, CompoundSearchOperator,
3232
MustCompoundSearchOperator, MustNotCompoundSearchOperator, ShouldCompoundSearchOperator, FilterCompoundSearchOperator,
3333
ExistsSearchOperator, TextSearchOperator, AutocompleteSearchOperator,
3434
NumberNearSearchOperator, DateNearSearchOperator, GeoNearSearchOperator,
35-
ValueBoostSearchScore, PathBoostSearchScore, ConstantSearchScore, FunctionSearchScore, GaussSearchScoreExpression,
36-
PathSearchScoreExpression,
35+
ValueBoostSearchScore, PathBoostSearchScore, ConstantSearchScore, FunctionSearchScore,
36+
GaussSearchScoreExpression, PathSearchScoreExpression,
3737
FacetSearchCollector,
3838
StringSearchFacet, NumberSearchFacet, DateSearchFacet {
3939
SearchConstructibleBsonElement(final String name) {
@@ -44,9 +44,17 @@ final class SearchConstructibleBsonElement extends AbstractConstructibleBsonElem
4444
super(name, value);
4545
}
4646

47+
SearchConstructibleBsonElement(final Bson baseElement) {
48+
super(baseElement);
49+
}
50+
51+
private SearchConstructibleBsonElement(final Bson baseElement, final Bson appendedElementValue) {
52+
super(baseElement, appendedElementValue);
53+
}
54+
4755
@Override
48-
protected SearchConstructibleBsonElement newSelf(final String name, final Bson value) {
49-
return new SearchConstructibleBsonElement(name, value);
56+
protected SearchConstructibleBsonElement newSelf(final Bson baseElement, final Bson appendedElementValue) {
57+
return new SearchConstructibleBsonElement(baseElement, appendedElementValue);
5058
}
5159

5260
@Override

driver-core/src/main/com/mongodb/client/model/search/SearchFacet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static DateSearchFacet dateFacet(final String name, final FieldSearchPath path,
116116
* @return The requested {@link SearchFacet}.
117117
*/
118118
static SearchFacet of(final Bson facet) {
119-
return new SearchConstructibleBson(notNull("facet", facet));
119+
return new SearchConstructibleBsonElement(notNull("facet", facet));
120120
}
121121

122122
/**

driver-core/src/main/com/mongodb/client/model/search/SearchFuzzy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ static SearchFuzzy of(final Bson fuzzy) {
8282
* @return {@link SearchFuzzy} that represents server defaults.
8383
*/
8484
static SearchFuzzy defaultSearchFuzzy() {
85-
return SearchConstructibleBson.EMPTY;
85+
return SearchConstructibleBson.EMPTY_IMMUTABLE;
8686
}
8787
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,6 @@ static GeoNearSearchOperator near(final Point origin, final Number pivot, final
304304
* @return The requested {@link SearchOperator}.
305305
*/
306306
static SearchOperator of(final Bson operator) {
307-
return new SearchConstructibleBson(notNull("operator", operator));
307+
return new SearchConstructibleBsonElement(notNull("operator", operator));
308308
}
309309
}

driver-core/src/main/com/mongodb/client/model/search/SearchOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ public interface SearchOptions extends Bson {
9191
* @return {@link SearchOptions} that represents server defaults.
9292
*/
9393
static SearchOptions defaultSearchOptions() {
94-
return SearchConstructibleBson.EMPTY;
94+
return SearchConstructibleBson.EMPTY_IMMUTABLE;
9595
}
9696
}

0 commit comments

Comments
 (0)