Skip to content

Add equals operator to Atlas Search #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change date to instant
  • Loading branch information
joykim1005 committed Jan 8, 2025
commit 9709f0e250b6d6c489f16b429e65ec8b20edd966
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ static EqualsSearchOperator equals(final FieldSearchPath path, @Nullable final N
* Returns a {@link SearchOperator} that performs a search for documents containing an ordered sequence of terms.
*
* @param path The indexed field to be searched.
* @param value The date value to query for.
* @param value The instant date value to query for.
* @return The requested {@link SearchOperator}.
* @mongodb.atlas.manual atlas-search/equals/ equals operator
*/
static EqualsSearchOperator equals(final FieldSearchPath path, @Nullable final Date value) {
static EqualsSearchOperator equals(final FieldSearchPath path, @Nullable final Instant value) {
if (value == null) {
return new SearchConstructibleBsonElement("equals", new Document("path", notNull("path", path).toValue())
.append("value", BsonNull.VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ void near() {
@Test
void equals() {
ObjectId id = new ObjectId();
BsonDateTime date = new BsonDateTime(System.currentTimeMillis());
UUID uuid = UUID.randomUUID();
Optional<String> optionalValue = Optional.ofNullable(null);
assertAll(
Expand Down Expand Up @@ -646,10 +645,10 @@ void equals() {
() -> assertEquals(
new BsonDocument("equals",
new BsonDocument("path", fieldPath("fieldName").toBsonValue())
.append("value", date)
.append("value", new BsonDateTime(Instant.EPOCH.toEpochMilli()))
),
SearchOperator.equals(
fieldPath("fieldName"), new Date(date.getValue())).toBsonDocument()
fieldPath("fieldName"), Instant.EPOCH).toBsonDocument()
),
() -> assertEquals(
new BsonDocument("equals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.mongodb.scala.model.geojson.Point
import org.bson.types.ObjectId;

import java.time.{ Duration, Instant }
import java.util.Date
import java.util.UUID
import collection.JavaConverters._

Expand Down Expand Up @@ -269,11 +268,11 @@ object SearchOperator {
* Returns a `SearchOperator` that performs a search for documents containing an ordered sequence of terms.
*
* @param path The indexed field to be searched.
* @param value The date value to query for.
* @param value The instant date value to query for.
* @return The requested `SearchOperator`.
* @see [[https://www.mongodb.com/docs/atlas/atlas-search/equals/ equals operator]]
*/
def equals(path: FieldSearchPath, value: Date): EqualsSearchOperator =
def equals(path: FieldSearchPath, value: Instant): EqualsSearchOperator =
JSearchOperator.equals(path, value)

/**
Expand Down