mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged searchrep (5.2.1) to 5.2.N (5.2.1)
136989 gjames: SEARCH-430: Combining pivot with range git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137080 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -53,16 +53,6 @@ public class SearchRequestContext
|
||||
this.includeRequest = includeRequest;
|
||||
this.pivotKeys = new HashMap<>();
|
||||
this.stores = new HashSet<>();
|
||||
|
||||
/**
|
||||
this.facetQueries = facetQueries!=null?Collections.unmodifiableList(facetQueries): Collections.emptyList();
|
||||
this.facetFields = new FacetFields(facetFields!=null?Collections.unmodifiableList(facetFields.getFacets()):Collections.emptyList());
|
||||
this.facetIntervals = facetIntervals!=null?
|
||||
new IntervalParameters(Collections.unmodifiableList(facetIntervals.getSets()),
|
||||
Collections.unmodifiableList(facetIntervals.getIntervals()))
|
||||
:
|
||||
new IntervalParameters(Collections.emptyList(),Collections.emptyList());
|
||||
this.pivots = pivots!=null?Collections.unmodifiableList(pivots): Collections.emptyList();**/
|
||||
}
|
||||
|
||||
public static final SearchRequestContext from(SearchQuery searchQuery)
|
||||
|
@@ -1,133 +0,0 @@
|
||||
/*-
|
||||
* #%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.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.service.cmr.search.RangeParameters;
|
||||
|
||||
/**Helper to map range results.
|
||||
*
|
||||
* @author Michael Suzuki
|
||||
*/
|
||||
public class RangeResultMapper
|
||||
{
|
||||
/**
|
||||
* Transforms the facet range response into generic facet response.
|
||||
* @param facetFields
|
||||
* @param searchQuery
|
||||
* @return GenericFacetResponse
|
||||
*/
|
||||
public static List<GenericFacetResponse> getGenericFacetsForRanges( Map<String,List<Map<String,String>>> facetFields, SearchQuery searchQuery)
|
||||
{
|
||||
List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
|
||||
if (facetFields != null && !facetFields.isEmpty() && searchQuery.getQuery() != null)
|
||||
{
|
||||
for (Entry<String, List<Map<String, String>>> facet : facetFields.entrySet())
|
||||
{
|
||||
List<GenericBucket> buckets = new ArrayList<>();
|
||||
facet.getValue().forEach(action -> buckets.add(buildGenericBucketFromRange(facet.getKey(),
|
||||
(Map<String, String>) action,
|
||||
searchQuery.getFacetRanges())));
|
||||
ffcs.add(new GenericFacetResponse(FACET_TYPE.range, facet.getKey(), buckets));
|
||||
}
|
||||
}
|
||||
return ffcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the generic facet response out of range results.
|
||||
* @param facetField
|
||||
* @param facet
|
||||
* @return
|
||||
*/
|
||||
private static GenericBucket buildGenericBucketFromRange(String facetField, Map<String,String> facet, List<RangeParameters> ranges)
|
||||
{
|
||||
String start = facet.get(GenericFacetResponse.START);
|
||||
String end = facet.get(GenericFacetResponse.END);
|
||||
boolean startInclusive = true;
|
||||
boolean endInclusive = false;
|
||||
|
||||
for(RangeParameters range : ranges)
|
||||
{
|
||||
if(range.getField().equalsIgnoreCase(facetField))
|
||||
{
|
||||
List<String> includes = range.getInclude();
|
||||
if(includes != null && !includes.isEmpty())
|
||||
{
|
||||
startInclusive = range.isRangeStartInclusive();
|
||||
endInclusive = range.isRangeEndInclusive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
facet.put(GenericFacetResponse.START_INC.toString(), Boolean.toString(startInclusive));
|
||||
facet.put(GenericFacetResponse.END_INC.toString(), Boolean.toString(endInclusive));
|
||||
|
||||
facet.remove(GenericFacetResponse.LABEL);
|
||||
StringBuilder filterQ = new StringBuilder();
|
||||
filterQ.append(facetField).append(":")
|
||||
.append(startInclusive ? "[" :"<")
|
||||
.append(start).append(" TO ")
|
||||
.append(end)
|
||||
.append(endInclusive ? "]" :">");
|
||||
|
||||
Set<Metric> metrics = new HashSet<Metric>(
|
||||
Arrays.asList(new SimpleMetric(
|
||||
METRIC_TYPE.count,facet.get(
|
||||
GenericFacetResponse.COUNT))));
|
||||
facet.remove("count");
|
||||
|
||||
StringBuilder label = new StringBuilder();
|
||||
label.append(startInclusive ? "[" :"(")
|
||||
.append(start)
|
||||
.append(" - ")
|
||||
.append(end)
|
||||
.append(endInclusive ? "]" :")");
|
||||
|
||||
return new GenericBucket(label.toString(),
|
||||
filterQ.toString(),
|
||||
null,
|
||||
metrics,
|
||||
null,
|
||||
facet);
|
||||
|
||||
}
|
||||
}
|
@@ -50,6 +50,7 @@ import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetRespo
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.RangeResultMapper;
|
||||
import org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
|
||||
import org.alfresco.repo.version.Version2Model;
|
||||
@@ -340,7 +341,7 @@ public class ResultMapper
|
||||
facets.addAll(getGenericFacetsForIntervals(facetInterval, searchQuery));
|
||||
|
||||
Map<String,List<Map<String,String>>> facetRanges = solrResultSet.getFacetRanges();
|
||||
facets.addAll(RangeResultMapper.getGenericFacetsForRanges(facetRanges, searchQuery));
|
||||
facets.addAll(RangeResultMapper.getGenericFacetsForRanges(facetRanges, searchQuery.getFacetRanges()));
|
||||
|
||||
List<GenericFacetResponse> stats = getFieldStats(searchRequestContext, solrResultSet.getStats());
|
||||
List<GenericFacetResponse> pimped = getPivots(searchRequestContext, solrResultSet.getPivotFacets(), stats);
|
||||
|
@@ -78,9 +78,7 @@ import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Locale.Builder;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -126,7 +124,7 @@ public class SearchMapper
|
||||
fromDefault(sp, searchQuery.getDefaults());
|
||||
fromFilterQuery(sp, searchQuery.getFilterQueries());
|
||||
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
||||
fromPivot(sp, searchQuery.getStats(), searchQuery.getFacetFields(), searchQuery.getPivots(), searchRequestContext);
|
||||
fromPivot(sp, searchQuery.getStats(), searchQuery.getFacetFields(), searchQuery.getFacetRanges(), searchQuery.getPivots(), searchRequestContext);
|
||||
fromStats(sp, searchQuery.getStats());
|
||||
fromFacetFields(sp, searchQuery.getFacetFields());
|
||||
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
||||
@@ -576,20 +574,22 @@ public class SearchMapper
|
||||
|
||||
}
|
||||
|
||||
public void fromPivot(SearchParameters sp, List<StatsRequestParameters> stats, FacetFields facetFields, List<Pivot> multiplePivots, SearchRequestContext searchRequestContext)
|
||||
public void fromPivot(SearchParameters sp, List<StatsRequestParameters> stats, FacetFields facetFields, List<RangeParameters> ranges, List<Pivot> multiplePivots,
|
||||
SearchRequestContext searchRequestContext)
|
||||
{
|
||||
if (multiplePivots != null && !multiplePivots.isEmpty())
|
||||
{
|
||||
multiplePivots.forEach(aPivot -> {
|
||||
List<String> pivotKeys = new ArrayList<>();
|
||||
buildPivotKeys(pivotKeys, aPivot, stats,facetFields, searchRequestContext);
|
||||
buildPivotKeys(pivotKeys, aPivot, stats, facetFields, ranges, searchRequestContext);
|
||||
sp.addPivots(pivotKeys);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void buildPivotKeys(List<String> pivotKeys, Pivot aPivot, List<StatsRequestParameters> stats, FacetFields facetFields, SearchRequestContext searchRequestContext)
|
||||
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;
|
||||
@@ -617,7 +617,7 @@ public class SearchMapper
|
||||
|
||||
if (pivotKey == null && ((aPivot.getPivots() == null) || aPivot.getPivots().isEmpty()))
|
||||
{
|
||||
//It is the last one so it can reference stats
|
||||
//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();
|
||||
@@ -628,12 +628,25 @@ public class SearchMapper
|
||||
searchRequestContext.getPivotKeys().put(pivotKey, pivotKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (ranges != null && !ranges.isEmpty())
|
||||
{
|
||||
for (RangeParameters aRange:ranges)
|
||||
{
|
||||
if (aRange.getTags().contains(aPivot.getKey()))
|
||||
{
|
||||
pivotKey = aPivot.getKey();
|
||||
pivotKeys.add(pivotKey);
|
||||
searchRequestContext.getPivotKeys().put(pivotKey, pivotKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pivotKey == null)
|
||||
{
|
||||
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
|
||||
new Object[] { ": Pivot parameter " + aPivot.getKey() + " does not reference a facet Field or stats." });
|
||||
new Object[] { ": Pivot parameter " + aPivot.getKey() + " does not reference a facet Field, range or stats." });
|
||||
}
|
||||
|
||||
if (aPivot.getPivots() != null && !aPivot.getPivots().isEmpty() && aPivot.getPivots().size()>1)
|
||||
@@ -644,7 +657,7 @@ public class SearchMapper
|
||||
|
||||
aPivot.getPivots().forEach(subPivot ->
|
||||
{
|
||||
buildPivotKeys(pivotKeys, subPivot, stats, facetFields, searchRequestContext);
|
||||
buildPivotKeys(pivotKeys, subPivot, stats, facetFields, ranges, searchRequestContext);
|
||||
});
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user