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:
Will Abson
2014-09-03 15:51:24 +00:00
parent 28d3fcfa78
commit b0d07f4c04
6 changed files with 102 additions and 11 deletions

View File

@@ -178,6 +178,7 @@ public class SolrFacetConfig extends AbstractLifecycleBean
QName fieldQName = resolveToQName(namespaceService, field);
String filterID = propValues.get(ValueName.PROP_FILTER_ID.getPropValueName(field));
String displayName = propValues.get(ValueName.PROP_DISPLAY_NAME.getPropValueName(field));
String displayControl = propValues.get(ValueName.PROP_DISPLAY_CONTROL.getPropValueName(field));
int maxFilters = getIntegerValue(propValues.get(ValueName.PROP_MAX_FILTERS.getPropValueName(field)));
int hitThreshold = getIntegerValue(propValues.get(ValueName.PROP_HIT_THRESHOLD.getPropValueName(field)));
int minFilterValueLength = getIntegerValue(propValues.get(ValueName.PROP_MIN_FILTER_VALUE_LENGTH.getPropValueName(field)));
@@ -192,6 +193,7 @@ public class SolrFacetConfig extends AbstractLifecycleBean
.filterID(filterID)
.facetQName(fieldQName)
.displayName(displayName)
.displayControl(displayControl)
.maxFilters(maxFilters)
.hitThreshold(hitThreshold)
.minFilterValueLength(minFilterValueLength)
@@ -199,6 +201,7 @@ public class SolrFacetConfig extends AbstractLifecycleBean
.scope(scope)
.index(index)
.isEnabled(isEnabled)
.isDefault(true)
.scopedSites(scopedSites).build();
facetProperties.put(filterID, fp);
@@ -309,7 +312,7 @@ public class SolrFacetConfig extends AbstractLifecycleBean
{
PROP_FILTER_ID("filterID"), PROP_DISPLAY_NAME("displayName"), PROP_MAX_FILTERS("maxFilters"), PROP_HIT_THRESHOLD("hitThreshold"),
PROP_MIN_FILTER_VALUE_LENGTH("minFilterValueLength"), PROP_SORTBY("sortBy"), PROP_SCOPE("scope"), PROP_SCOPED_SITES("scopedSites"),
PROP_INDEX("index"), PROP_IS_ENABLED("isEnabled");
PROP_INDEX("index"), PROP_IS_ENABLED("isEnabled"), PROP_DISPLAY_CONTROL("displayControl");
private ValueName(String propValueName)
{

View File

@@ -37,6 +37,8 @@ public interface SolrFacetModel
public static final QName PROP_FIELD_LABEL = QName.createQName(SOLR_FACET_MODEL_URL, "fieldLabel");
public static final QName PROP_DISPLAY_CONTROL = QName.createQName(SOLR_FACET_MODEL_URL, "displayControl");
public static final QName PROP_MAX_FILTERS = QName.createQName(SOLR_FACET_MODEL_URL, "maxFilters");
public static final QName PROP_HIT_THRESHOLD = QName.createQName(SOLR_FACET_MODEL_URL, "hitThreshold");
@@ -52,4 +54,6 @@ public interface SolrFacetModel
public static final QName PROP_INDEX = QName.createQName(SOLR_FACET_MODEL_URL, "index");
public static final QName PROP_IS_ENABLED = QName.createQName(SOLR_FACET_MODEL_URL, "isEnabled");
public static final QName PROP_IS_DEFAULT = QName.createQName(SOLR_FACET_MODEL_URL, "isDefault");
}

View File

@@ -31,11 +31,12 @@ import org.alfresco.service.namespace.QName;
*
* @author Jamal Kaabi-Mofrad
*/
public class SolrFacetProperties
public class SolrFacetProperties implements Comparable<SolrFacetProperties>
{
private final String filterID;
private final QName facetQName;
private final String displayName;
private final String displayControl;
private final int maxFilters;
private final int hitThreshold;
private final int minFilterValueLength;
@@ -44,6 +45,7 @@ public class SolrFacetProperties
private final Set<String> scopedSites;
private final int index;
private final boolean isEnabled;
private final boolean isDefault; // is loaded from properties files?
/**
* Initialises a newly created <code>SolrFacetProperty</code> object
@@ -55,6 +57,7 @@ public class SolrFacetProperties
this.filterID = builder.filterID;
this.facetQName = builder.facetQName;
this.displayName = builder.displayName;
this.displayControl = builder.displayControl;
this.maxFilters = builder.maxFilters;
this.hitThreshold = builder.hitThreshold;
this.minFilterValueLength = builder.minFilterValueLength;
@@ -62,6 +65,7 @@ public class SolrFacetProperties
this.scope = builder.scope;
this.index = builder.index;
this.isEnabled = builder.isEnabled;
this.isDefault = builder.isDefault;
this.scopedSites = (builder.scopedSites == null) ? null :Collections.unmodifiableSet(new HashSet<String>(builder.scopedSites));
}
@@ -89,6 +93,14 @@ public class SolrFacetProperties
return this.displayName;
}
/**
* @return the displayControl
*/
public String getDisplayControl()
{
return this.displayControl;
}
/**
* @return the maxFilters
*/
@@ -159,6 +171,16 @@ public class SolrFacetProperties
return this.isEnabled;
}
/**
* Whether the facet is a default facet (loaded from a configuration file) or not
*
* @return true if the facet is default, false otherwise
*/
public boolean isDefault()
{
return this.isDefault;
}
/*
* @see java.lang.Object#hashCode()
*/
@@ -204,21 +226,31 @@ public class SolrFacetProperties
return true;
}
/*
* @see java.lang.Comparable#compareTo(T)
*/
@Override
public int compareTo(SolrFacetProperties that)
{
return Integer.compare(this.index, that.index);
}
/*
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder2 = new StringBuilder(270);
builder2.append("FacetProperty [filterID=").append(this.filterID).append(", facetQName=")
.append(this.facetQName).append(", displayName=").append(this.displayName).append(", maxFilters=")
StringBuilder sb = new StringBuilder(320);
sb.append("FacetProperty [filterID=").append(this.filterID).append(", facetQName=")
.append(this.facetQName).append(", displayName=").append(this.displayName)
.append(", displayControl=").append(this.displayControl).append(", maxFilters=")
.append(this.maxFilters).append(", hitThreshold=").append(this.hitThreshold)
.append(", minFilterValueLength=").append(this.minFilterValueLength).append(", sortBy=")
.append(this.sortBy).append(", scope=").append(this.scope).append(", scopedSites=")
.append(this.scopedSites).append(", index=").append(this.index).append(", isEnabled=").append(this.isEnabled)
.append("]");
return builder2.toString();
.append(", isDefault=").append(this.isDefault).append("]");
return sb.toString();
}
public static class Builder
@@ -226,6 +258,7 @@ public class SolrFacetProperties
private String filterID;
private QName facetQName;
private String displayName;
private String displayControl;
private int maxFilters;
private int hitThreshold;
private int minFilterValueLength;
@@ -234,6 +267,7 @@ public class SolrFacetProperties
private Set<String> scopedSites;
private int index;
private boolean isEnabled;
private boolean isDefault;
public Builder filterID(String filterID)
{
@@ -253,6 +287,12 @@ public class SolrFacetProperties
return this;
}
public Builder displayControl(String displayControl)
{
this.displayControl = displayControl;
return this;
}
public Builder maxFilters(int maxFilters)
{
this.maxFilters = maxFilters;
@@ -301,6 +341,12 @@ public class SolrFacetProperties
return this;
}
public Builder isDefault(boolean isDefault)
{
this.isDefault = isDefault;
return this;
}
public SolrFacetProperties build()
{
return new SolrFacetProperties(this);

View File

@@ -21,7 +21,6 @@ package org.alfresco.repo.search.impl.solr.facet;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -54,6 +53,7 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
@@ -196,7 +196,8 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
@Override
public Map<String, SolrFacetProperties> getFacets()
{
return Collections.unmodifiableMap(facetsMap);
Map<String, SolrFacetProperties> sortedMap = CollectionUtils.sortMapByValue(facetsMap);
return sortedMap;
}
@Override
@@ -254,6 +255,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
String filterID = (String) properties.get(ContentModel.PROP_NAME);
QName fieldQName = (QName) properties.get(SolrFacetModel.PROP_FIELD_TYPE);
String displayName = (String) properties.get(SolrFacetModel.PROP_FIELD_LABEL);
String displayControl = (String) properties.get(SolrFacetModel.PROP_DISPLAY_CONTROL);
int maxFilters = (Integer) properties.get(SolrFacetModel.PROP_MAX_FILTERS);
int hitThreshold = (Integer) properties.get(SolrFacetModel.PROP_HIT_THRESHOLD);
int minFilterValueLength = (Integer) properties.get(SolrFacetModel.PROP_MIN_FILTER_VALUE_LENGTH);
@@ -261,6 +263,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
String scope = (String) properties.get(SolrFacetModel.PROP_SCOPE);
int index = (Integer) properties.get(SolrFacetModel.PROP_INDEX);
boolean isEnabled = (Boolean) properties.get(SolrFacetModel.PROP_IS_ENABLED);
boolean isDefault = (Boolean) properties.get(SolrFacetModel.PROP_IS_DEFAULT);
@SuppressWarnings("unchecked")
List<String> scSites = (List<String>) properties.get(SolrFacetModel.PROP_SCOPED_SITES);
Set<String> scopedSites = (scSites == null) ? null : new HashSet<>(scSites);
@@ -270,6 +273,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
.filterID(filterID)
.facetQName(fieldQName)
.displayName(displayName)
.displayControl(displayControl)
.maxFilters(maxFilters)
.hitThreshold(hitThreshold)
.minFilterValueLength(minFilterValueLength)
@@ -277,6 +281,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
.scope(scope)
.index(index)
.isEnabled(isEnabled)
.isDefault(isDefault)
.scopedSites(scopedSites).build();
return fp;
@@ -404,7 +409,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
throw new SolrFacetConfigException("Filter Id cannot be null.");
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(11);
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(14);
if (withFilterId)
{
@@ -412,6 +417,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
}
properties.put(SolrFacetModel.PROP_FIELD_TYPE, facetProperties.getFacetQName());
properties.put(SolrFacetModel.PROP_FIELD_LABEL, facetProperties.getDisplayName());
properties.put(SolrFacetModel.PROP_DISPLAY_CONTROL, facetProperties.getDisplayControl());
properties.put(SolrFacetModel.PROP_MAX_FILTERS, facetProperties.getMaxFilters());
properties.put(SolrFacetModel.PROP_HIT_THRESHOLD, facetProperties.getHitThreshold());
properties.put(SolrFacetModel.PROP_MIN_FILTER_VALUE_LENGTH, facetProperties.getMinFilterValueLength());
@@ -421,6 +427,9 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
properties.put(SolrFacetModel.PROP_INDEX, facetProperties.getIndex());
properties.put(SolrFacetModel.PROP_IS_ENABLED, facetProperties.isEnabled());
SolrFacetProperties fp = facetConfig.getDefaultFacets().get(facetProperties.getFilterID());
properties.put(SolrFacetModel.PROP_IS_DEFAULT, (fp == null) ? false : fp.isDefault());
return properties;
}
@@ -531,6 +540,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
{
SolrFacetProperties fp = getFacetProperties(childAssocRef.getChildRef());
this.facetsMap.put(fp.getFilterID(), fp);
this.facetNodeRefCache.put(fp.getFilterID(), childAssocRef.getChildRef());
}
@Override
@@ -538,5 +548,6 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
{
String filterID = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
this.facetsMap.remove(filterID);
this.facetNodeRefCache.remove(filterID);
}
}