From 3a8e6c7309c452d61a4758dedbe3e44440f700f8 Mon Sep 17 00:00:00 2001 From: Will Abson Date: Wed, 3 Sep 2014 16:14:31 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 80643: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 76831: Enhancement to the /api/solr/facet-config REST endpoint to support facet reordering. If you add a query parameter like so: /api/solr/facet-config/{filterID}?relativePos={relativePos?} then the specified filterID will be moved by the specified relative position. '3' means move it 3 places down the list. '-1' means move it one place up the list. Note that currently you cannot provide a HTTP request body (JSON) at the same time as the relativePos param, in other words you cannot update the facet metadata and reposition in in one REST call. It is either or. We may enhance the webscript to support simultaneous edits of metadata and position at a future date. Also added automatic management of facet position on facet create and delete. New facets are put at the end of the list - this can easily be changed if it is not what's wanted. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82937 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../impl/solr/facet/SolrFacetServiceImpl.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/source/java/org/alfresco/repo/search/impl/solr/facet/SolrFacetServiceImpl.java b/source/java/org/alfresco/repo/search/impl/solr/facet/SolrFacetServiceImpl.java index c0efb4670b..6f8361042c 100644 --- a/source/java/org/alfresco/repo/search/impl/solr/facet/SolrFacetServiceImpl.java +++ b/source/java/org/alfresco/repo/search/impl/solr/facet/SolrFacetServiceImpl.java @@ -102,7 +102,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF private SimpleCache singletonCache; // eg. for facetsHomeNodeRef private final String KEY_FACETS_HOME_NODEREF = "key.facetshome.noderef"; private SimpleCache facetNodeRefCache; // for filterID to nodeRef lookup - private NavigableMap facetsMap = new ConcurrentSkipListMap<>(); + private NavigableMap facetsMap = new ConcurrentSkipListMap<>(); // TODO private int maxAllowedFilters = 100; /** @@ -455,8 +455,6 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF { logger.debug("Deleted [" + filterID + "] facet."); } - - // TODO Remove the matching filterID from the property list on the container. } private Map createNodeProperties(SolrFacetProperties facetProperties) @@ -652,6 +650,17 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF SolrFacetProperties fp = getFacetProperties(childAssocRef.getChildRef()); this.facetsMap.put(fp.getIndex(), fp); this.facetNodeRefCache.put(fp.getFilterID(), childAssocRef.getChildRef()); + + // We must also add the new filterID to the facetOrder property. + final NodeRef facetsRoot = getFacetsRoot(); + + @SuppressWarnings("unchecked") + ArrayList facetOrder = (ArrayList) nodeService.getProperty(facetsRoot, SolrFacetModel.PROP_FACET_ORDER); + + // We'll put it at the end (arbitrarily). + facetOrder.add(fp.getFilterID()); + + nodeService.setProperty(facetsRoot, SolrFacetModel.PROP_FACET_ORDER, facetOrder); } @Override @@ -662,6 +671,17 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF this.facetsMap.remove(index); this.facetNodeRefCache.remove(filterID); + + // We must also remove the filterID from the facetOrder property. + final NodeRef facetsRoot = getFacetsRoot(); + + @SuppressWarnings("unchecked") + ArrayList facetOrder = (ArrayList) nodeService.getProperty(facetsRoot, SolrFacetModel.PROP_FACET_ORDER); + + if (facetOrder.remove(filterID)) + { + nodeService.setProperty(facetsRoot, SolrFacetModel.PROP_FACET_ORDER, facetOrder); + } } @Override