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)));
}
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)));
}
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)));
}
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")));
}
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")));
}
Aggregations