mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -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;
|
||||||
import org.alfresco.rest.api.search.context.FacetFieldContext.Bucket;
|
import org.alfresco.rest.api.search.context.FacetFieldContext.Bucket;
|
||||||
import org.alfresco.rest.api.search.context.SpellCheckContext;
|
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.api.search.model.SearchEntry;
|
||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.api.search.context.SearchContext;
|
import org.alfresco.rest.api.search.context.SearchContext;
|
||||||
import org.alfresco.rest.api.search.context.FacetQueryContext;
|
import org.alfresco.rest.api.search.context.FacetQueryContext;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
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.ResultSet;
|
||||||
import org.alfresco.service.cmr.search.SpellCheckResult;
|
import org.alfresco.service.cmr.search.SpellCheckResult;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
@@ -80,6 +82,7 @@ public class ResultMapper
|
|||||||
Integer total = null;
|
Integer total = null;
|
||||||
List<Node> noderesults = new ArrayList();
|
List<Node> noderesults = new ArrayList();
|
||||||
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
|
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
|
||||||
|
Map<NodeRef, List<Pair<String, List<String>>>> hightLighting = results.getHighlighting();
|
||||||
|
|
||||||
results.forEach(row ->
|
results.forEach(row ->
|
||||||
{
|
{
|
||||||
@@ -87,7 +90,18 @@ public class ResultMapper
|
|||||||
if (aNode != null)
|
if (aNode != null)
|
||||||
{
|
{
|
||||||
float f = row.getScore();
|
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);
|
noderesults.add(aNode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -25,16 +25,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api.search.model;
|
package org.alfresco.rest.api.search.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POJO class representing the extra information that comes back from Search.
|
* POJO class representing the extra information that comes back from Search.
|
||||||
**/
|
**/
|
||||||
public class SearchEntry
|
public class SearchEntry
|
||||||
{
|
{
|
||||||
private final Float score;
|
private final Float score;
|
||||||
|
private final List<HighlightEntry> highlight;
|
||||||
|
|
||||||
public SearchEntry(Float score)
|
public SearchEntry(Float score, List<HighlightEntry> highlight)
|
||||||
{
|
{
|
||||||
this.score = score;
|
this.score = score;
|
||||||
|
this.highlight = highlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getScore()
|
public Float getScore()
|
||||||
@@ -42,5 +46,8 @@ public class SearchEntry
|
|||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
//In future highlighting.
|
public List<HighlightEntry> getHighlight()
|
||||||
|
{
|
||||||
|
return highlight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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_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" + " },"
|
+ "\"facet_fields\":{\"content.size\":[\"Big\",8,\"Brown\",3,\"Fox\",5,\"Jumped\",2,\"somewhere\",3]},\"facet_dates\":{},\"facet_ranges\":{},\"facet_intervals\":{}\n" + " },"
|
||||||
+ "\"spellcheck\":{\"searchInsteadFor\":\"alfresco\"},"
|
+ "\"spellcheck\":{\"searchInsteadFor\":\"alfresco\"},"
|
||||||
|
+ "\"highlighting\": {"
|
||||||
|
+ " \"_DEFAULT_!800001579e3d1964!800001579e3d1969\": {\"name\": [\"some very <al>long<fresco> name\"],\"title\": [\"title1 is very <al>long<fresco>\"], \"DBID\": \"521\"},"
|
||||||
|
+ " \"_DEFAULT_!800001579e3d1964!800001579e3d196a\": {\"name\": [\"this is some <al>long<fresco> text. It\", \" has the word <al>long<fresco> in many places\", \". In fact, it has <al>long<fresco> on some\", \" happens to <al>long<fresco> in this case.\"], \"DBID\": \"1475846153692\"}"
|
||||||
|
+ "},"
|
||||||
+ "\"processedDenies\":true, \"lastIndexedTx\":34}";
|
+ "\"processedDenies\":true, \"lastIndexedTx\":34}";
|
||||||
public static final Params EMPTY_PARAMS = Params.valueOf((String)null,(String)null,(WebScriptRequest) null);
|
public static final Params EMPTY_PARAMS = Params.valueOf((String)null,(String)null,(WebScriptRequest) null);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user