Merged searchapi (5.2.1) to 5.2.N (5.2.1)

130028 gjames: SEARCH-120: Moving SearchContext and facets to its own package


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130289 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-06 15:36:44 +00:00
parent 8cdfa5f8de
commit f0f886be92
8 changed files with 65 additions and 37 deletions

View File

@@ -0,0 +1,51 @@
/*-
* #%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.context;
/**
* The results of a facet query
*/
public class FacetQueryContext
{
private final String label;
private final int count;
public FacetQueryContext(String label, int count)
{
this.label = label;
this.count = count;
}
public String getLabel()
{
return label;
}
public int getCount()
{
return count;
}
}

View File

@@ -23,10 +23,9 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.framework.resource.parameters; package org.alfresco.rest.api.search.context;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* The contextual results of a Search * The contextual results of a Search
@@ -34,9 +33,9 @@ import java.util.Map;
public class SearchContext public class SearchContext
{ {
private final Consistency consistency; private final Consistency consistency;
private final List<FacetQueryResult> facetQueries; private final List<FacetQueryContext> facetQueries;
public SearchContext(long lastTxId, List<FacetQueryResult> facetQueries) public SearchContext(long lastTxId, List<FacetQueryContext> facetQueries)
{ {
if (lastTxId > 0) if (lastTxId > 0)
{ {
@@ -54,33 +53,11 @@ public class SearchContext
return consistency; return consistency;
} }
public List<FacetQueryResult> getFacetQueries() public List<FacetQueryContext> getFacetQueries()
{ {
return facetQueries; 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 public class Consistency
{ {
private final long lastTxId; private final long lastTxId;

View File

@@ -33,8 +33,8 @@ import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.search.model.SearchEntry; import org.alfresco.rest.api.search.model.SearchEntry;
import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.SearchContext; import org.alfresco.rest.api.search.context.SearchContext;
import org.alfresco.rest.framework.resource.parameters.SearchContext.FacetQueryResult; import org.alfresco.rest.api.search.context.FacetQueryContext;
import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -134,14 +134,14 @@ public class ResultMapper
{ {
SearchContext context = null; SearchContext context = null;
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries(); Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
List<FacetQueryResult> facetResults = null; List<FacetQueryContext> facetResults = null;
if(facetQueries!= null && !facetQueries.isEmpty()) if(facetQueries!= null && !facetQueries.isEmpty())
{ {
facetResults = new ArrayList<>(facetQueries.size()); facetResults = new ArrayList<>(facetQueries.size());
for (Entry<String, Integer> fq:facetQueries.entrySet()) for (Entry<String, Integer> fq:facetQueries.entrySet())
{ {
facetResults.add(new FacetQueryResult(fq.getKey(), fq.getValue())); facetResults.add(new FacetQueryContext(fq.getKey(), fq.getValue()));
} }
} }
context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults); context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults);

View File

@@ -26,7 +26,7 @@
package org.alfresco.rest.framework.resource; package org.alfresco.rest.framework.resource;
import org.alfresco.rest.framework.resource.parameters.SearchContext; import org.alfresco.rest.api.search.context.SearchContext;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Paging;
import java.util.Collection; import java.util.Collection;

View File

@@ -25,6 +25,7 @@
*/ */
package org.alfresco.rest.framework.resource.parameters; package org.alfresco.rest.framework.resource.parameters;
import org.alfresco.rest.api.search.context.SearchContext;
import org.alfresco.rest.framework.resource.SerializablePagedCollection; import org.alfresco.rest.framework.resource.SerializablePagedCollection;
import java.util.Arrays; import java.util.Arrays;

View File

@@ -43,7 +43,7 @@ import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.search.impl.ResultMapper; import org.alfresco.rest.api.search.impl.ResultMapper;
import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.SearchContext; import org.alfresco.rest.api.search.context.SearchContext;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;

View File

@@ -31,8 +31,8 @@ import org.alfresco.rest.api.search.model.Default;
import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.framework.jacksonextensions.ExecutionResult; import org.alfresco.rest.framework.jacksonextensions.ExecutionResult;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.SearchContext; import org.alfresco.rest.api.search.context.SearchContext;
import org.alfresco.rest.framework.resource.parameters.SearchContext.FacetQueryResult; import org.alfresco.rest.api.search.context.FacetQueryContext;
import org.alfresco.rest.framework.tests.api.mocks.Farmer; import org.alfresco.rest.framework.tests.api.mocks.Farmer;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@@ -92,7 +92,7 @@ public class SearchQuerySerializerTests
public void testSerializeContext() throws IOException public void testSerializeContext() throws IOException
{ {
ExecutionResult exec1 = new ExecutionResult(new Farmer("180"),null); ExecutionResult exec1 = new ExecutionResult(new Farmer("180"),null);
SearchContext searchContext = new SearchContext(23l, Arrays.asList(new FacetQueryResult("f1", 15), new FacetQueryResult("f2", 20))); SearchContext searchContext = new SearchContext(23l, Arrays.asList(new FacetQueryContext("f1", 15), new FacetQueryContext("f2", 20)));
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext); CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
String out = helper.writeResponse(coll); String out = helper.writeResponse(coll);
assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}")); assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}"));

View File

@@ -49,7 +49,6 @@ import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResource
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.rest.framework.resource.content.BinaryProperty; import org.alfresco.rest.framework.resource.content.BinaryProperty;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.SearchContext;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Paging;
import org.alfresco.rest.framework.resource.parameters.Params; import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.tests.api.mocks.Farmer; import org.alfresco.rest.framework.tests.api.mocks.Farmer;