Skip to content

Test Java Atlas Workflow #1

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 17 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion generated-examples/java/AnnQueryBasic.snippet.example.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class AnnQueryBasic {
public static void main(String[] args ) {
// Replace the placeholder with your Atlas connection string
String uri = <connectionString>;
String uri = "<connectionString>";

// Connect to your Atlas cluster
try (MongoClient mongoClient = MongoClients.create(uri)) {
Expand Down
21 changes: 12 additions & 9 deletions generated-examples/java/AnnQueryFilter.snippet.example.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import static com.mongodb.client.model.Aggregates.*;
import static com.mongodb.client.model.Projections.*;
import static com.mongodb.client.model.Aggregates.project;
import static com.mongodb.client.model.Aggregates.vectorSearch;
import static com.mongodb.client.model.Projections.exclude;
import static com.mongodb.client.model.Projections.fields;
import static com.mongodb.client.model.Projections.include;
import static com.mongodb.client.model.Projections.metaVectorSearchScore;
import static com.mongodb.client.model.search.SearchPath.fieldPath;
import static com.mongodb.client.model.search.VectorSearchOptions.approximateVectorSearchOptions;
import static java.util.Arrays.asList;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.*;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.search.VectorSearchOptions;

import java.util.ArrayList;
import java.util.List;
import com.mongodb.client.model.search.FieldSearchPath;
import org.bson.Document;
import org.bson.conversions.Bson;

import static java.util.Arrays.asList;
import java.util.ArrayList;
import java.util.List;

public class AnnQueryFilter {
public static void main(String[] args ) {
// Replace the placeholder with your Atlas connection string
String uri = <connectionString>;
String uri = "<connectionString>";

// Connect to your Atlas cluster
try (MongoClient mongoClient = MongoClients.create(uri)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class CreateIndexBasic {
public static void main(String[] args) {
// Replace the placeholder with your Atlas connection string
String uri = <connectionString>;
String uri = "<connectionString>";

// Connect to your Atlas cluster
try (MongoClient mongoClient = MongoClients.create(uri)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class CreateIndexFilter {
public static void main(String[] args) {
// Replace the placeholder with your Atlas connection string
String uri = <connectionString>;
String uri = "<connectionString>";

// Connect to your Atlas cluster
try (MongoClient mongoClient = MongoClients.create(uri)) {
Expand Down
2 changes: 1 addition & 1 deletion generated-examples/java/DropIndex.snippet.example.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class DropIndex {
public static void main(String[] args) {
// Replace the placeholder with your Atlas connection string
String uri = <connectionString>;
String uri = "<connectionString>";

// Connect to your Atlas cluster
try (MongoClient mongoClient = MongoClients.create(uri)) {
Expand Down
2 changes: 1 addition & 1 deletion generated-examples/java/ViewIndex.snippet.example.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class ViewIndex {
public static void main(String[] args) {
// Replace the placeholder with your Atlas connection string
String uri = <connectionString>;
String uri = "<connectionString>";

// Connect to your Atlas cluster
try (MongoClient mongoClient = MongoClients.create(uri)) {
Expand Down
1 change: 1 addition & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<atlas.connection.string>${env.ATLAS_CONNECTION_STRING}</atlas.connection.string>
</properties>
<dependencies>
<!-- Unit testing framework -->
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/indexes/CreateIndexBasic.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :replace-start: {
// "terms": {
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "<connectionString>"
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "\"<connectionString>\""
// }
// }
package indexes;
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/indexes/CreateIndexFilter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :replace-start: {
// "terms": {
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "<connectionString>"
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "\"<connectionString>\""
// }
// }
package indexes;
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/indexes/DropIndex.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :replace-start: {
// "terms": {
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "<connectionString>"
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "\"<connectionString>\""
// }
// }
package indexes;
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/indexes/ViewIndex.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// :replace-start: {
// "terms": {
// "Document": "void",
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "<connectionString>"
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "\"<connectionString>\""
// }
// }
package indexes;
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/queries/AnnQueryBasic.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// :replace-start: {
// "terms": {
// "ArrayList<Document>": "void",
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "<connectionString>"
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "\"<connectionString>\""
// }
// }
package queries;
Expand Down
23 changes: 13 additions & 10 deletions java/src/main/java/queries/AnnQueryFilter.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
// :replace-start: {
// "terms": {
// "ArrayList<Document>": "void",
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "<connectionString>"
// "System.getenv(\"ATLAS_CONNECTION_STRING\")": "\"<connectionString>\""
// }
// }
package queries;
// :snippet-start: example
import static com.mongodb.client.model.Aggregates.*;
import static com.mongodb.client.model.Projections.*;
import static com.mongodb.client.model.Aggregates.project;
import static com.mongodb.client.model.Aggregates.vectorSearch;
import static com.mongodb.client.model.Projections.exclude;
import static com.mongodb.client.model.Projections.fields;
import static com.mongodb.client.model.Projections.include;
import static com.mongodb.client.model.Projections.metaVectorSearchScore;
import static com.mongodb.client.model.search.SearchPath.fieldPath;
import static com.mongodb.client.model.search.VectorSearchOptions.approximateVectorSearchOptions;
import static java.util.Arrays.asList;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.*;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.search.VectorSearchOptions;

import java.util.ArrayList;
import java.util.List;
import com.mongodb.client.model.search.FieldSearchPath;
import org.bson.Document;
import org.bson.conversions.Bson;

import static java.util.Arrays.asList;
import java.util.ArrayList;
import java.util.List;

public class AnnQueryFilter {
public static ArrayList<Document> main(String[] args ) {
// Replace the placeholder with your Atlas connection string
// Replace the placeholder with your Atlas connection string.
String uri = System.getenv("ATLAS_CONNECTION_STRING");

// Connect to your Atlas cluster
Expand Down
20 changes: 10 additions & 10 deletions java/src/test/java/queries/QueryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ void TestAnnQueryBasic() {
if (Objects.equals(env, "Atlas")) {
expected.add(new Document("plot", "A reporter, learning of time travelers visiting 20th century disasters, tries to change the history they know by averting upcoming disasters.").append("title", "Thrill Seekers").append("score", 0.7892671227455139));
expected.add(new Document("plot", "At the age of 21, Tim discovers he can travel in time and change what happens and has happened in his own life. His decision to make his world a better place by getting a girlfriend turns out not to be as easy as you might think.").append("title", "About Time").append("score", 0.7843604683876038));
expected.add(new Document("plot", "Hoping to alter the events of the past, a 19th century inventor instead travels 800,000 years into the future, where he finds humankind divided into two warring races.").append("title", "The Time Machine").append("score", 0.7801066637039185));
expected.add(new Document("plot", "Hoping to alter the events of the past, a 19th century inventor instead travels 800,000 years into the future, where he finds humankind divided into two warring races.").append("title", "The Time Machine").append("score", 0.7801067233085632));
expected.add(new Document("plot", "After using his mother's newly built time machine, Dolf gets stuck involuntary in the year 1212. He ends up in a children's crusade where he confronts his new friends with modern techniques...").append("title", "Crusade in Jeans").append("score", 0.7789170742034912));
expected.add(new Document("plot", "An officer for a security agency that regulates time travel, must fend for his life against a shady politician who has a tie to his past.").append("title", "Timecop").append("score", 0.7771612405776978));
expected.add(new Document("plot", "An officer for a security agency that regulates time travel, must fend for his life against a shady politician who has a tie to his past.").append("title", "Timecop").append("score", 0.7771613597869873));
expected.add(new Document("plot", "A time-travel experiment in which a robot probe is sent from the year 2073 to the year 1973 goes terribly wrong thrusting one of the project scientists, a man named Nicholas Sinclair into a...").append("title", "A.P.E.X.").append("score", 0.7730885744094849));
expected.add(new Document("plot", "Agent J travels in time to M.I.B.'s early days in 1969 to stop an alien from assassinating his friend Agent K and changing history.").append("title", "Men in Black 3").append("score", 0.7712380886077881));
expected.add(new Document("plot", "Agent J travels in time to M.I.B.'s early days in 1969 to stop an alien from assassinating his friend Agent K and changing history.").append("title", "Men in Black 3").append("score", 0.7712380290031433));
expected.add(new Document("plot", "Bound by a shared destiny, a teen bursting with scientific curiosity and a former boy-genius inventor embark on a mission to unearth the secrets of a place somewhere in time and space that exists in their collective memory.").append("title", "Tomorrowland").append("score", 0.7669923901557922));
expected.add(new Document("plot", "With the help of his uncle, a man travels to the future to try and bring his girlfriend back to life.").append("title", "Love Story 2050").append("score", 0.7649372816085815));
expected.add(new Document("plot", "With the help of his uncle, a man travels to the future to try and bring his girlfriend back to life.").append("title", "Love Story 2050").append("score", 0.7649372220039368));
expected.add(new Document("plot", "A dimension-traveling wizard gets stuck in the 21st century because cell-phone radiation interferes with his magic. With his home world on the brink of war, he seeks help from a jaded ...").append("title", "The Portal").append("score", 0.7640786170959473));
} else if (Objects.equals(env, "local")) {
expected.add(new Document("plot", "A reporter, learning of time travelers visiting 20th century disasters, tries to change the history they know by averting upcoming disasters.").append("title", "Thrill Seekers").append("score", 0.7892671227455139));
Expand Down Expand Up @@ -80,13 +80,13 @@ void TestAnnQueryFilter() {
if (Objects.equals(env, "Atlas")) {
expected.add(new Document("plot", "In this magical tale about the boy who refuses to grow up, Peter Pan and his mischievous fairy sidekick Tinkerbell visit the nursery of Wendy, Michael, and John Darling. With a sprinkling ...").append("title", "Peter Pan").append("year", 1960).append("score", 0.748110830783844));
expected.add(new Document("plot", "A down-on-his-luck inventor turns a broken-down Grand Prix car into a fancy vehicle for his children, and then they go off on a magical fantasy adventure to save their grandfather in a far-off land.").append("title", "Chitty Chitty Bang Bang").append("year", 1968).append("score", 0.7442465424537659));
expected.add(new Document("plot", "A young man comes to the rescue of his girlfriend abducted by thieves and brought to Rio. An extravagant adventure ensues.").append("title", "That Man from Rio").append("year", 1964).append("score", 0.7416020035743713));
expected.add(new Document("plot", "A young man comes to the rescue of his girlfriend abducted by thieves and brought to Rio. An extravagant adventure ensues.").append("title", "That Man from Rio").append("year", 1964).append("score", 0.7416019439697266));
expected.add(new Document("plot", "A pilot, stranded in the desert, meets a little boy who is a prince on a planet.").append("title", "The Little Prince").append("year", 1974).append("score", 0.7378944158554077));
expected.add(new Document("plot", "A red balloon with a life of its own follows a little boy around the streets of Paris.").append("title", "The Red Balloon").append("year", 1956).append("score", 0.7342712879180908));
expected.add(new Document("plot", "A poor boy wins the opportunity to tour the most eccentric and wonderful candy factory of all.").append("title", "Willy Wonka & the Chocolate Factory").append("year", 1971).append("score", 0.7342107892036438));
expected.add(new Document("plot", "An apprentice witch, three kids and a cynical conman search for the missing component to a magic spell useful to the defense of Britain.").append("title", "Bedknobs and Broomsticks").append("year", 1971).append("score", 0.7339356541633606));
expected.add(new Document("plot", "A young boys' coming of age tale set in a strange, carnivalesque village becomes the recreation of a memory that the director has twenty years later.").append("title", "Pastoral Hide and Seek").append("year", 1974).append("score", 0.733299970626831));
expected.add(new Document("plot", "A young swordsman comes to Paris and faces villains, romance, adventure and intrigue with three Musketeer friends.").append("title", "The Three Musketeers").append("year", 1973).append("score", 0.7331198453903198));
expected.add(new Document("plot", "A red balloon with a life of its own follows a little boy around the streets of Paris.").append("title", "The Red Balloon").append("year", 1956).append("score", 0.734271228313446));
expected.add(new Document("plot", "A poor boy wins the opportunity to tour the most eccentric and wonderful candy factory of all.").append("title", "Willy Wonka & the Chocolate Factory").append("year", 1971).append("score", 0.7342106699943542));
expected.add(new Document("plot", "An apprentice witch, three kids and a cynical conman search for the missing component to a magic spell useful to the defense of Britain.").append("title", "Bedknobs and Broomsticks").append("year", 1971).append("score", 0.7339357137680054));
expected.add(new Document("plot", "A young boys' coming of age tale set in a strange, carnivalesque village becomes the recreation of a memory that the director has twenty years later.").append("title", "Pastoral Hide and Seek").append("year", 1974).append("score", 0.7332999110221863));
expected.add(new Document("plot", "A young swordsman comes to Paris and faces villains, romance, adventure and intrigue with three Musketeer friends.").append("title", "The Three Musketeers").append("year", 1973).append("score", 0.733119785785675));
expected.add(new Document("plot", "A fairy-tale about a conceited young man and a young woman with a tyrannical step-mother, who must overcome magical trials in order to be together.").append("title", "Frosty").append("year", 1964).append("score", 0.7318308353424072));
} else if (Objects.equals(env, "local")) {
expected.add(new Document("plot", "In this magical tale about the boy who refuses to grow up, Peter Pan and his mischievous fairy sidekick Tinkerbell visit the nursery of Wendy, Michael, and John Darling. With a sprinkling ...").append("title", "Peter Pan").append("year", 1960).append("score", 0.748110830783844));
Expand Down