|
20 | 20 | import com.mongodb.annotations.Sealed;
|
21 | 21 | import com.mongodb.client.model.Aggregates;
|
22 | 22 | import com.mongodb.client.model.geojson.Point;
|
| 23 | +import org.bson.BsonDocument; |
23 | 24 | import org.bson.BsonType;
|
24 | 25 | import org.bson.Document;
|
25 | 26 | import org.bson.conversions.Bson;
|
@@ -292,6 +293,31 @@ static GeoNearSearchOperator near(final Point origin, final Number pivot, final
|
292 | 293 | .append("pivot", notNull("pivot", pivot)));
|
293 | 294 | }
|
294 | 295 |
|
| 296 | + /** |
| 297 | + * Returns a {@link SearchOperator} that returns documents similar to input document. |
| 298 | + * |
| 299 | + * @param like The BSON document that is used to extract representative terms to query for. |
| 300 | + * @return The requested {@link SearchOperator}. |
| 301 | + * @mongodb.atlas.manual atlas-search/morelikethis/ moreLikeThis operator |
| 302 | + */ |
| 303 | + static MoreLikeThisSearchOperator moreLikeThis(final BsonDocument like) { |
| 304 | + return moreLikeThis(singleton(notNull("like", like))); |
| 305 | + } |
| 306 | + |
| 307 | + /** |
| 308 | + * Returns a {@link SearchOperator} that returns documents similar to input documents. |
| 309 | + * |
| 310 | + * @param likes The BSON documents that are used to extract representative terms to query for. |
| 311 | + * @return The requested {@link SearchOperator}. |
| 312 | + * @mongodb.atlas.manual atlas-search/morelikethis/ moreLikeThis operator |
| 313 | + */ |
| 314 | + static MoreLikeThisSearchOperator moreLikeThis(final Iterable<BsonDocument> likes) { |
| 315 | + Iterator<? extends BsonDocument> likesIterator = notNull("likes", likes).iterator(); |
| 316 | + isTrueArgument("likes must not be empty", likesIterator.hasNext()); |
| 317 | + BsonDocument firstLike = likesIterator.next(); |
| 318 | + return new SearchConstructibleBsonElement("moreLikeThis", new Document("like", likesIterator.hasNext() ? likes : firstLike)); |
| 319 | + } |
| 320 | + |
295 | 321 | /**
|
296 | 322 | * Returns a {@link SearchOperator} that supports querying a combination of indexed fields and values.
|
297 | 323 | *
|
|
0 commit comments