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

129820 gjames: SEARCH-113: The JSON body not request is used for all params


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130180 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-06 14:19:01 +00:00
parent 347aedfa1b
commit c2953c739c
4 changed files with 30 additions and 20 deletions

View File

@@ -90,14 +90,14 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP
//Parse the parameters
Params params = getParams(webScriptRequest, searchQuery);
//Turn the params into the Java SearchParameters object
//Turn the SearchQuery json into the Java SearchParameters object
SearchParameters searchParams = searchMapper.toSearchParameters(searchQuery);
//Call searchService
ResultSet results = searchService.query(searchParams);
//Turn solr results into JSON
CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, results);
CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(searchQuery, results);
//Post-process the request and pass in params, eg. params.getFilter()
Object toRender = helper.processAdditionsToTheResponse(null, null, null, params, resultJson);
@@ -111,7 +111,7 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP
}
/**
* Gets the Params object, parameters come from the SearchQuery json not the requerst
* Gets the Params object, parameters come from the SearchQuery json not the request
* @param webScriptRequest
* @param searchQuery
* @return Params

View File

@@ -26,21 +26,23 @@
package org.alfresco.rest.api.search.impl;
import org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet;
import org.alfresco.repo.search.impl.lucene.SolrJSONResultSet;
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.search.model.SearchEntry;
import org.alfresco.rest.api.search.model.SearchQuery;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.SearchContext;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Maps from a Solr ResultSet to a json public api representation.
@@ -51,6 +53,7 @@ public class ResultMapper
{
private Nodes nodes;
private static Log logger = LogFactory.getLog(ResultMapper.class);
public ResultMapper(Nodes nodes)
{
@@ -64,21 +67,28 @@ public class ResultMapper
* @param results
* @return
*/
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, ResultSet results)
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(SearchQuery searchQuery, ResultSet results)
{
SearchQuery searchQuery = (SearchQuery) params.getPassedIn();
SearchContext context = null;
Long totalItems = results.getNumberFound();
List<Node> noderesults = new ArrayList();
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
results.forEach(row ->
{
Node aNode = nodes.getFolderOrDocument(row.getNodeRef(), null, null, params.getInclude(), null);
float f = row.getScore();
aNode.setSearch(new SearchEntry(f));
noderesults.add(aNode);
}
);
Node aNode = nodes.getFolderOrDocument(row.getNodeRef(), null, null, searchQuery.getInclude(), mapUserInfo);
if (aNode != null)
{
float f = row.getScore();
aNode.setSearch(new SearchEntry(f));
noderesults.add(aNode);
}
else
{
//What do I do?
logger.warn("Unknown noderef returned from search results "+row.getNodeRef());
}
});
Integer total = Integer.valueOf(totalItems.intValue());
int skip = searchQuery.getPaging()==null?0:searchQuery.getPaging().getSkipCount();

View File

@@ -30,7 +30,7 @@ package org.alfresco.rest.api.search.model;
**/
public class SearchEntry
{
Float score;
private final Float score;
public SearchEntry(Float score)
{

View File

@@ -98,7 +98,7 @@ public class ResultMapperTests
ServiceRegistry sr = mock(ServiceRegistry.class);
nodes.setServiceRegistry(sr);
when(nodes.getFolderOrDocument(notNull(NodeRef.class), any(), any(), notNull(List.class), any())).thenAnswer(new Answer<Node>() {
when(nodes.getFolderOrDocument(notNull(NodeRef.class), any(), any(), any(), any())).thenAnswer(new Answer<Node>() {
@Override
public Node answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
@@ -111,7 +111,7 @@ public class ResultMapperTests
@Test
public void testNoResults() throws Exception
{
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(mockParams(SearchQuery.EMPTY),new EmptyResultSet());
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(SearchQuery.EMPTY,new EmptyResultSet());
assertNotNull(collection);
assertFalse(collection.hasMoreItems());
assertTrue(collection.getTotalItems() < 1);
@@ -121,7 +121,7 @@ public class ResultMapperTests
public void testToCollectionWithPagingInfo() throws Exception
{
ResultSet results = mockResultset();
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(SearchQuery.EMPTY),results);
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(SearchQuery.EMPTY,results);
assertNotNull(collectionWithPage);
Long found = results.getNumberFound();
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
@@ -142,7 +142,7 @@ public class ResultMapperTests
ResultSet results = new SolrJSONResultSet(json,sp,nodeService, null, LimitBy.FINAL_SIZE, 10);
return results;
}
/**
private Params mockParams(SearchQuery searchQuery)
{
Params params = mock(Params.class);
@@ -150,5 +150,5 @@ public class ResultMapperTests
when(params.getPassedIn()).thenReturn(searchQuery);
return params;
}
**/
}