From 67c21ad60090676da3b6cfd7b4cbae9c70bddd24 Mon Sep 17 00:00:00 2001 From: Gethin James Date: Tue, 6 Sep 2016 14:17:56 +0000 Subject: [PATCH] Merged searchapi (5.2.1) to 5.2.N (5.2.1) 129779 gjames: SEARCH-118: Adding search.score to node response git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130171 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/model/Node.java | 16 ++++++++++++++ .../rest/api/search/impl/ResultMapper.java | 5 +++-- .../rest/api/search/model/SearchEntry.java | 21 +++++++++++++++++++ .../rest/api/search/ResultMapperTests.java | 8 ++++--- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 source/java/org/alfresco/rest/api/search/model/SearchEntry.java diff --git a/source/java/org/alfresco/rest/api/model/Node.java b/source/java/org/alfresco/rest/api/model/Node.java index 2d49dccff9..0605ad18d2 100644 --- a/source/java/org/alfresco/rest/api/model/Node.java +++ b/source/java/org/alfresco/rest/api/model/Node.java @@ -34,6 +34,7 @@ import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.rest.api.search.model.SearchEntry; import org.alfresco.rest.framework.resource.UniqueId; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; @@ -91,6 +92,9 @@ public class Node implements Comparable protected List allowableOperations; + //optional SearchEntry (only ever returned from a search) + protected SearchEntry search = null; + public Node(NodeRef nodeRef, NodeRef parentNodeRef, Map nodeProps, Map mapUserInfo, ServiceRegistry sr) { if(nodeRef == null) @@ -464,6 +468,10 @@ public class Node implements Comparable { sb.append(", allowableOperations=").append(getAllowableOperations()); } + if (getSearch() != null) + { + sb.append(", search=").append(getSearch()); + } sb.append("]"); return sb.toString(); } @@ -498,7 +506,15 @@ public class Node implements Comparable this.association = association; } + public SearchEntry getSearch() + { + return search; + } + public void setSearch(SearchEntry search) + { + this.search = search; + } // TODO for backwards compat' - set explicitly when needed (ie. favourites) (note: we could choose to have separate old Node/NodeImpl etc) protected String title; 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 615b3db7f3..63ad9b8004 100644 --- a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java @@ -30,6 +30,7 @@ import org.alfresco.model.ContentModel; 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.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Params; @@ -78,8 +79,8 @@ public class ResultMapper results.forEach(row -> { Node aNode = nodes.getFolderOrDocument(row.getNodeRef(), null, null, params.getInclude(), null); - //float f = row.getScore(); - //Long dbId = (Long) row.getValue(ContentModel.PROP_NODE_DBID); + float f = row.getScore(); + aNode.setSearch(new SearchEntry(f)); noderesults.add(aNode); } ); diff --git a/source/java/org/alfresco/rest/api/search/model/SearchEntry.java b/source/java/org/alfresco/rest/api/search/model/SearchEntry.java new file mode 100644 index 0000000000..b9f7a89ded --- /dev/null +++ b/source/java/org/alfresco/rest/api/search/model/SearchEntry.java @@ -0,0 +1,21 @@ +package org.alfresco.rest.api.search.model; + +/** + * POJO class representing the extra information that comes back from Search. + **/ +public class SearchEntry +{ + Float score; + + public SearchEntry(Float score) + { + this.score = score; + } + + public Float getScore() + { + return score; + } + + //In future highlighting. +} 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 b99062864b..0fad98d3fc 100644 --- a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java +++ b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java @@ -121,10 +121,12 @@ public class ResultMapperTests public void testToCollectionWithPagingInfo() throws Exception { ResultSet results = mockResultset(); - CollectionWithPagingInfo collection = mapper.toCollectionWithPagingInfo(mockParams(),results); - assertNotNull(collection); + CollectionWithPagingInfo collectionWithPage = mapper.toCollectionWithPagingInfo(mockParams(),results); + assertNotNull(collectionWithPage); Long found = results.getNumberFound(); - assertEquals(found.intValue(), collection.getTotalItems().intValue()); + assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue()); + Node firstNode = collectionWithPage.getCollection().stream().findFirst().get(); + assertNotNull(firstNode.getSearch().getScore()); } private ResultSet mockResultset() throws JSONException