[
https://issues.apache.org/jira/browse/OAK-3847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15098365#comment-15098365
]
Tommaso Teofili commented on OAK-3847:
--------------------------------------
here's the proposal for the {{FacetResult}} API:
{code}
/**
* A facet result is a wrapper for {@link javax.jcr.query.QueryResult} capable
of returning information about facets
* stored in the query result {@link javax.jcr.query.Row}s.
*/
public class FacetResult {
private final Map<String, List<Facet>> facets = new HashMap<String,
List<Facet>>();
public FacetResult(QueryResult queryResult) {
try {
RowIterator rows = queryResult.getRows();
if (rows.hasNext()) {
Row row = rows.nextRow();
for (String column : queryResult.getColumnNames()) {
if (column.startsWith(QueryImpl.REP_FACET)) {
String dimension =
column.substring(QueryImpl.REP_FACET.length() + 1, column.length() - 1);
String jsonFacetString =
row.getValue(column).getString();
// parse ...
facets.put(dimension, new Facet(...));
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Nonnull
public Set<String> getDimensions() {
return facets.keySet();
}
@CheckForNull
public List<Facet> getFacets(@Nonnull String dimension) {
return facets.get(dimension);
}
public static class Facet {
private final String label;
private final Integer count;
private Facet(String label, Integer count) {
this.label = label;
this.count = count;
}
@Nonnull
public String getLabel() {
return label;
}
@Nonnull
public Integer getCount() {
return count;
}
}
}
{code}
> Provide an easy way to parse/retrieve facets
> --------------------------------------------
>
> Key: OAK-3847
> URL: https://issues.apache.org/jira/browse/OAK-3847
> Project: Jackrabbit Oak
> Issue Type: Improvement
> Components: lucene, solr
> Reporter: Tommaso Teofili
> Assignee: Tommaso Teofili
> Fix For: 1.3.14
>
>
> Current facet results are returned within the rep:facet($propertyname)
> property of each resulting node. The resulting String [1] is however a bit
> annoying to parse as it separates label / value by comma so that if label
> contains a similar pattern parsing may even be buggy.
> An easier format for facets should be used, eventually together with an
> utility class that returns proper objects that client code can consume.
> [1] :
> https://github.com/apache/jackrabbit-oak/blob/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/FacetTest.java#L99
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)