diff --git a/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java b/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java index 893aa4467f..8b7eed6d4b 100644 --- a/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java +++ b/source/java/org/alfresco/rest/api/search/SearchApiWebscript.java @@ -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 resultJson = resultMapper.toCollectionWithPagingInfo(params, results); + CollectionWithPagingInfo 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 diff --git a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java index 0e88a10004..7f2934e74e 100644 --- a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java @@ -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 toCollectionWithPagingInfo(Params params, ResultSet results) + public CollectionWithPagingInfo toCollectionWithPagingInfo(SearchQuery searchQuery, ResultSet results) { - SearchQuery searchQuery = (SearchQuery) params.getPassedIn(); SearchContext context = null; Long totalItems = results.getNumberFound(); List noderesults = new ArrayList(); + Map 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(); diff --git a/source/java/org/alfresco/rest/api/search/model/SearchEntry.java b/source/java/org/alfresco/rest/api/search/model/SearchEntry.java index 49eea51de2..266563e248 100644 --- a/source/java/org/alfresco/rest/api/search/model/SearchEntry.java +++ b/source/java/org/alfresco/rest/api/search/model/SearchEntry.java @@ -30,7 +30,7 @@ package org.alfresco.rest.api.search.model; **/ public class SearchEntry { - Float score; + private final Float score; public SearchEntry(Float score) { diff --git a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java index f09aca5641..6da9edc1db 100644 --- a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java +++ b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java @@ -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() { + when(nodes.getFolderOrDocument(notNull(NodeRef.class), any(), any(), any(), any())).thenAnswer(new Answer() { @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 collection = mapper.toCollectionWithPagingInfo(mockParams(SearchQuery.EMPTY),new EmptyResultSet()); + CollectionWithPagingInfo 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 collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(SearchQuery.EMPTY),results); + CollectionWithPagingInfo 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; } - +**/ }