@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"))); }
@Override @SuppressWarnings("unchecked") public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { final Optional<DateRangeFacetValue> facet = FacetParsingHelp.getValue(facetName, facets); if (!facet.isPresent()) { return; } String lowerLimitString = facet.get().getLowerLimit() + ""; String upperLimitString = facet.get().getUpperLimit() + ""; try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } }
DatableRangeFacetDescription extends AbstractFacetDescription { @Override @SuppressWarnings("unchecked") public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { final Optional<DateRangeFacetValue> facet = FacetParsingHelp.getValue(facetName, facets); if (!facet.isPresent()) { return; } String lowerLimitString = facet.get().getLowerLimit() + ""; String upperLimitString = facet.get().getUpperLimit() + ""; try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } }
DatableRangeFacetDescription extends AbstractFacetDescription { @Override @SuppressWarnings("unchecked") public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { final Optional<DateRangeFacetValue> facet = FacetParsingHelp.getValue(facetName, facets); if (!facet.isPresent()) { return; } String lowerLimitString = facet.get().getLowerLimit() + ""; String upperLimitString = facet.get().getUpperLimit() + ""; try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } DatableRangeFacetDescription(String facetName, String propertyName); }
DatableRangeFacetDescription extends AbstractFacetDescription { @Override @SuppressWarnings("unchecked") public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { final Optional<DateRangeFacetValue> facet = FacetParsingHelp.getValue(facetName, facets); if (!facet.isPresent()) { return; } String lowerLimitString = facet.get().getLowerLimit() + ""; String upperLimitString = facet.get().getUpperLimit() + ""; try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } DatableRangeFacetDescription(String facetName, String propertyName); @Override @SuppressWarnings("unchecked") void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); }
DatableRangeFacetDescription extends AbstractFacetDescription { @Override @SuppressWarnings("unchecked") public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) { final Optional<DateRangeFacetValue> facet = FacetParsingHelp.getValue(facetName, facets); if (!facet.isPresent()) { return; } String lowerLimitString = facet.get().getLowerLimit() + ""; String upperLimitString = facet.get().getUpperLimit() + ""; try { Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString)); graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> { Datable datable = getDatable("" + o1); if (!datable.isValid()) { return false; } Range<Date> range1 = (Range<Date>) o2; return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate()); }, range))); } catch (ParseException e) { LOG.error("Cannot parse date", e); } } DatableRangeFacetDescription(String facetName, String propertyName); @Override @SuppressWarnings("unchecked") void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets); static final SimpleDateFormat FILTER_FORMAT; static final Logger LOG; }