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
|
Get faceted-search config, if configured
|
||||||
|
|
||||||
http://<host>:<port>/alfresco/api/solr/facet-config
|
http://<host>:<port>/alfresco/api/solr/facet-config
|
||||||
|
Or
|
||||||
|
http://<host>:<port>/alfresco/api/solr/facet-config/{filterId}
|
||||||
|
|
||||||
Example response from this web script:
|
Example response from this web script:
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@
|
|||||||
"filterID" : "filter_content_size",
|
"filterID" : "filter_content_size",
|
||||||
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
||||||
"displayName" : "faceted-search.facet-menu.facet.size",
|
"displayName" : "faceted-search.facet-menu.facet.size",
|
||||||
|
"displayControl" : "alfresco\/search\/FacetFilters",
|
||||||
"maxFilters" : 5,
|
"maxFilters" : 5,
|
||||||
"hitThreshold" : 1,
|
"hitThreshold" : 1,
|
||||||
"minFilterValueLength" : 5,
|
"minFilterValueLength" : 5,
|
||||||
@@ -25,7 +28,8 @@
|
|||||||
"site1"
|
"site1"
|
||||||
],
|
],
|
||||||
"index" : 5,
|
"index" : 5,
|
||||||
"isEnabled" : true
|
"isEnabled" : true,
|
||||||
|
"isDefault" : true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -35,6 +39,7 @@
|
|||||||
]]>
|
]]>
|
||||||
</description>
|
</description>
|
||||||
<url>/api/solr/facet-config</url>
|
<url>/api/solr/facet-config</url>
|
||||||
|
<url>/api/solr/facet-config/{filterID}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
@@ -1,28 +1,38 @@
|
|||||||
|
<#macro facetJSON facet>
|
||||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
{
|
"filterID" : "${facet.filterID}",
|
||||||
"facets": [
|
"facetQName" : "${facet.facetQName}",
|
||||||
<#list filters?keys as facet>
|
"displayName" : "${facet.displayName}",
|
||||||
<#assign f=filters[facet]>
|
"displayControl" : "${facet.displayControl}",
|
||||||
{
|
"maxFilters" : ${facet.maxFilters?c},
|
||||||
"filterID" : "${f.filterID}",
|
"hitThreshold" : ${facet.hitThreshold?c},
|
||||||
"facetQName" : "${f.facetQName}",
|
"minFilterValueLength" : ${facet.minFilterValueLength?c},
|
||||||
"displayName" : "${f.displayName}",
|
"sortBy" : "${facet.sortBy}",
|
||||||
"maxFilters" : ${f.maxFilters?c},
|
"scope" : "${facet.scope}",
|
||||||
"hitThreshold" : ${f.hitThreshold?c},
|
|
||||||
"minFilterValueLength" : ${f.minFilterValueLength?c},
|
|
||||||
"sortBy" : "${f.sortBy}",
|
|
||||||
"scope" : "${f.scope}",
|
|
||||||
"scopedSites" : [
|
"scopedSites" : [
|
||||||
<#if f.scopedSites??>
|
<#if facet.scopedSites??>
|
||||||
<#list f.scopedSites as site>
|
<#list facet.scopedSites as site>
|
||||||
"${site}"<#if site_has_next>,</#if>
|
"${site}"<#if site_has_next>,</#if>
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
],
|
],
|
||||||
"index" : ${f.index?c},
|
"index" : ${facet.index?c},
|
||||||
"isEnabled" : ${f.enabled?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>
|
}<#if facet_has_next>,</#if>
|
||||||
</#list>
|
</#list>
|
||||||
]
|
]
|
||||||
|
|
||||||
|
<#else>
|
||||||
|
<@facetJSON facet=filter />
|
||||||
|
</#if>
|
||||||
}
|
}
|
||||||
</#escape>
|
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
"filterID" : "filter_content_size",
|
"filterID" : "filter_content_size",
|
||||||
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
||||||
"displayName" : "faceted-search.facet-menu.facet.size",
|
"displayName" : "faceted-search.facet-menu.facet.size",
|
||||||
|
"displayControl" : "alfresco/search/FacetFilters",
|
||||||
"maxFilters" : 5,
|
"maxFilters" : 5,
|
||||||
"hitThreshold" : 1,
|
"hitThreshold" : 1,
|
||||||
"minFilterValueLength" : 5,
|
"minFilterValueLength" : 5,
|
||||||
@@ -22,8 +23,8 @@
|
|||||||
"site2",
|
"site2",
|
||||||
"site1"
|
"site1"
|
||||||
],
|
],
|
||||||
"index" : 6,
|
"index" : 6, // optional
|
||||||
"isEnabled" : true
|
"isEnabled" : true // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
"filterID" : "filter_content_size",
|
"filterID" : "filter_content_size",
|
||||||
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
|
||||||
"displayName" : "faceted-search.facet-menu.facet.size",
|
"displayName" : "faceted-search.facet-menu.facet.size",
|
||||||
|
"displayControl" : "alfresco/search/FacetFilters",
|
||||||
"maxFilters" : 5,
|
"maxFilters" : 5,
|
||||||
"hitThreshold" : 1,
|
"hitThreshold" : 1,
|
||||||
"minFilterValueLength" : 5,
|
"minFilterValueLength" : 5,
|
||||||
@@ -22,8 +23,8 @@
|
|||||||
"site2",
|
"site2",
|
||||||
"site1"
|
"site1"
|
||||||
],
|
],
|
||||||
"index" : 6,
|
"index" : 6, // optional
|
||||||
"isEnabled" : true
|
"isEnabled" : true // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
@@ -51,6 +51,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
|||||||
protected static final String PARAM_FILTER_ID = "filterID";
|
protected static final String PARAM_FILTER_ID = "filterID";
|
||||||
protected static final String PARAM_FACET_QNAME = "facetQName";
|
protected static final String PARAM_FACET_QNAME = "facetQName";
|
||||||
protected static final String PARAM_DISPLAY_NAME = "displayName";
|
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_MAX_FILTERS = "maxFilters";
|
||||||
protected static final String PARAM_HIT_THRESHOLD = "hitThreshold";
|
protected static final String PARAM_HIT_THRESHOLD = "hitThreshold";
|
||||||
protected static final String PARAM_MIN_FILTER_VALUE_LENGTH = "minFilterValueLength";
|
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 QName facetQName = QName.createQName(facetQNameStr);
|
||||||
final String displayName = json.getString(PARAM_DISPLAY_NAME);
|
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 maxFilters = json.getInt(PARAM_MAX_FILTERS);
|
||||||
final int hitThreshold = json.getInt(PARAM_HIT_THRESHOLD);
|
final int hitThreshold = json.getInt(PARAM_HIT_THRESHOLD);
|
||||||
final int minFilterValueLength = json.getInt(PARAM_MIN_FILTER_VALUE_LENGTH);
|
final int minFilterValueLength = json.getInt(PARAM_MIN_FILTER_VALUE_LENGTH);
|
||||||
final String sortBy = json.getString(PARAM_SORT_BY);
|
final String sortBy = json.getString(PARAM_SORT_BY);
|
||||||
final String scope = json.getString(PARAM_SCOPE);
|
final String scope = json.getString(PARAM_SCOPE);
|
||||||
final int index = json.getInt(PARAM_INDEX);
|
final int index = getValue(Integer.class, json.opt(PARAM_INDEX), 0); //FIXME get the index from the service
|
||||||
final boolean isEnabled = json.getBoolean(PARAM_IS_ENABLED);
|
final boolean isEnabled = getValue(Boolean.class, json.opt(PARAM_IS_ENABLED), true);
|
||||||
JSONArray scopedSitesJsonArray = json.getJSONArray(PARAM_SCOPED_SITES);
|
JSONArray scopedSitesJsonArray = json.getJSONArray(PARAM_SCOPED_SITES);
|
||||||
Set<String> scopedSites = null;
|
Set<String> scopedSites = null;
|
||||||
if (scopedSitesJsonArray != null)
|
if (scopedSitesJsonArray != null)
|
||||||
@@ -128,6 +130,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
|||||||
.filterID(filterID)
|
.filterID(filterID)
|
||||||
.facetQName(facetQName)
|
.facetQName(facetQName)
|
||||||
.displayName(displayName)
|
.displayName(displayName)
|
||||||
|
.displayControl(displayControl)
|
||||||
.maxFilters(maxFilters)
|
.maxFilters(maxFilters)
|
||||||
.hitThreshold(hitThreshold)
|
.hitThreshold(hitThreshold)
|
||||||
.minFilterValueLength(minFilterValueLength)
|
.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);
|
abstract protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache);
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.web.scripts.solr.facet;
|
package org.alfresco.repo.web.scripts.solr.facet;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties;
|
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.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,15 +44,30 @@ public class SolrFacetConfigAdminGet extends AbstractSolrFacetConfigAdminWebScri
|
|||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
|
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);
|
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||||
|
|
||||||
|
if (filterID == null)
|
||||||
|
{
|
||||||
|
List<SolrFacetProperties> filters = new ArrayList<>(facetService.getFacets().values());
|
||||||
model.put("filters", filters);
|
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())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Retrieved all available facets: " + filters);
|
logger.debug("Retrieved all available facets: " + model.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
Reference in New Issue
Block a user