mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
80509: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 74144: ACE-1582: added: - more facet props to the Model and the related JSON response - GET one facet API - Sorting by facet index git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82806 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
Get faceted-search config, if configured
|
||||
|
||||
http://<host>:<port>/alfresco/api/solr/facet-config
|
||||
Or
|
||||
http://<host>:<port>/alfresco/api/solr/facet-config/{filterId}
|
||||
|
||||
Example response from this web script:
|
||||
|
||||
@@ -14,6 +16,7 @@
|
||||
"filterID" : "filter_content_size",
|
||||
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
||||
"displayName" : "faceted-search.facet-menu.facet.size",
|
||||
"displayControl" : "alfresco\/search\/FacetFilters",
|
||||
"maxFilters" : 5,
|
||||
"hitThreshold" : 1,
|
||||
"minFilterValueLength" : 5,
|
||||
@@ -25,7 +28,8 @@
|
||||
"site1"
|
||||
],
|
||||
"index" : 5,
|
||||
"isEnabled" : true
|
||||
"isEnabled" : true,
|
||||
"isDefault" : true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -35,6 +39,7 @@
|
||||
]]>
|
||||
</description>
|
||||
<url>/api/solr/facet-config</url>
|
||||
<url>/api/solr/facet-config/{filterID}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -1,28 +1,38 @@
|
||||
<#macro facetJSON facet>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"facets": [
|
||||
<#list filters?keys as facet>
|
||||
<#assign f=filters[facet]>
|
||||
{
|
||||
"filterID" : "${f.filterID}",
|
||||
"facetQName" : "${f.facetQName}",
|
||||
"displayName" : "${f.displayName}",
|
||||
"maxFilters" : ${f.maxFilters?c},
|
||||
"hitThreshold" : ${f.hitThreshold?c},
|
||||
"minFilterValueLength" : ${f.minFilterValueLength?c},
|
||||
"sortBy" : "${f.sortBy}",
|
||||
"scope" : "${f.scope}",
|
||||
"filterID" : "${facet.filterID}",
|
||||
"facetQName" : "${facet.facetQName}",
|
||||
"displayName" : "${facet.displayName}",
|
||||
"displayControl" : "${facet.displayControl}",
|
||||
"maxFilters" : ${facet.maxFilters?c},
|
||||
"hitThreshold" : ${facet.hitThreshold?c},
|
||||
"minFilterValueLength" : ${facet.minFilterValueLength?c},
|
||||
"sortBy" : "${facet.sortBy}",
|
||||
"scope" : "${facet.scope}",
|
||||
"scopedSites" : [
|
||||
<#if f.scopedSites??>
|
||||
<#list f.scopedSites as site>
|
||||
<#if facet.scopedSites??>
|
||||
<#list facet.scopedSites as site>
|
||||
"${site}"<#if site_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
],
|
||||
"index" : ${f.index?c},
|
||||
"isEnabled" : ${f.enabled?c}
|
||||
}<#if facet_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
}
|
||||
"index" : ${facet.index?c},
|
||||
"isEnabled" : ${facet.enabled?c},
|
||||
"isDefault" : ${facet.default?c}
|
||||
</#escape>
|
||||
</#macro>
|
||||
|
||||
{
|
||||
<#if filters??>
|
||||
"facets" : [
|
||||
<#list filters as facet>
|
||||
{
|
||||
<@facetJSON facet=facet />
|
||||
}<#if facet_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
|
||||
<#else>
|
||||
<@facetJSON facet=filter />
|
||||
</#if>
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
"filterID" : "filter_content_size",
|
||||
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
||||
"displayName" : "faceted-search.facet-menu.facet.size",
|
||||
"displayControl" : "alfresco/search/FacetFilters",
|
||||
"maxFilters" : 5,
|
||||
"hitThreshold" : 1,
|
||||
"minFilterValueLength" : 5,
|
||||
@@ -22,8 +23,8 @@
|
||||
"site2",
|
||||
"site1"
|
||||
],
|
||||
"index" : 6,
|
||||
"isEnabled" : true
|
||||
"index" : 6, // optional
|
||||
"isEnabled" : true // optional
|
||||
}
|
||||
|
||||
Notes:
|
||||
|
@@ -12,6 +12,7 @@
|
||||
"filterID" : "filter_content_size",
|
||||
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
||||
"displayName" : "faceted-search.facet-menu.facet.size",
|
||||
"displayControl" : "alfresco/search/FacetFilters",
|
||||
"maxFilters" : 5,
|
||||
"hitThreshold" : 1,
|
||||
"minFilterValueLength" : 5,
|
||||
@@ -22,8 +23,8 @@
|
||||
"site2",
|
||||
"site1"
|
||||
],
|
||||
"index" : 6,
|
||||
"isEnabled" : true
|
||||
"index" : 6, // optional
|
||||
"isEnabled" : true // optional
|
||||
}
|
||||
|
||||
Notes:
|
||||
|
@@ -51,6 +51,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
protected static final String PARAM_FILTER_ID = "filterID";
|
||||
protected static final String PARAM_FACET_QNAME = "facetQName";
|
||||
protected static final String PARAM_DISPLAY_NAME = "displayName";
|
||||
protected static final String PARAM_DISPLAY_CONTROL = "displayControl";
|
||||
protected static final String PARAM_MAX_FILTERS = "maxFilters";
|
||||
protected static final String PARAM_HIT_THRESHOLD = "hitThreshold";
|
||||
protected static final String PARAM_MIN_FILTER_VALUE_LENGTH = "minFilterValueLength";
|
||||
@@ -105,13 +106,14 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
|
||||
final QName facetQName = QName.createQName(facetQNameStr);
|
||||
final String displayName = json.getString(PARAM_DISPLAY_NAME);
|
||||
final String displayControl = json.getString(PARAM_DISPLAY_CONTROL);
|
||||
final int maxFilters = json.getInt(PARAM_MAX_FILTERS);
|
||||
final int hitThreshold = json.getInt(PARAM_HIT_THRESHOLD);
|
||||
final int minFilterValueLength = json.getInt(PARAM_MIN_FILTER_VALUE_LENGTH);
|
||||
final String sortBy = json.getString(PARAM_SORT_BY);
|
||||
final String scope = json.getString(PARAM_SCOPE);
|
||||
final int index = json.getInt(PARAM_INDEX);
|
||||
final boolean isEnabled = json.getBoolean(PARAM_IS_ENABLED);
|
||||
final int index = getValue(Integer.class, json.opt(PARAM_INDEX), 0); //FIXME get the index from the service
|
||||
final boolean isEnabled = getValue(Boolean.class, json.opt(PARAM_IS_ENABLED), true);
|
||||
JSONArray scopedSitesJsonArray = json.getJSONArray(PARAM_SCOPED_SITES);
|
||||
Set<String> scopedSites = null;
|
||||
if (scopedSitesJsonArray != null)
|
||||
@@ -128,6 +130,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
.filterID(filterID)
|
||||
.facetQName(facetQName)
|
||||
.displayName(displayName)
|
||||
.displayControl(displayControl)
|
||||
.maxFilters(maxFilters)
|
||||
.hitThreshold(hitThreshold)
|
||||
.minFilterValueLength(minFilterValueLength)
|
||||
@@ -148,5 +151,22 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getValue(Class<T> clazz, Object value, T defaultValue) throws JSONException
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return clazz.cast(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JSONException("JSONObject[" + value +"] is not an instance of [" + clazz.getName() +"]");
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache);
|
||||
}
|
||||
|
@@ -19,7 +19,9 @@
|
||||
|
||||
package org.alfresco.repo.web.scripts.solr.facet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties;
|
||||
@@ -27,6 +29,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -41,15 +44,30 @@ public class SolrFacetConfigAdminGet extends AbstractSolrFacetConfigAdminWebScri
|
||||
@Override
|
||||
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
Map<String, SolrFacetProperties> filters = facetService.getFacets();
|
||||
// get the filterID parameter.
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String filterID = templateVars.get("filterID");
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||
|
||||
model.put("filters", filters);
|
||||
if (filterID == null)
|
||||
{
|
||||
List<SolrFacetProperties> filters = new ArrayList<>(facetService.getFacets().values());
|
||||
model.put("filters", filters);
|
||||
}
|
||||
else
|
||||
{
|
||||
SolrFacetProperties fp = facetService.getFacet(filterID);
|
||||
if (fp == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Filter not found");
|
||||
}
|
||||
model.put("filter", fp);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Retrieved all available facets: " + filters);
|
||||
logger.debug("Retrieved all available facets: " + model.values());
|
||||
}
|
||||
|
||||
return model;
|
||||
|
Reference in New Issue
Block a user