From 9f5cc53cf32bcbd59d03e7975bc7ea8008040e98 Mon Sep 17 00:00:00 2001 From: Gethin James Date: Tue, 6 Sep 2016 15:39:32 +0000 Subject: [PATCH] Merged searchapi (5.2.1) to 5.2.N (5.2.1) 130146 gjames: SEARCH-121: Implementing facet fields git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130305 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rest/api/search/impl/SearchMapper.java | 65 +++++++++ .../rest/api/search/model/FacetField.java | 133 ++++++++++++++++++ .../rest/api/search/model/FacetFields.java | 50 +++++++ .../rest/api/search/model/SearchQuery.java | 10 +- .../rest/api/search/SearchMapperTests.java | 79 ++++++++++- .../search/SearchQuerySerializerTests.java | 13 +- .../rest/api/search/SerializerTestHelper.java | 1 + 7 files changed, 348 insertions(+), 3 deletions(-) create mode 100644 source/java/org/alfresco/rest/api/search/model/FacetField.java create mode 100644 source/java/org/alfresco/rest/api/search/model/FacetFields.java diff --git a/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java b/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java index 0fc0a6ab6b..43ed25bb84 100644 --- a/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/SearchMapper.java @@ -28,6 +28,8 @@ package org.alfresco.rest.api.search.impl; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.rest.api.search.model.Default; +import org.alfresco.rest.api.search.model.FacetField; +import org.alfresco.rest.api.search.model.FacetFields; import org.alfresco.rest.api.search.model.FacetQuery; import org.alfresco.rest.api.search.model.FilterQuery; import org.alfresco.rest.api.search.model.Query; @@ -46,6 +48,9 @@ import org.alfresco.service.cmr.search.LimitBy; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.rest.api.model.Node; +import org.alfresco.service.cmr.search.SearchParameters.FieldFacet; +import org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod; +import org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort; import org.alfresco.service.cmr.search.SearchParameters.Operator; import org.alfresco.service.cmr.search.SearchParameters.SortDefinition; import org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType; @@ -104,6 +109,7 @@ public class SearchMapper fromDefault(sp, searchQuery.getDefaults()); fromFilterQuery(sp, searchQuery.getFilterQueries()); fromFacetQuery(sp, searchQuery.getFacetQueries()); + fromFacetFields(sp, searchQuery.getFacetFields()); fromSpellCheck(sp, searchQuery.getSpellcheck()); fromScope(sp, searchQuery.getScope()); @@ -309,6 +315,65 @@ public class SearchMapper } } + + /** + * 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(); + String label = facet.getLabel()!=null?facet.getLabel():field; + field = "{key='"+label+"'}"+field; + + 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.setCountDocsMissingFacetField(facet.getMissing()); + ff.setLimitOrNull(facet.getLimit()); + ff.setOffset(facet.getOffset()); + ff.setMinCount(facet.getMincount()); + ff.setEnumMethodCacheMinDF(facet.getFacetEnumCacheMinDf()); + + sp.addFieldFacet(ff); + } + } + } + } /** * SearchParameters from SpellCheck object * @param sp SearchParameters diff --git a/source/java/org/alfresco/rest/api/search/model/FacetField.java b/source/java/org/alfresco/rest/api/search/model/FacetField.java new file mode 100644 index 0000000000..ad8c14608e --- /dev/null +++ b/source/java/org/alfresco/rest/api/search/model/FacetField.java @@ -0,0 +1,133 @@ +/*- + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.api.search.model; + +import org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod; +import org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort; +import org.codehaus.jackson.annotate.JsonCreator; +import org.codehaus.jackson.annotate.JsonProperty; + +/** + * POJO class representing the FacetField + * + * @author Gethin James + */ +public class FacetField +{ + private final String field; + private final String label; + private final String prefix; + private final String sort; //actually an enum + private final String method; //actually an enum + private final Boolean missing; + private final Integer limit; + private final Integer offset; + private final Integer mincount; + private final Integer facetEnumCacheMinDf; + + @JsonCreator + public FacetField(@JsonProperty("field") String field, + @JsonProperty("label") String label, + @JsonProperty("prefix") String prefix, + @JsonProperty("sort") String sort, + @JsonProperty("method") String method, + @JsonProperty("missing") Boolean missing, + @JsonProperty("limit") Integer limit, + @JsonProperty("offset") Integer offset, + @JsonProperty("mincount") Integer mincount, + @JsonProperty("facetEnumCacheMinDf") Integer facetEnumCacheMinDf) + { + this.field = field; + this.label = label; + this.prefix = prefix; + this.sort = sort; + this.method = method; + this.missing = missing == null?true:missing; //Not set in SolrQueryHTTPClient, bug? + this.limit = limit; //Can be null + this.offset = offset == null?0:offset; + this.mincount = mincount == null?0:mincount; + this.facetEnumCacheMinDf = facetEnumCacheMinDf == null?0:facetEnumCacheMinDf; + } + /** + + "excludeFilters": [ + "string" + ], + + "contains": "string", + "containsIgnoreCase": true, + **/ + + public String getField() + { + return field; + } + + public String getLabel() + { + return label; + } + + public String getPrefix() + { + return prefix; + } + + public String getSort() + { + return sort; + } + + public String getMethod() + { + return method; + } + + public Boolean getMissing() + { + return missing; + } + + public Integer getLimit() + { + return limit; + } + + public Integer getOffset() + { + return offset; + } + + public Integer getMincount() + { + return mincount; + } + + public Integer getFacetEnumCacheMinDf() + { + return facetEnumCacheMinDf; + } +} diff --git a/source/java/org/alfresco/rest/api/search/model/FacetFields.java b/source/java/org/alfresco/rest/api/search/model/FacetFields.java new file mode 100644 index 0000000000..0eac9c2d7e --- /dev/null +++ b/source/java/org/alfresco/rest/api/search/model/FacetFields.java @@ -0,0 +1,50 @@ +/*- + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.api.search.model; + +import org.codehaus.jackson.annotate.JsonCreator; +import org.codehaus.jackson.annotate.JsonProperty; + +import java.util.List; + +/** + * POJO class representing a FacetField + */ +public class FacetFields +{ + private final List facets; + + @JsonCreator + public FacetFields(@JsonProperty("facets") List facets) + { + this.facets = facets; + } + + public List getFacets() + { + return facets; + } +} diff --git a/source/java/org/alfresco/rest/api/search/model/SearchQuery.java b/source/java/org/alfresco/rest/api/search/model/SearchQuery.java index 8e9885064d..fe48d7c64d 100644 --- a/source/java/org/alfresco/rest/api/search/model/SearchQuery.java +++ b/source/java/org/alfresco/rest/api/search/model/SearchQuery.java @@ -48,10 +48,11 @@ public class SearchQuery private final Default defaults; private final List filterQueries; private final List facetQueries; + private final FacetFields facetFields; private final Spelling spellcheck; private final Scope scope; - public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null, null, null); + public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null, null, null, null); @JsonCreator public SearchQuery(@JsonProperty("query") Query query, @@ -61,6 +62,7 @@ public class SearchQuery @JsonProperty("templates") List