Merged searchbcr (5.2.1) to 5.2.N (5.2.1)

136071 gjames: SEARCH-334: Adding pivot to the request


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@136101 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2017-03-24 13:18:28 +00:00
parent 7369c04df6
commit 719f6637be
4 changed files with 159 additions and 7 deletions

View File

@@ -28,12 +28,14 @@ package org.alfresco.rest.api.search.impl;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.search.impl.lucene.LuceneQueryLanguageSPI;
import org.alfresco.rest.api.search.context.SearchRequestContext;
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.Limits;
import org.alfresco.rest.api.search.model.Pivot;
import org.alfresco.rest.api.search.model.Query;
import org.alfresco.rest.api.search.model.Scope;
import org.alfresco.rest.api.search.model.SearchQuery;
@@ -68,8 +70,8 @@ import static org.alfresco.service.cmr.search.SearchService.*;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Maps from a json request and a solr SearchParameters object.
@@ -93,7 +95,7 @@ public class SearchMapper
* @param params
* @return SearchParameters
*/
public SearchParameters toSearchParameters(Params params, SearchQuery searchQuery)
public SearchParameters toSearchParameters(Params params, SearchQuery searchQuery, SearchRequestContext searchRequestContext)
{
ParameterCheck.mandatory("query", searchQuery.getQuery());
@@ -108,6 +110,7 @@ public class SearchMapper
fromDefault(sp, searchQuery.getDefaults());
fromFilterQuery(sp, searchQuery.getFilterQueries());
fromFacetQuery(sp, searchQuery.getFacetQueries());
fromPivot(sp, searchQuery.getFacetFields(), searchQuery.getPivots(), searchRequestContext);
fromFacetFields(sp, searchQuery.getFacetFields());
fromSpellCheck(sp, searchQuery.getSpellcheck());
fromHighlight(sp, searchQuery.getHighlight());
@@ -409,6 +412,7 @@ public class SearchMapper
}
}
}
/**
* SearchParameters from SpellCheck object
* @param sp SearchParameters
@@ -504,6 +508,38 @@ public class SearchMapper
sp.setInterval(facetIntervals);
}
public void fromPivot(SearchParameters sp, FacetFields facetFields, List<Pivot> pivots, SearchRequestContext searchRequestContext)
{
if (facetFields != null && pivots != null && !pivots.isEmpty())
{
ParameterCheck.mandatory("facetFields facets", facetFields.getFacets());
if (facetFields.getFacets() != null && !facetFields.getFacets().isEmpty())
{
for (Pivot pivot:pivots)
{
ParameterCheck.mandatoryString("pivot key", pivot.getKey());
String pivotKey = pivot.getKey();
Optional<FacetField> found = facetFields.getFacets().stream().filter(
queryable -> pivotKey.equals(queryable.getLabel()!=null?queryable.getLabel():queryable.getField())).findFirst();
if (found.isPresent())
{
sp.addPivot(found.get().getField());
facetFields.getFacets().remove(found.get());
searchRequestContext.getPivotKeys().put(found.get().getField(), pivotKey);
}
else
{
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
new Object[] { ": Pivot parameter "+pivotKey+" is does not reference a facet Field." });
}
}
}
}
}
protected void validateSets(List<IntervalSet> intervalSets, String prefix)
{
if (intervalSets != null && !intervalSets.isEmpty())

View File

@@ -0,0 +1,48 @@
/*-
* #%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;
/**
* POJO class representing Pivot
*/
public class Pivot
{
private final String key;
@JsonCreator
public Pivot(@JsonProperty("key") String key)
{
this.key = key;
}
public String getKey()
{
return key;
}
}