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 071b992274..3a373f412a 100644 --- a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java @@ -33,11 +33,13 @@ import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.api.search.context.FacetFieldContext; import org.alfresco.rest.api.search.context.FacetFieldContext.Bucket; import org.alfresco.rest.api.search.context.SpellCheckContext; +import org.alfresco.rest.api.search.model.HighlightEntry; import org.alfresco.rest.api.search.model.SearchEntry; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.api.search.context.SearchContext; import org.alfresco.rest.api.search.context.FacetQueryContext; import org.alfresco.rest.framework.resource.parameters.Params; +import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SpellCheckResult; import org.alfresco.util.Pair; @@ -80,6 +82,7 @@ public class ResultMapper Integer total = null; List noderesults = new ArrayList(); Map mapUserInfo = new HashMap<>(10); + Map>>> hightLighting = results.getHighlighting(); results.forEach(row -> { @@ -87,7 +90,18 @@ public class ResultMapper if (aNode != null) { float f = row.getScore(); - aNode.setSearch(new SearchEntry(f)); + List highlightEntries = null; + List>> high = hightLighting.get(row.getNodeRef()); + + if (high != null && !high.isEmpty()) + { + highlightEntries = new ArrayList(high.size()); + for (Pair> highlight:high) + { + highlightEntries.add(new HighlightEntry(highlight.getFirst(), highlight.getSecond())); + } + } + aNode.setSearch(new SearchEntry(f, highlightEntries)); noderesults.add(aNode); } else diff --git a/source/java/org/alfresco/rest/api/search/model/HighlightEntry.java b/source/java/org/alfresco/rest/api/search/model/HighlightEntry.java new file mode 100644 index 0000000000..3971b6e88f --- /dev/null +++ b/source/java/org/alfresco/rest/api/search/model/HighlightEntry.java @@ -0,0 +1,55 @@ +/*- + * #%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 . + * #L% + */ +package org.alfresco.rest.api.search.model; + +import java.util.List; + +/** + * POJO class representing a HighlightEntry + * + * @author Gethin James + */ +public class HighlightEntry +{ + private final String field; + private final List snippets; + + public HighlightEntry(String field, List snippets) + { + this.field = field; + this.snippets = snippets; + } + + public String getField() + { + return field; + } + + public List getSnippets() + { + return snippets; + } +} 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 266563e248..4f83af7da2 100644 --- a/source/java/org/alfresco/rest/api/search/model/SearchEntry.java +++ b/source/java/org/alfresco/rest/api/search/model/SearchEntry.java @@ -25,16 +25,20 @@ */ package org.alfresco.rest.api.search.model; +import java.util.List; + /** * POJO class representing the extra information that comes back from Search. **/ public class SearchEntry { private final Float score; + private final List highlight; - public SearchEntry(Float score) + public SearchEntry(Float score, List highlight) { this.score = score; + this.highlight = highlight; } public Float getScore() @@ -42,5 +46,8 @@ public class SearchEntry return score; } - //In future highlighting. + public List getHighlight() + { + return highlight; + } } 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 54713ffd12..eeac15ec07 100644 --- a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java +++ b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java @@ -86,6 +86,10 @@ public class ResultMapperTests + "\"facet_counts\":{\"facet_queries\":{\"small\":0,\"large\":0,\"xtra small\":3,\"xtra large\":0,\"medium\":8,\"XX large\":0}," + "\"facet_fields\":{\"content.size\":[\"Big\",8,\"Brown\",3,\"Fox\",5,\"Jumped\",2,\"somewhere\",3]},\"facet_dates\":{},\"facet_ranges\":{},\"facet_intervals\":{}\n" + " }," + "\"spellcheck\":{\"searchInsteadFor\":\"alfresco\"}," + + "\"highlighting\": {" + + " \"_DEFAULT_!800001579e3d1964!800001579e3d1969\": {\"name\": [\"some very long name\"],\"title\": [\"title1 is very long\"], \"DBID\": \"521\"}," + + " \"_DEFAULT_!800001579e3d1964!800001579e3d196a\": {\"name\": [\"this is some long text. It\", \" has the word long in many places\", \". In fact, it has long on some\", \" happens to long in this case.\"], \"DBID\": \"1475846153692\"}" + + "}," + "\"processedDenies\":true, \"lastIndexedTx\":34}"; public static final Params EMPTY_PARAMS = Params.valueOf((String)null,(String)null,(WebScriptRequest) null);