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

131295 gjames: SEARCH-195: Adding highlighting to the public api


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132239 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-11-03 13:47:53 +00:00
parent 36b5206d45
commit 03acdaef03
4 changed files with 83 additions and 3 deletions

View File

@@ -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<Node> noderesults = new ArrayList();
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
Map<NodeRef, List<Pair<String, List<String>>>> 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<HighlightEntry> highlightEntries = null;
List<Pair<String, List<String>>> high = hightLighting.get(row.getNodeRef());
if (high != null && !high.isEmpty())
{
highlightEntries = new ArrayList<HighlightEntry>(high.size());
for (Pair<String, List<String>> highlight:high)
{
highlightEntries.add(new HighlightEntry(highlight.getFirst(), highlight.getSecond()));
}
}
aNode.setSearch(new SearchEntry(f, highlightEntries));
noderesults.add(aNode);
}
else

View File

@@ -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 <http://www.gnu.org/licenses/>.
* #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<String> snippets;
public HighlightEntry(String field, List<String> snippets)
{
this.field = field;
this.snippets = snippets;
}
public String getField()
{
return field;
}
public List<String> getSnippets()
{
return snippets;
}
}

View File

@@ -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<HighlightEntry> highlight;
public SearchEntry(Float score)
public SearchEntry(Float score, List<HighlightEntry> highlight)
{
this.score = score;
this.highlight = highlight;
}
public Float getScore()
@@ -42,5 +46,8 @@ public class SearchEntry
return score;
}
//In future highlighting.
public List<HighlightEntry> getHighlight()
{
return highlight;
}
}