Search in sources :

Example 16 with GraphTraversal

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

the class SortDescriptionTest method sortAddsASortParametersThatSortsTheVertices.

@Test
@SuppressWarnings("unchecked")
public void sortAddsASortParametersThatSortsTheVertices() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_1, "value1.2")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_1, "value1.1")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_1, "value1")).build().traversal().V();
    List<SortParameter> sortParameters = Lists.newArrayList(new SortParameter(SORT_FIELD_1, asc));
    instance.sort(traversal, sortParameters);
    List<Vertex> actual = traversal.toList();
    assertThat(actual, contains(likeVertex().withTimId("id3"), likeVertex().withTimId("id2"), likeVertex().withTimId("id1")));
}
Also used : Test(org.junit.Test) BuildableSortFieldDescription.newSortFieldDescription(nl.knaw.huygens.timbuctoo.search.description.sort.BuildableSortFieldDescription.newSortFieldDescription) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Direction.asc(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter.Direction.asc) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) List(java.util.List) Property.localProperty(nl.knaw.huygens.timbuctoo.search.description.Property.localProperty) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) Test(org.junit.Test)

Example 17 with GraphTraversal

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

the class SortFieldDescriptionTest method getTraversalAddsATraversalWithADefaultValueForTheVerticesWithoutTheProperty.

@Test
public void getTraversalAddsATraversalWithADefaultValueForTheVerticesWithoutTheProperty() {
    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")).build().traversal().V();
    SortFieldDescription instance = newSortFieldDescription().withName("name").withDefaultValue("").withProperty(localProperty().withName(PROPERTY)).build();
    GraphTraversal<?, ?> orderTraversal = instance.getTraversal().get(0);
    List<Vertex> vertices = traversal.order().by(orderTraversal, Order.incr).toList();
    assertThat(vertices, contains(likeVertex().withTimId("id3"), likeVertex().withTimId("id1"), likeVertex().withTimId("id2")));
}
Also used : List(java.util.List) Property.localProperty(nl.knaw.huygens.timbuctoo.search.description.Property.localProperty) Matchers.contains(org.hamcrest.Matchers.contains) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Test(org.junit.Test) BuildableSortFieldDescription.newSortFieldDescription(nl.knaw.huygens.timbuctoo.search.description.sort.BuildableSortFieldDescription.newSortFieldDescription) 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) BuildableSortFieldDescription.newSortFieldDescription(nl.knaw.huygens.timbuctoo.search.description.sort.BuildableSortFieldDescription.newSortFieldDescription) Test(org.junit.Test)

Example 18 with GraphTraversal

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

the class DatableRangeFacetDescriptionTest method filterAddFiltersTheVertices.

@Test
public void filterAddFiltersTheVertices() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, asSerializedDatable("2015-01"))).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, asSerializedDatable("0015-01"))).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, asSerializedDatable("0190-01"))).build().traversal().V();
    List<FacetValue> facetValues = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 101101L, 10001231L));
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), containsInAnyOrder(likeVertex().withTimId("id2"), likeVertex().withTimId("id3")));
}
Also used : Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) 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) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Test(org.junit.Test)

Example 19 with GraphTraversal

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

the class FullTextSearchDescriptionTest method filterFiltersTheVerticesOnTheValueOfTheProperty.

@Test
public void filterFiltersTheVerticesOnTheValueOfTheProperty() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(vertex -> vertex.withTimId("v1").withProperty(PROPERTY, "value1")).withVertex(vertex -> vertex.withTimId("v2").withProperty(PROPERTY, "number2")).withVertex(vertex -> vertex.withTimId("v3").withProperty(PROPERTY, "value1")).build().traversal().V();
    FullTextSearchParameter searchParameter = new FullTextSearchParameter(NAME, "value1");
    instance.filter(traversal, searchParameter);
    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 20 with GraphTraversal

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

the class FullTextSearchDescriptionTest method filterFiltersAllTheVerticesFromTheTraversalWhenNoneMatch.

@Test
public void filterFiltersAllTheVerticesFromTheTraversalWhenNoneMatch() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(vertex -> vertex.withTimId("v1").withProperty(PROPERTY, "value1")).withVertex(vertex -> vertex.withTimId("v2").withProperty(PROPERTY, "value2")).withVertex(vertex -> vertex.withTimId("v3").withProperty(PROPERTY, "value").withProperty(BACKUP_PROPERTY, "value1")).build().traversal().V();
    FullTextSearchParameter fullTextSearchParameter = new FullTextSearchParameter(NAME, "Not matching");
    FullTextSearchDescription instance = createLocalFullTextSearchDescriptionWithBackupProperty(NAME, PROPERTY, BACKUP_PROPERTY);
    instance.filter(traversal, fullTextSearchParameter);
    assertThat(traversal.toList(), is(empty()));
}
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) FullTextSearchDescription.createLocalSimpleFullTextSearchDescription(nl.knaw.huygens.timbuctoo.search.description.fulltext.FullTextSearchDescription.createLocalSimpleFullTextSearchDescription) FullTextSearchParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.FullTextSearchParameter) Test(org.junit.Test)

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