use of nl.knaw.huygens.timbuctoo.search.description.facet.Facet in project timbuctoo by HuygensING.
the class ChangeRangeFacetGetter method getFacet.
@Override
public Facet getFacet(String facetName, Map<String, Set<Vertex>> values) {
long lowerLimit = 0;
long upperLimit = 0;
for (String key : values.keySet()) {
try {
LocalDate localDate = getChangeLocalDate(key);
long dateStamp = Long.valueOf(FORMATTER.format(localDate));
if (dateStamp > upperLimit) {
upperLimit = dateStamp;
}
if (lowerLimit == 0 || dateStamp < lowerLimit) {
lowerLimit = dateStamp;
}
} catch (IOException e) {
LOG.error("'{}' is not a valid change.", key);
}
}
return new Facet(facetName, Lists.newArrayList(new Facet.RangeOption(lowerLimit, upperLimit)), "RANGE");
}
use of nl.knaw.huygens.timbuctoo.search.description.facet.Facet in project timbuctoo by HuygensING.
the class DatableRangeFacetGetter method getFacet.
@Override
public Facet getFacet(String facetName, Map<String, Set<Vertex>> values) {
long lowerLimit = 0;
long upperLimit = 0;
for (String key : values.keySet()) {
Datable datable = getDatable(key);
if (datable.isValid()) {
long fromDate = Long.valueOf(FORMAT.format(datable.getFromDate()));
long toDate = Long.valueOf(FORMAT.format(datable.getToDate()));
if (toDate > upperLimit) {
upperLimit = toDate;
}
if (lowerLimit == 0 || fromDate < lowerLimit) {
lowerLimit = fromDate;
}
}
}
return new Facet(facetName, Lists.newArrayList(new Facet.RangeOption(lowerLimit, upperLimit)), "RANGE");
}
use of nl.knaw.huygens.timbuctoo.search.description.facet.Facet in project timbuctoo by HuygensING.
the class ListFacetGetterTest method getFacetReturnsParsedValueKeysAndTheirCounts.
@Test
public void getFacetReturnsParsedValueKeysAndTheirCounts() {
FacetGetter instance = new ListFacetGetter(new PropertyParserFactory().getParser(Gender.class));
Map<String, Set<Vertex>> values = Maps.newHashMap();
List<Vertex> vertices1 = newGraph().withVertex(v -> v.withTimId("1")).withVertex(v -> v.withTimId("2")).build().traversal().V().toList();
List<Vertex> vertices2 = newGraph().withVertex(v -> v.withTimId("3")).build().traversal().V().toList();
values.put("\"MALE\"", Sets.newHashSet(vertices1));
values.put("\"FEMALE\"", Sets.newHashSet(vertices2));
Facet facet = instance.getFacet(FACET_NAME, values);
assertThat(facet.getName(), equalTo(FACET_NAME));
assertThat(facet.getOptions(), containsInAnyOrder(new Facet.DefaultOption("MALE", 2), new Facet.DefaultOption("FEMALE", 1)));
}
Aggregations