use of org.alfresco.rest.api.search.model.FacetField in project alfresco-remote-api by Alfresco.
the class SearchQuerySerializerTests method testDeserializeQuery.
@Test
public void testDeserializeQuery() throws IOException {
SearchQuery searchQuery = helper.searchQueryFromJson();
assertEquals(SearchQuery.class, searchQuery.getClass());
assertEquals("afts", searchQuery.getQuery().getLanguage());
assertEquals("g*", searchQuery.getQuery().getQuery());
assertEquals("great", searchQuery.getQuery().getUserQuery());
assertEquals(99, searchQuery.getPaging().getMaxItems());
assertEquals(4, searchQuery.getPaging().getSkipCount());
assertEquals(2, searchQuery.getInclude().size());
assertTrue(searchQuery.getInclude().contains("aspectNames"));
assertTrue(searchQuery.getInclude().contains("properties"));
assertEquals(1, searchQuery.getSort().size());
assertEquals(2, searchQuery.getTemplates().size());
Default defaults = searchQuery.getDefaults();
assertEquals("namesp", defaults.getNamespace());
assertEquals("myfield", defaults.getDefaultFieldName());
assertEquals("AND", defaults.getDefaultFTSOperator());
assertEquals(2, defaults.getTextAttributes().size());
assertTrue(defaults.getTextAttributes().contains("roy"));
assertTrue(defaults.getTextAttributes().contains("king"));
assertEquals(2, searchQuery.getFilterQueries().size());
assertEquals("myquery", searchQuery.getFilterQueries().get(0).getQuery());
assertEquals(2, searchQuery.getFilterQueries().get(0).getTags().size());
assertEquals("myquery2", searchQuery.getFilterQueries().get(1).getQuery());
assertEquals(1, searchQuery.getFacetQueries().size());
assertEquals("cm:created:bob", searchQuery.getFacetQueries().get(0).getQuery());
assertEquals("small", searchQuery.getFacetQueries().get(0).getLabel());
assertEquals("alfrezco", searchQuery.getSpellcheck().getQuery());
assertEquals(1, searchQuery.getScope().getLocations().size());
assertEquals(StoreMapper.LIVE_NODES, searchQuery.getScope().getLocations().get(0));
assertEquals(3, searchQuery.getFacetFields().getFacets().size());
FacetField ff = searchQuery.getFacetFields().getFacets().get(0);
assertEquals("cm:creator", ff.getField());
assertEquals("myquery2", ff.getPrefix());
assertEquals("COUNT", ff.getSort());
assertEquals(false, ff.getMissing());
ff = searchQuery.getFacetFields().getFacets().get(1);
assertEquals("modifier", ff.getField());
assertEquals("mylabel", ff.getLabel());
assertEquals("FC", ff.getMethod());
assertEquals(Integer.valueOf(5), ff.getMincount());
assertEquals(2000, searchQuery.getLimits().getPermissionEvaluationCount().intValue());
assertEquals(5000, searchQuery.getLimits().getPermissionEvaluationTime().intValue());
assertEquals(2, searchQuery.getFields().size());
assertTrue(searchQuery.getFields().contains("id"));
assertTrue(searchQuery.getFields().contains("name"));
// Highlight
assertEquals("]", searchQuery.getHighlight().getPostfix());
assertEquals("[", searchQuery.getHighlight().getPrefix());
assertEquals(20, searchQuery.getHighlight().getSnippetCount().intValue());
assertEquals(10, searchQuery.getHighlight().getFragmentSize().intValue());
assertEquals(true, searchQuery.getHighlight().getMergeContiguous());
assertEquals(40, searchQuery.getHighlight().getMaxAnalyzedChars().intValue());
assertEquals(true, searchQuery.getHighlight().getUsePhraseHighlighter());
assertEquals(2, searchQuery.getHighlight().getFields().size());
FieldHighlightParameters high1 = searchQuery.getHighlight().getFields().get(0);
assertEquals("my", high1.getField());
assertEquals("ยก", high1.getPostfix());
assertEquals("?", high1.getPrefix());
assertEquals(23, high1.getSnippetCount().intValue());
assertEquals(5, high1.getFragmentSize().intValue());
assertEquals(true, high1.getMergeContiguous());
FieldHighlightParameters high2 = searchQuery.getHighlight().getFields().get(1);
assertEquals("your", high2.getField());
assertEquals(")", high2.getPostfix());
assertEquals("(", high2.getPrefix());
assertEquals(3, high2.getSnippetCount().intValue());
assertEquals(15, high2.getFragmentSize().intValue());
assertEquals(false, high2.getMergeContiguous());
// Facet intervals
IntervalParameters ip = searchQuery.getFacetIntervals();
assertNotNull(ip);
assertEquals(1, ip.getSets().size());
IntervalSet expected = new IntervalSet("1", "2", "king", true, false);
assertTrue(ip.getSets().contains(expected));
assertEquals(2, ip.getIntervals().size());
Interval interval = ip.getIntervals().get(0);
assertEquals("creator", interval.getLabel());
assertEquals("cm:creator", interval.getField());
expected = new IntervalSet("a", "b", "last", false, true);
assertTrue(interval.getSets().contains(expected));
assertEquals(1, searchQuery.getPivots().size());
assertEquals("mylabel", searchQuery.getPivots().get(0).getKey());
assertEquals(1, searchQuery.getStats().size());
assertEquals("cm:creator", searchQuery.getStats().get(0).getField());
assertEquals("mylabel", searchQuery.getStats().get(0).getLabel());
// Range Facet
List<RangeParameters> ranges = searchQuery.getFacetRanges();
assertNotNull(ranges);
}
use of org.alfresco.rest.api.search.model.FacetField in project alfresco-remote-api by Alfresco.
the class ResultMapper method getFacetBucketsForFacetFieldsAsFacets.
protected List<GenericFacetResponse> getFacetBucketsForFacetFieldsAsFacets(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
if (facetFields != null && !facetFields.isEmpty()) {
List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
if (facet.getValue() != null && !facet.getValue().isEmpty()) {
List<GenericBucket> buckets = new ArrayList<>(facet.getValue().size());
for (Pair<String, Integer> buck : facet.getValue()) {
Object display = null;
String filterQuery = null;
if (searchQuery != null && searchQuery.getFacetFields() != null && searchQuery.getFacetFields().getFacets() != null && !searchQuery.getFacetFields().getFacets().isEmpty()) {
Optional<FacetField> found = searchQuery.getFacetFields().getFacets().stream().filter(queryable -> facet.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();
if (found.isPresent()) {
display = propertyLookup.lookup(found.get().getField(), buck.getFirst());
String fq = found.get().toFilterQuery(buck.getFirst());
if (fq != null) {
filterQuery = fq;
}
}
}
GenericBucket bucket = new GenericBucket(buck.getFirst(), filterQuery, display, new HashSet<Metric>(Arrays.asList(new SimpleMetric(METRIC_TYPE.count, String.valueOf(buck.getSecond())))), null, null);
buckets.add(bucket);
}
ffcs.add(new GenericFacetResponse(FACET_TYPE.field, facet.getKey(), buckets));
}
}
return ffcs;
}
return Collections.emptyList();
}
use of org.alfresco.rest.api.search.model.FacetField in project alfresco-remote-api by Alfresco.
the class SearchMapper method fromFacetFields.
/**
* SearchParameters from FacetFields object
* @param sp SearchParameters
* @param FacetFields facetFields
*/
public void fromFacetFields(SearchParameters sp, FacetFields facetFields) {
if (facetFields != null) {
ParameterCheck.mandatory("facetFields facets", facetFields.getFacets());
if (facetFields.getFacets() != null && !facetFields.getFacets().isEmpty()) {
for (FacetField facet : facetFields.getFacets()) {
ParameterCheck.mandatoryString("facetFields facet field", facet.getField());
String field = facet.getField();
FieldFacet ff = new FieldFacet(field);
if (facet.getSort() != null && !facet.getSort().isEmpty()) {
try {
ff.setSort(FieldFacetSort.valueOf(facet.getSort()));
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { facet.getSort() });
}
}
if (facet.getMethod() != null && !facet.getMethod().isEmpty()) {
try {
ff.setMethod(FieldFacetMethod.valueOf(facet.getMethod()));
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { facet.getMethod() });
}
}
ff.setPrefix(facet.getPrefix());
ff.setLabel(facet.getLabel());
ff.setExcludeFilters(facet.getExcludeFilters());
ff.setCountDocsMissingFacetField(facet.getMissing());
ff.setLimitOrNull(facet.getLimit());
ff.setOffset(facet.getOffset());
ff.setMinCount(facet.getMincount());
ff.setEnumMethodCacheMinDF(facet.getFacetEnumCacheMinDf());
sp.addFieldFacet(ff);
}
}
}
}
use of org.alfresco.rest.api.search.model.FacetField in project alfresco-remote-api by Alfresco.
the class ResultMapper method getFacetBucketsForFacetFields.
protected List<FacetFieldContext> getFacetBucketsForFacetFields(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
if (facetFields != null && !facetFields.isEmpty()) {
List<FacetFieldContext> ffcs = new ArrayList<>(facetFields.size());
for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
if (facet.getValue() != null && !facet.getValue().isEmpty()) {
List<Bucket> buckets = new ArrayList<>(facet.getValue().size());
for (Pair<String, Integer> buck : facet.getValue()) {
Object display = null;
String filterQuery = null;
if (searchQuery != null && searchQuery.getFacetFields() != null && searchQuery.getFacetFields().getFacets() != null && !searchQuery.getFacetFields().getFacets().isEmpty()) {
Optional<FacetField> found = searchQuery.getFacetFields().getFacets().stream().filter(queryable -> facet.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();
if (found.isPresent()) {
display = propertyLookup.lookup(found.get().getField(), buck.getFirst());
String fq = found.get().toFilterQuery(buck.getFirst());
if (fq != null) {
filterQuery = fq;
}
}
}
buckets.add(new Bucket(buck.getFirst(), filterQuery, buck.getSecond(), display));
}
ffcs.add(new FacetFieldContext(facet.getKey(), buckets));
}
}
return ffcs;
}
return Collections.emptyList();
}
use of org.alfresco.rest.api.search.model.FacetField in project alfresco-remote-api by Alfresco.
the class SearchMapper method buildPivotKeys.
protected void buildPivotKeys(List<String> pivotKeys, Pivot aPivot, List<StatsRequestParameters> stats, FacetFields facetFields, List<RangeParameters> ranges, SearchRequestContext searchRequestContext) {
if (aPivot == null)
return;
String pivotKey = null;
ParameterCheck.mandatoryString("pivot key", aPivot.getKey());
if (facetFields.getFacets() != null && !facetFields.getFacets().isEmpty()) {
Optional<FacetField> found = facetFields.getFacets().stream().filter(queryable -> aPivot.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();
if (found.isPresent()) {
pivotKey = aPivot.getKey();
if (searchRequestContext.getPivotKeys().containsValue(pivotKey)) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Duplicate pivot parameter " + aPivot.getKey() + "" });
}
pivotKeys.add(found.get().getField());
facetFields.getFacets().remove(found.get());
searchRequestContext.getPivotKeys().put(found.get().getField(), pivotKey);
}
}
if (pivotKey == null && ((aPivot.getPivots() == null) || aPivot.getPivots().isEmpty())) {
// It is the last one so it can reference stats or range
if (stats != null && !stats.isEmpty()) {
Optional<StatsRequestParameters> foundStat = stats.stream().filter(stas -> aPivot.getKey().equals(stas.getLabel() != null ? stas.getLabel() : stas.getField())).findFirst();
if (foundStat.isPresent()) {
pivotKey = aPivot.getKey();
if (pivotKeys.isEmpty()) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Stats key " + pivotKey + " cannot be used here" });
}
pivotKeys.add(pivotKey);
searchRequestContext.getPivotKeys().put(pivotKey, pivotKey);
}
}
if (ranges != null && !ranges.isEmpty()) {
for (RangeParameters aRange : ranges) {
if (aPivot.getKey().equals(aRange.getLabel())) {
pivotKey = aPivot.getKey();
if (pivotKeys.isEmpty()) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Range key " + pivotKey + " cannot be used here" });
}
pivotKeys.add(pivotKey);
searchRequestContext.getPivotKeys().put(pivotKey, pivotKey);
}
}
}
}
if (pivotKey == null) {
String invalidMessage = searchRequestContext.getPivotKeys().values().contains(aPivot.getKey()) ? " cannot be used more than once." : " does not reference a facet Field, range or stats.";
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Pivot parameter " + aPivot.getKey() + invalidMessage });
}
if (aPivot.getPivots() != null && !aPivot.getPivots().isEmpty() && aPivot.getPivots().size() > 1) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Currently only 1 nested pivot is supported, you have " + aPivot.getPivots().size() });
}
aPivot.getPivots().forEach(subPivot -> {
buildPivotKeys(pivotKeys, subPivot, stats, facetFields, ranges, searchRequestContext);
});
}
Aggregations