mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged searchapi (5.2.1) to 5.2.N (5.2.1)
130027 gjames: SEARCH-120: Implementing facet queries git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130288 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -34,6 +34,7 @@ import org.alfresco.rest.api.search.model.SearchEntry;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.SearchContext;
|
||||
import org.alfresco.rest.framework.resource.parameters.SearchContext.FacetQueryResult;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -43,6 +44,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Maps from a ResultSet to a json public api representation.
|
||||
@@ -94,7 +96,7 @@ public class ResultMapper
|
||||
if (solrResultSet != null)
|
||||
{
|
||||
//We used Solr for this query
|
||||
context = setSearchContext(solrResultSet);
|
||||
context = toSearchContext(solrResultSet);
|
||||
total = setTotal(solrResultSet);
|
||||
}
|
||||
else
|
||||
@@ -128,15 +130,32 @@ public class ResultMapper
|
||||
* @param SolrJSONResultSet
|
||||
* @return SearchContext
|
||||
*/
|
||||
protected SearchContext setSearchContext(SolrJSONResultSet solrResultSet)
|
||||
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet)
|
||||
{
|
||||
SearchContext context = null;
|
||||
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
|
||||
List<FacetQueryResult> facetResults = null;
|
||||
|
||||
if (solrResultSet.getLastIndexedTxId() > 0)
|
||||
if(facetQueries!= null && !facetQueries.isEmpty())
|
||||
{
|
||||
context = new SearchContext(solrResultSet.getLastIndexedTxId());
|
||||
facetResults = new ArrayList<>(facetQueries.size());
|
||||
for (Entry<String, Integer> fq:facetQueries.entrySet())
|
||||
{
|
||||
facetResults.add(new FacetQueryResult(fq.getKey(), fq.getValue()));
|
||||
}
|
||||
}
|
||||
return context;
|
||||
context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults);
|
||||
return isNullContext(context)?null:context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the context null?
|
||||
* @param context
|
||||
* @return true if its null
|
||||
*/
|
||||
protected boolean isNullContext(SearchContext context)
|
||||
{
|
||||
return (context.getFacetQueries() == null && context.getConsistency() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -27,6 +27,7 @@
|
||||
package org.alfresco.rest.api.search.impl;
|
||||
|
||||
import org.alfresco.rest.api.search.model.Default;
|
||||
import org.alfresco.rest.api.search.model.FacetQuery;
|
||||
import org.alfresco.rest.api.search.model.FilterQuery;
|
||||
import org.alfresco.rest.api.search.model.Query;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
@@ -92,6 +93,7 @@ public class SearchMapper
|
||||
validateInclude(searchQuery.getInclude());
|
||||
fromDefault(sp, searchQuery.getDefaults());
|
||||
fromFilterQuery(sp, searchQuery.getFilterQueries());
|
||||
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
||||
|
||||
return sp;
|
||||
}
|
||||
@@ -257,4 +259,20 @@ public class SearchMapper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** SearchParameters from List<FacetQuery>
|
||||
* @param sp
|
||||
* @param facetQueries
|
||||
*/
|
||||
public void fromFacetQuery(SearchParameters sp, List<FacetQuery> facetQueries)
|
||||
{
|
||||
if (facetQueries != null && !facetQueries.isEmpty())
|
||||
{
|
||||
for (FacetQuery fq:facetQueries)
|
||||
{
|
||||
sp.addFacetQuery(fq.getQuery());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,55 @@
|
||||
/*-
|
||||
* #%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 the FacetQuery
|
||||
*/
|
||||
public class FacetQuery
|
||||
{
|
||||
private final String query;
|
||||
private final String label;
|
||||
|
||||
@JsonCreator
|
||||
public FacetQuery(@JsonProperty("query") String query, @JsonProperty("label") String label)
|
||||
{
|
||||
this.query = query;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getQuery()
|
||||
{
|
||||
return query;
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
}
|
@@ -46,8 +46,9 @@ public class SearchQuery
|
||||
private final List<Template> templates;
|
||||
private final Default defaults;
|
||||
private final List<FilterQuery> filterQueries;
|
||||
private final List<FacetQuery> facetQueries;
|
||||
|
||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null);
|
||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null);
|
||||
|
||||
@JsonCreator
|
||||
public SearchQuery(@JsonProperty("query") Query query,
|
||||
@@ -56,7 +57,8 @@ public class SearchQuery
|
||||
@JsonProperty("sort") List<SortDef> sort,
|
||||
@JsonProperty("templates") List<Template> templates,
|
||||
@JsonProperty("defaults") Default defaults,
|
||||
@JsonProperty("filterQueries") List<FilterQuery> filterQueries)
|
||||
@JsonProperty("filterQueries") List<FilterQuery> filterQueries,
|
||||
@JsonProperty("facetQueries") List<FacetQuery> facetQueries)
|
||||
{
|
||||
this.query = query;
|
||||
this.paging = paging;
|
||||
@@ -65,6 +67,7 @@ public class SearchQuery
|
||||
this.templates = templates;
|
||||
this.defaults = defaults;
|
||||
this.filterQueries = filterQueries;
|
||||
this.facetQueries = facetQueries;
|
||||
}
|
||||
|
||||
public Query getQuery()
|
||||
@@ -99,4 +102,9 @@ public class SearchQuery
|
||||
{
|
||||
return filterQueries;
|
||||
}
|
||||
|
||||
public List<FacetQuery> getFacetQueries()
|
||||
{
|
||||
return facetQueries;
|
||||
}
|
||||
}
|
||||
|
@@ -25,16 +25,28 @@
|
||||
*/
|
||||
package org.alfresco.rest.framework.resource.parameters;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The contextual results of a Search
|
||||
*/
|
||||
public class SearchContext
|
||||
{
|
||||
Consistency consistency;
|
||||
private final Consistency consistency;
|
||||
private final List<FacetQueryResult> facetQueries;
|
||||
|
||||
public SearchContext(long lastTxId)
|
||||
public SearchContext(long lastTxId, List<FacetQueryResult> facetQueries)
|
||||
{
|
||||
consistency = new Consistency(lastTxId);
|
||||
if (lastTxId > 0)
|
||||
{
|
||||
consistency = new Consistency(lastTxId);
|
||||
}
|
||||
else
|
||||
{
|
||||
consistency = null;
|
||||
}
|
||||
this.facetQueries = facetQueries;
|
||||
}
|
||||
|
||||
public Consistency getConsistency()
|
||||
@@ -42,9 +54,36 @@ public class SearchContext
|
||||
return consistency;
|
||||
}
|
||||
|
||||
public List<FacetQueryResult> getFacetQueries()
|
||||
{
|
||||
return facetQueries;
|
||||
}
|
||||
|
||||
public static class FacetQueryResult
|
||||
{
|
||||
private final String label;
|
||||
private final int count;
|
||||
|
||||
public FacetQueryResult(String label, int count)
|
||||
{
|
||||
this.label = label;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public class Consistency
|
||||
{
|
||||
private long lastTxId;
|
||||
private final long lastTxId;
|
||||
|
||||
public Consistency(long lastTxId)
|
||||
{
|
||||
|
Reference in New Issue
Block a user