Search in sources :

Example 6 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class MultiValueListFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facetValues) {
    Optional<FacetValue> first = facetValues.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof ListFacetValue)) {
        return;
    }
    List<String> values = ((ListFacetValue) facetValue).getValues();
    if (values.isEmpty()) {
        return;
    }
    graphTraversal.where(__.<String>has(propertyName, P.test((o1, o2) -> o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(value -> ((String) o1).contains("\"" + value + "\"")), values)));
}
Also used : Objects(java.util.Objects) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) MultiValuePropertyGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.MultiValuePropertyGetter) Optional(java.util.Optional) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) 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) P(org.apache.tinkerpop.gremlin.process.traversal.P) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) List(java.util.List)

Example 7 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class AltNameFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facetValues) {
    Optional<FacetValue> first = facetValues.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof ListFacetValue)) {
        return;
    }
    List<String> values = ((ListFacetValue) facetValue).getValues();
    if (values.isEmpty()) {
        return;
    }
    graphTraversal.where(__.<String>has(propertyName, P.test((o1, o2) -> o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(value -> ((String) o1).contains("\"" + value + "\"")), values)));
}
Also used : Logger(org.slf4j.Logger) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IOException(java.io.IOException) 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) Objects(java.util.Objects) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) Optional(java.util.Optional) P(org.apache.tinkerpop.gremlin.process.traversal.P) 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) List(java.util.List)

Example 8 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class DerivedListFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof ListFacetValue)) {
        return;
    }
    List<String> values = ((ListFacetValue) facetValue).getValues();
    if (values.isEmpty()) {
        return;
    }
    graphTraversal.where(__.bothE(relations).otherV().bothE(relationNames).otherV().values(propertyName).map(value -> parser.parse((String) value.get())).is(within(values)));
}
Also used : Objects(java.util.Objects) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) Optional(java.util.Optional) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DerivedPropertyValueGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.DerivedPropertyValueGetter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) 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) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)

Example 9 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class CharterPortaalFondsFacetDescriptionTest method filterChecksIfTheVertexContainsTheRightFondsAndFondsNaam.

@Test
public void filterChecksIfTheVertexContainsTheRightFondsAndFondsNaam() {
    // fonds is unique, but two fondsen could have the same name.
    Graph graph = newGraph().withVertex(v -> v.withTimId("id1").withProperty(FONDS, "fonds").withProperty(FONDS_NAAM, "fondsNaam")).withVertex(v -> v.withProperty(FONDS, "fonds1").withProperty(FONDS_NAAM, "fondsNaam")).build();
    CharterPortaalFondsFacetDescription instance = new CharterPortaalFondsFacetDescription(FACET_NAME, Mockito.mock(PropertyParser.class));
    GraphTraversal<Vertex, Vertex> traversal = graph.traversal().V();
    instance.filter(traversal, Lists.newArrayList(new ListFacetValue("facetName", Lists.newArrayList("fondsNaam (fonds)"))));
    List<Vertex> actual = traversal.toList();
    assertThat(actual, contains(likeVertex().withTimId("id1")));
}
Also used : FONDS_NAAM(nl.knaw.huygens.timbuctoo.search.description.facet.CharterPortaalFondsFacetDescription.FONDS_NAAM) MockVertexBuilder.vertex(nl.knaw.huygens.timbuctoo.search.MockVertexBuilder.vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) 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) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) Mockito(org.mockito.Mockito) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) FONDS(nl.knaw.huygens.timbuctoo.search.description.facet.CharterPortaalFondsFacetDescription.FONDS) 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) Graph(org.apache.tinkerpop.gremlin.structure.Graph) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) Test(org.junit.Test)

Example 10 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue 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)

Aggregations

List (java.util.List)18 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)18 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)18 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)17 Lists (com.google.common.collect.Lists)16 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)14 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)14 Test (org.junit.Test)14 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)13 Matchers.contains (org.hamcrest.Matchers.contains)11 Before (org.junit.Before)11 PropertyParser (nl.knaw.huygens.timbuctoo.search.description.PropertyParser)9 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BDDMockito.given (org.mockito.BDDMockito.given)6 Mockito.mock (org.mockito.Mockito.mock)6 Mockito.verify (org.mockito.Mockito.verify)6 ArrayList (java.util.ArrayList)5 SearchRequestV2_1 (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1)5