Search in sources :

Example 6 with Facet

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");
}
Also used : IOException(java.io.IOException) LocalDate(java.time.LocalDate) Facet(nl.knaw.huygens.timbuctoo.search.description.facet.Facet)

Example 7 with Facet

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");
}
Also used : Datable(nl.knaw.huygens.timbuctoo.model.Datable) Facet(nl.knaw.huygens.timbuctoo.search.description.facet.Facet)

Example 8 with Facet

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)));
}
Also used : FacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.FacetGetter) Set(java.util.Set) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PropertyParserFactory(nl.knaw.huygens.timbuctoo.search.description.propertyparser.PropertyParserFactory) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Map(java.util.Map) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Gender(nl.knaw.huygens.timbuctoo.model.Gender) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Facet(nl.knaw.huygens.timbuctoo.search.description.facet.Facet) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Set(java.util.Set) FacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.FacetGetter) Gender(nl.knaw.huygens.timbuctoo.model.Gender) PropertyParserFactory(nl.knaw.huygens.timbuctoo.search.description.propertyparser.PropertyParserFactory) Facet(nl.knaw.huygens.timbuctoo.search.description.facet.Facet) Test(org.junit.Test)

Aggregations

Facet (nl.knaw.huygens.timbuctoo.search.description.facet.Facet)8 Maps (com.google.common.collect.Maps)6 Sets (com.google.common.collect.Sets)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6 FacetGetter (nl.knaw.huygens.timbuctoo.search.description.facet.FacetGetter)6 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)6 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)6 Matchers.equalTo (org.hamcrest.Matchers.equalTo)6 Test (org.junit.Test)6 LocalDate (java.time.LocalDate)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Instant (java.time.Instant)2 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Change (nl.knaw.huygens.timbuctoo.model.Change)2 Gender (nl.knaw.huygens.timbuctoo.model.Gender)2