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
This commit is contained in:
Gethin James
2016-09-06 15:39:32 +00:00
parent 7bb1ba047a
commit 9f5cc53cf3
7 changed files with 348 additions and 3 deletions

View File

@@ -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

View File

@@ -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 <http://www.gnu.org/licenses/>.
* #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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
* #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<FacetField> facets;
@JsonCreator
public FacetFields(@JsonProperty("facets") List<FacetField> facets)
{
this.facets = facets;
}
public List<FacetField> getFacets()
{
return facets;
}
}

View File

@@ -48,10 +48,11 @@ public class SearchQuery
private final Default defaults;
private final List<FilterQuery> filterQueries;
private final List<FacetQuery> 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<Template> templates,
@JsonProperty("defaults") Default defaults,
@JsonProperty("filterQueries") List<FilterQuery> filterQueries,
@JsonProperty("facetFields") FacetFields facetFields,
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
@JsonProperty("spellcheck") Spelling spellcheck,
@JsonProperty("scope") Scope scope)
@@ -75,6 +77,7 @@ public class SearchQuery
this.facetQueries = facetQueries;
this.spellcheck = spellcheck;
this.scope = scope;
this.facetFields = facetFields;
}
public Query getQuery()
@@ -124,4 +127,9 @@ public class SearchQuery
{
return scope;
}
public FacetFields getFacetFields()
{
return facetFields;
}
}