Search in sources :

Example 81 with GraphTraversal

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

the class RelatedMultiValueListFacetDescriptionTest method filterAddsAFilterToTheGraphTraversal.

@Test
public void filterAddsAFilterToTheGraphTraversal() {
    RelatedMultiValueListFacetDescription instance = new RelatedMultiValueListFacetDescription(FACET_NAME, PROPERTY, RELATION);
    List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(FACET_VALUE)));
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)).withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)).withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")).withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")).build().traversal().V();
    instance.filter(traversal, facets);
    List<Vertex> vertices = traversal.toList();
    assertThat(vertices, contains(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) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) ArrayList(java.util.ArrayList) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) 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) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) Test(org.junit.Test)

Example 82 with GraphTraversal

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

the class SortDescriptionTest method sortAddsASortParameterToTheSearchResultsForEachOfTheSortParameters.

@Test
@SuppressWarnings("unchecked")
public void sortAddsASortParameterToTheSearchResultsForEachOfTheSortParameters() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_1, "value1.2").withProperty(PROPERTY_2, "value2")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_1, "value1").withProperty(PROPERTY_2, "value2.1")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_1, "value1").withProperty(PROPERTY_2, "value2")).build().traversal().V();
    List<SortParameter> sortParameters = Lists.newArrayList(new SortParameter(SORT_FIELD_1, asc), new SortParameter(SORT_FIELD_2, 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 83 with GraphTraversal

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

the class SortFieldDescriptionTest method getTraversalReturnsTheTraversalToOrderThePropertyValues.

@Test
public void getTraversalReturnsTheTraversalToOrderThePropertyValues() {
    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, "12")).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 84 with GraphTraversal

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

the class SortFieldDescriptionTest method getTraversalReturnsATraversalWithABackupTraversalWhenConfigured.

@Test
public void getTraversalReturnsATraversalWithABackupTraversalWhenConfigured() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY, "abc")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY, "abcd")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_2, "efgh")).withVertex(v -> v.withTimId("id4").withProperty(PROPERTY_2, "ab")).build().traversal().V();
    SortFieldDescription instance = newSortFieldDescription().withName("name").withDefaultValue("").withProperty(localProperty().withName(PROPERTY)).withBackupProperty(localProperty().withName(PROPERTY_2)).build();
    GraphTraversal<?, ?> orderTraversal = instance.getTraversal().get(0);
    List<Vertex> vertices = traversal.order().by(orderTraversal, Order.incr).toList();
    assertThat(vertices, contains(likeVertex().withTimId("id4"), likeVertex().withTimId("id1"), likeVertex().withTimId("id2"), likeVertex().withTimId("id3")));
}
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 85 with GraphTraversal

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

the class FullTextSearchDescriptionTest method filterFiltersOnEachOfTheTermIndividuallyEachPropertyHasToContainOnlyOne.

@Test
public void filterFiltersOnEachOfTheTermIndividuallyEachPropertyHasToContainOnlyOne() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(vertex -> vertex.withTimId("v1").withProperty(PROPERTY, "value 12344324 value2")).withVertex(vertex -> vertex.withTimId("v2").withProperty(PROPERTY, "value value2")).withVertex(vertex -> vertex.withTimId("v3").withProperty(PROPERTY, "value1 value2")).build().traversal().V();
    FullTextSearchParameter fullTextSearchParameter = new FullTextSearchParameter(NAME, "value value2");
    instance.filter(traversal, fullTextSearchParameter);
    assertThat(traversal.toList(), containsInAnyOrder(likeVertex().withTimId("v1"), likeVertex().withTimId("v2"), 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)

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