Skip to content

Commit 07763dd

Browse files
authored
Use T first, T... more in $search/$setWindowFields query building API to represent that at least one value is required (#966)
1 parent 1375eee commit 07763dd

36 files changed

+594
-421
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Objects;
3636

3737
import static com.mongodb.assertions.Assertions.assertTrue;
38+
import static com.mongodb.internal.Iterables.concat;
3839
import static java.util.Arrays.asList;
3940
import static org.bson.assertions.Assertions.notNull;
4041

@@ -614,17 +615,17 @@ public static Bson sample(final int size) {
614615
* Sorting is required by certain functions and may be required by some windows (see {@link Windows} for more details).
615616
* Sorting is used only for the purpose of computing window functions and does not guarantee ordering
616617
* of the output documents.
617-
* @param output A nonempty array of {@linkplain WindowedComputation windowed computations}.
618+
* @param output A {@linkplain WindowedComputation windowed computation}.
619+
* @param moreOutput More {@linkplain WindowedComputation windowed computations}.
618620
* @param <TExpression> The {@code partitionBy} expression type.
619621
* @return The {@code $setWindowFields} pipeline stage.
620622
* @mongodb.driver.dochub core/window-functions-set-window-fields $setWindowFields
621623
* @mongodb.server.release 5.0
622624
* @since 4.3
623625
*/
624626
public static <TExpression> Bson setWindowFields(@Nullable final TExpression partitionBy, @Nullable final Bson sortBy,
625-
final WindowedComputation... output) {
626-
notNull("output", output);
627-
return setWindowFields(partitionBy, sortBy, asList(output));
627+
final WindowedComputation output, final WindowedComputation... moreOutput) {
628+
return setWindowFields(partitionBy, sortBy, concat(notNull("output", output), moreOutput));
628629
}
629630

630631
/**
@@ -640,7 +641,8 @@ public static <TExpression> Bson setWindowFields(@Nullable final TExpression par
640641
* Sorting is required by certain functions and may be required by some windows (see {@link Windows} for more details).
641642
* Sorting is used only for the purpose of computing window functions and does not guarantee ordering
642643
* of the output documents.
643-
* @param output A nonempty list of {@linkplain WindowedComputation windowed computations}.
644+
* @param output A list of {@linkplain WindowedComputation windowed computations}.
645+
* Specifying an empty list is not an error, but the resulting stage does not do anything useful.
644646
* @param <TExpression> The {@code partitionBy} expression type.
645647
* @return The {@code $setWindowFields} pipeline stage.
646648
* @mongodb.driver.dochub core/window-functions-set-window-fields $setWindowFields

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import com.mongodb.annotations.Evolving;
2020

2121
/**
22-
* @see SearchOperator#autocomplete(String, FieldSearchPath)
23-
* @see SearchOperator#autocomplete(Iterable, FieldSearchPath)
22+
* @see SearchOperator#autocomplete(FieldSearchPath, String, String...)
23+
* @see SearchOperator#autocomplete(FieldSearchPath, Iterable)
2424
* @since 4.7
2525
*/
2626
@Evolving
@@ -32,10 +32,18 @@ public interface AutocompleteSearchOperator extends SearchOperator {
3232
/**
3333
* Creates a new {@link AutocompleteSearchOperator} that uses fuzzy search.
3434
*
35-
* @param option Fuzzy search option.
3635
* @return A new {@link AutocompleteSearchOperator}.
3736
*/
38-
AutocompleteSearchOperator fuzzy(SearchFuzzy option);
37+
AutocompleteSearchOperator fuzzy();
38+
39+
/**
40+
* Creates a new {@link AutocompleteSearchOperator} that uses fuzzy search.
41+
*
42+
* @param options The fuzzy search options.
43+
* Specifying {@link FuzzySearchOptions#fuzzySearchOptions()} is equivalent to calling {@link #fuzzy()}.
44+
* @return A new {@link AutocompleteSearchOperator}.
45+
*/
46+
AutocompleteSearchOperator fuzzy(FuzzySearchOptions options);
3947

4048
/**
4149
* Creates a new {@link AutocompleteSearchOperator} that does not require tokens to appear in the same order as they are specified.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.time.Instant;
2323

2424
/**
25-
* @see SearchOperator#near(Instant, Duration, FieldSearchPath)
25+
* @see SearchOperator#near(Instant, Duration, FieldSearchPath, FieldSearchPath...)
2626
* @see SearchOperator#near(Instant, Duration, Iterable)
2727
* @since 4.7
2828
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.mongodb.annotations.Evolving;
2020

2121
/**
22-
* @see SearchOperator#dateRange(FieldSearchPath)
22+
* @see SearchOperator#dateRange(FieldSearchPath, FieldSearchPath...)
2323
* @see SearchOperator#dateRange(Iterable)
2424
* @since 4.7
2525
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* A base for a {@link DateRangeSearchOperator} which allows creating instances of this operator.
2525
* This interface is a technicality and does not represent a meaningful element of the full-text search query syntax.
2626
*
27-
* @see SearchOperator#dateRange(FieldSearchPath)
27+
* @see SearchOperator#dateRange(FieldSearchPath, FieldSearchPath...)
2828
* @see SearchOperator#dateRange(Iterable)
2929
* @since 4.7
3030
*/

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import com.mongodb.annotations.Evolving;
2020
import org.bson.conversions.Bson;
2121

22-
import static com.mongodb.assertions.Assertions.notNull;
23-
2422
/**
2523
* Fuzzy search options that may be used with some {@link SearchOperator}s.
2624
*
@@ -30,58 +28,58 @@
3028
*/
3129
@Evolving
3230
@Beta(Beta.Reason.CLIENT)
33-
public interface SearchFuzzy extends Bson {
31+
public interface FuzzySearchOptions extends Bson {
3432
/**
35-
* Creates a new {@link SearchFuzzy} with the maximum
33+
* Creates a new {@link FuzzySearchOptions} with the maximum
3634
* <a href="https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance">number of single-character edits</a>
3735
* required to match a search term.
3836
*
3937
* @param maxEdits The maximum number of single-character edits required to match a search term.
40-
* @return A new {@link SearchFuzzy}.
38+
* @return A new {@link FuzzySearchOptions}.
4139
*/
42-
SearchFuzzy maxEdits(int maxEdits);
40+
FuzzySearchOptions maxEdits(int maxEdits);
4341

4442
/**
45-
* Creates a new {@link SearchFuzzy} with the number of characters at the beginning of a search term that must exactly match.
43+
* Creates a new {@link FuzzySearchOptions} with the number of characters at the beginning of a search term that must exactly match.
4644
*
4745
* @param prefixLength The number of characters at the beginning of a search term that must exactly match.
48-
* @return A new {@link SearchFuzzy}.
46+
* @return A new {@link FuzzySearchOptions}.
4947
*/
50-
SearchFuzzy prefixLength(int prefixLength);
48+
FuzzySearchOptions prefixLength(int prefixLength);
5149

5250
/**
53-
* Creates a new {@link SearchFuzzy} with the maximum number of variations to generate and consider to match a search term.
51+
* Creates a new {@link FuzzySearchOptions} with the maximum number of variations to generate and consider to match a search term.
5452
*
5553
* @param maxExpansions The maximum number of variations to generate and consider to match a search term.
56-
* @return A new {@link SearchFuzzy}.
54+
* @return A new {@link FuzzySearchOptions}.
5755
*/
58-
SearchFuzzy maxExpansions(int maxExpansions);
56+
FuzzySearchOptions maxExpansions(int maxExpansions);
5957

6058
/**
61-
* Creates a new {@link SearchFuzzy} from a {@link Bson} in situations when there is no builder method that better satisfies your needs.
59+
* Creates a new {@link FuzzySearchOptions} with the specified option in situations when there is no builder method
60+
* that better satisfies your needs.
6261
* This method cannot be used to validate the syntax.
6362
* <p>
6463
* <i>Example</i><br>
65-
* The following code creates two functionally equivalent {@link SearchFuzzy} objects,
64+
* The following code creates two functionally equivalent {@link FuzzySearchOptions} objects,
6665
* though they may not be {@linkplain Object#equals(Object) equal}.
6766
* <pre>{@code
68-
* SearchFuzzy fuzzy1 = SearchFuzzy.defaultSearchFuzzy().maxEdits(1);
69-
* SearchFuzzy fuzzy2 = SearchFuzzy.of(new Document("maxEdits", 1));
67+
* FuzzySearchOptions options1 = FuzzySearchOptions.fuzzySearchOptions().maxEdits(1)
68+
* FuzzySearchOptions options2 = FuzzySearchOptions.fuzzySearchOptions().option("maxEdits", 1)
7069
* }</pre>
7170
*
72-
* @param fuzzy A {@link Bson} representing the required {@link SearchFuzzy}.
73-
* @return A new {@link SearchFuzzy}.
71+
* @param name The option name.
72+
* @param value The option value.
73+
* @return A new {@link FuzzySearchOptions}.
7474
*/
75-
static SearchFuzzy of(final Bson fuzzy) {
76-
return new SearchConstructibleBson(notNull("fuzzy", fuzzy));
77-
}
75+
FuzzySearchOptions option(String name, Object value);
7876

7977
/**
80-
* Returns {@link SearchFuzzy} that represents server defaults.
78+
* Returns {@link FuzzySearchOptions} that represents server defaults.
8179
*
82-
* @return {@link SearchFuzzy} that represents server defaults.
80+
* @return {@link FuzzySearchOptions} that represents server defaults.
8381
*/
84-
static SearchFuzzy defaultSearchFuzzy() {
82+
static FuzzySearchOptions fuzzySearchOptions() {
8583
return SearchConstructibleBson.EMPTY_IMMUTABLE;
8684
}
8785
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.mongodb.client.model.geojson.Point;
2121

2222
/**
23-
* @see SearchOperator#near(Point, Number, FieldSearchPath)
23+
* @see SearchOperator#near(Point, Number, FieldSearchPath, FieldSearchPath...)
2424
* @see SearchOperator#near(Point, Number, Iterable)
2525
* @since 4.7
2626
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.mongodb.annotations.Evolving;
2020

2121
/**
22-
* @see SearchOperator#near(Number, Number, FieldSearchPath)
22+
* @see SearchOperator#near(Number, Number, FieldSearchPath, FieldSearchPath...)
2323
* @see SearchOperator#near(Number, Number, Iterable)
2424
* @since 4.7
2525
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.mongodb.annotations.Evolving;
2020

2121
/**
22-
* @see SearchOperator#numberRange(FieldSearchPath)
22+
* @see SearchOperator#numberRange(FieldSearchPath, FieldSearchPath...)
2323
* @see SearchOperator#numberRange(Iterable)
2424
* @since 4.7
2525
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* A base for a {@link NumberRangeSearchOperator} which allows creating instances of this operator.
2323
* This interface is a technicality and does not represent a meaningful element of the full-text search query syntax.
2424
*
25-
* @see SearchOperator#numberRange(FieldSearchPath)
25+
* @see SearchOperator#numberRange(FieldSearchPath, FieldSearchPath...)
2626
* @see SearchOperator#numberRange(Iterable)
2727
* @since 4.7
2828
*/

0 commit comments

Comments
 (0)