Search in sources :

Example 21 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class DatableRangeFacetDescriptionTest method filterAddsAFilterIgnoresLastFourNumbers.

@Test
public void filterAddsAFilterIgnoresLastFourNumbers() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, asSerializedDatable("2015-01-01"))).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, asSerializedDatable("1000-03-02"))).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, asSerializedDatable("2100-03-02"))).build().traversal().V();
    List<FacetValue> facets = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20151001L, 20160101L));
    instance.filter(traversal, facets);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
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 22 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class DatableRangeFacetDescriptionTest method filterIncludesTheVerticesWhereOnlyTheStartFallsInTheRange.

@Test
public void filterIncludesTheVerticesWhereOnlyTheStartFallsInTheRange() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, asSerializedDatable("2015/2020"))).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, 20140101L, 20160101L));
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
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 23 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class DatableRangeFacetDescriptionTest method filterAddsAFilterThatIgnoresInvalidDatables.

@Test
public void filterAddsAFilterThatIgnoresInvalidDatables() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, asSerializedDatable("2015-01-01"))).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, asSerializedDatable("invalidDatable"))).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, asSerializedDatable("2100-03-02"))).build().traversal().V();
    List<FacetValue> facets = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20151001L, 20160101L));
    instance.filter(traversal, facets);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
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 24 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class EdgeListFacetDescriptionTest method filterAddsNoFilterIfTheFacetValuesIsEmpty.

@Test
public void filterAddsNoFilterIfTheFacetValuesIsEmpty() {
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList()));
    SearchRequestV2_1 searchRequest = new SearchRequestV2_1();
    searchRequest.setFacetValues(facetValues);
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("1")).withVertex(v -> v.withTimId("2")).build().traversal().V();
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), containsInAnyOrder(VertexMatcher.likeVertex().withTimId("1"), VertexMatcher.likeVertex().withTimId("2")));
}
Also used : VertexMatcher(nl.knaw.huygens.timbuctoo.util.VertexMatcher) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) 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) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) Test(org.junit.Test)

Example 25 with FacetValue

use of nl.knaw.huygens.timbuctoo.search.FacetValue in project timbuctoo by HuygensING.

the class EdgeListFacetDescriptionTest method filterAddsAFilterToFilterOutTheNonMatchingVertices.

@Test
public void filterAddsAFilterToFilterOutTheNonMatchingVertices() {
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(RELATION_NAME)));
    SearchRequestV2_1 searchRequest = new SearchRequestV2_1();
    searchRequest.setFacetValues(facetValues);
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("1")).withVertex("v2", v -> v.withTimId("2").withOutgoingRelation(RELATION_NAME, "v1")).build().traversal().V();
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), contains(VertexMatcher.likeVertex().withTimId("1")));
}
Also used : VertexMatcher(nl.knaw.huygens.timbuctoo.util.VertexMatcher) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) 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) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) Test(org.junit.Test)

Aggregations

FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)34 List (java.util.List)32 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)31 Lists (com.google.common.collect.Lists)27 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)25 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)25 Test (org.junit.Test)25 Before (org.junit.Before)23 Matchers.contains (org.hamcrest.Matchers.contains)22 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)19 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)18 DateRangeFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue)16 PropertyParser (nl.knaw.huygens.timbuctoo.search.description.PropertyParser)9 Objects (java.util.Objects)7 Optional (java.util.Optional)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 BDDMockito.given (org.mockito.BDDMockito.given)7 Mockito.mock (org.mockito.Mockito.mock)7