Search in sources :

Example 91 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class FullTextSearchDescriptionTest method filterDiscardsTheVerticesThatContainThePropertyWithADifferentTypeOfValue.

@Test
public void filterDiscardsTheVerticesThatContainThePropertyWithADifferentTypeOfValue() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(vertex -> vertex.withTimId("v1").withProperty(PROPERTY, "value12344324")).withVertex(vertex -> vertex.withTimId("v2").withProperty(PROPERTY, 12334)).withVertex(vertex -> vertex.withTimId("v3").withProperty(PROPERTY, "value1")).build().traversal().V();
    FullTextSearchParameter fullTextSearchParameter = new FullTextSearchParameter(NAME, "value");
    instance.filter(traversal, fullTextSearchParameter);
    assertThat(traversal.toList(), containsInAnyOrder(likeVertex().withTimId("v1"), likeVertex().withTimId("v3")));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) FullTextSearchDescription.createLocalFullTextSearchDescriptionWithBackupProperty(nl.knaw.huygens.timbuctoo.search.description.fulltext.FullTextSearchDescription.createLocalFullTextSearchDescriptionWithBackupProperty) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) FullTextSearchParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.FullTextSearchParameter) FullTextSearchDescription.createLocalSimpleFullTextSearchDescription(nl.knaw.huygens.timbuctoo.search.description.fulltext.FullTextSearchDescription.createLocalSimpleFullTextSearchDescription) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Matchers.is(org.hamcrest.Matchers.is) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) FullTextSearchParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.FullTextSearchParameter) Test(org.junit.Test)

Example 92 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class PropertyTest method getTraversalReturnsATraversalThatOrdersByStringValue.

@Test
public void getTraversalReturnsATraversalThatOrdersByStringValue() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY, "123")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY, "1234")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY, "254")).build().traversal().V();
    Property instance = Property.localProperty().withName(PROPERTY).build();
    GraphTraversal<?, ?> orderTraversal = instance.getTraversal();
    List<Vertex> vertices = traversal.order().by(orderTraversal, Order.incr).toList();
    assertThat(vertices, contains(likeVertex().withTimId("id1"), likeVertex().withTimId("id2"), likeVertex().withTimId("id3")));
}
Also used : PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Property(nl.knaw.huygens.timbuctoo.search.description.Property) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Property(nl.knaw.huygens.timbuctoo.search.description.Property) Test(org.junit.Test)

Example 93 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class Gremlin method evaluateQuery.

private String evaluateQuery(String query) throws ScriptException {
    GraphTraversal traversalResult = (GraphTraversal) engine.eval(query, bindings);
    StringBuilder result = new StringBuilder();
    while (traversalResult.hasNext()) {
        dumpItem(traversalResult.next(), result);
    }
    if (result.length() > 0) {
        return result.toString();
    } else {
        return "No results...";
    }
}
Also used : GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)

Aggregations

GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)93 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)67 Test (org.junit.Test)57 List (java.util.List)51 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)50 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)44 Before (org.junit.Before)42 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)40 Matchers.contains (org.hamcrest.Matchers.contains)39 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)35 Lists (com.google.common.collect.Lists)34 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)31 Optional (java.util.Optional)24 P (org.apache.tinkerpop.gremlin.process.traversal.P)21 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)20 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)19 Matchers.is (org.hamcrest.Matchers.is)17 Mockito.mock (org.mockito.Mockito.mock)17 Matchers.empty (org.hamcrest.Matchers.empty)15 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14