search for vertices where multiple properties

I need to search for vertices where multiple properties are a certain value.
Here is what I am able to come up with.

try (TinkerGraph graph = TinkerGraph.open()) {
    Vertex person1 = graph.addVertex(T.label, "Person", "name", "John", "surname", "Smith", "id", 1);
    Vertex person2 = graph.addVertex(T.label, "Person", "name", "John", "surname", "Do", "id", 2);
    Vertex person3 = graph.addVertex(T.label, "Person", "name", "John", "surname", "Ho", "id", 3);
    Vertex person4 = graph.addVertex(T.label, "Person", "name", "Jo", "surname", "Do", "id", 4);

    List<Vertex> persons = graph.traversal().V().hasLabel("Person")
            .has("name", P.within("John",  "Jo"))
            .has("surname", P.within("Smith",  "Do"))
            .toList();

    System.out.println(persons.stream().map(v -> "[" + v.value("name") + " " + v.value("surname") + "]").reduce((a,b) -> a + "," + b).orElse(""));

    persons =  graph.traversal().V().hasLabel("Person").as("person")
            .values("name").concat(__.select("person").values("surname"))
            .filter(t -> Arrays.asList("JohnSmith", "JoDo").contains(t.get()))
            .<Vertex>select("person")
            .toList();
    System.out.println(persons.stream().map(v -> "[" + v.value("name") + " " + v.value("surname") + "]").reduce((a,b) -> a + "," + b).orElse(""));
}


This will print out,

[John Smith],[John Do],[Jo Do]
[John Smith],[Jo Do]


The second query is the results I am looking for, but is there a better way to do this?
Using concat and filter is hard to optimize.
Was this page helpful?