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)
131292 gjames: SEARCH-195: Implementing hightlighting for the search public API git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132236 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -43,6 +43,7 @@ import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.search.GeneralHighlightParameters;
|
||||||
import org.alfresco.service.cmr.search.LimitBy;
|
import org.alfresco.service.cmr.search.LimitBy;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters;
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.FieldFacet;
|
import org.alfresco.service.cmr.search.SearchParameters.FieldFacet;
|
||||||
@@ -102,6 +103,7 @@ public class SearchMapper
|
|||||||
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
||||||
fromFacetFields(sp, searchQuery.getFacetFields());
|
fromFacetFields(sp, searchQuery.getFacetFields());
|
||||||
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
||||||
|
fromHighlight(sp, searchQuery.getHighlight());
|
||||||
fromScope(sp, searchQuery.getScope());
|
fromScope(sp, searchQuery.getScope());
|
||||||
fromLimits(sp, searchQuery.getLimits());
|
fromLimits(sp, searchQuery.getLimits());
|
||||||
|
|
||||||
@@ -426,6 +428,16 @@ public class SearchMapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the hightlight object on search parameters
|
||||||
|
* @param sp SearchParameters
|
||||||
|
* @param hightlight GeneralHighlightParameters
|
||||||
|
*/
|
||||||
|
public void fromHighlight(SearchParameters sp, GeneralHighlightParameters hightlight)
|
||||||
|
{
|
||||||
|
sp.setHightlight(hightlight);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SearchParameters from the Limits object
|
* SearchParameters from the Limits object
|
||||||
* @param sp SearchParameters
|
* @param sp SearchParameters
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.rest.api.search.model;
|
package org.alfresco.rest.api.search.model;
|
||||||
|
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.apache.solr.common.params.SpellingParams;
|
import org.alfresco.service.cmr.search.GeneralHighlightParameters;
|
||||||
import org.codehaus.jackson.annotate.JsonCreator;
|
import org.codehaus.jackson.annotate.JsonCreator;
|
||||||
import org.codehaus.jackson.annotate.JsonProperty;
|
import org.codehaus.jackson.annotate.JsonProperty;
|
||||||
|
|
||||||
@@ -53,8 +53,9 @@ public class SearchQuery
|
|||||||
private final Spelling spellcheck;
|
private final Spelling spellcheck;
|
||||||
private final Scope scope;
|
private final Scope scope;
|
||||||
private final Limits limits;
|
private final Limits limits;
|
||||||
|
private final GeneralHighlightParameters highlight;
|
||||||
|
|
||||||
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null,null, null, null, null, null);
|
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null,null, null, null,null, null, null, null, null, null);
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public SearchQuery(@JsonProperty("query") Query query,
|
public SearchQuery(@JsonProperty("query") Query query,
|
||||||
@@ -69,7 +70,8 @@ public class SearchQuery
|
|||||||
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
|
@JsonProperty("facetQueries") List<FacetQuery> facetQueries,
|
||||||
@JsonProperty("spellcheck") Spelling spellcheck,
|
@JsonProperty("spellcheck") Spelling spellcheck,
|
||||||
@JsonProperty("scope") Scope scope,
|
@JsonProperty("scope") Scope scope,
|
||||||
@JsonProperty("limits")Limits limits)
|
@JsonProperty("limits")Limits limits,
|
||||||
|
@JsonProperty("highlight")GeneralHighlightParameters highlight)
|
||||||
{
|
{
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.paging = paging;
|
this.paging = paging;
|
||||||
@@ -84,6 +86,7 @@ public class SearchQuery
|
|||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.facetFields = facetFields;
|
this.facetFields = facetFields;
|
||||||
this.limits = limits;
|
this.limits = limits;
|
||||||
|
this.highlight = highlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getQuery()
|
public Query getQuery()
|
||||||
@@ -145,6 +148,10 @@ public class SearchQuery
|
|||||||
return facetFields;
|
return facetFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GeneralHighlightParameters getHighlight()
|
||||||
|
{
|
||||||
|
return highlight;
|
||||||
|
}
|
||||||
public Limits getLimits()
|
public Limits getLimits()
|
||||||
{
|
{
|
||||||
return limits;
|
return limits;
|
||||||
|
@@ -53,6 +53,8 @@ import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.search.FieldHighlightParameters;
|
||||||
|
import org.alfresco.service.cmr.search.GeneralHighlightParameters;
|
||||||
import org.alfresco.service.cmr.search.LimitBy;
|
import org.alfresco.service.cmr.search.LimitBy;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters;
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.FieldFacet;
|
import org.alfresco.service.cmr.search.SearchParameters.FieldFacet;
|
||||||
@@ -60,6 +62,7 @@ import org.alfresco.service.cmr.search.SearchService;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the SearchMapper class
|
* Tests the SearchMapper class
|
||||||
@@ -511,10 +514,20 @@ public class SearchMapperTests
|
|||||||
assertEquals(-1, searchParameters.getMaxPermissionChecks());
|
assertEquals(-1, searchParameters.getMaxPermissionChecks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromHighlight() throws Exception
|
||||||
|
{
|
||||||
|
SearchParameters searchParameters = new SearchParameters();
|
||||||
|
List<FieldHighlightParameters> fields = Arrays.asList(new FieldHighlightParameters("desc",50,100,false,"@","#"), new FieldHighlightParameters("title",55,105,true,"*","¿"));
|
||||||
|
GeneralHighlightParameters highlightParameters = new GeneralHighlightParameters(5, 10, false, "{", "}", 20, true, fields);
|
||||||
|
searchMapper.fromHighlight(searchParameters,highlightParameters);
|
||||||
|
assertEquals(searchParameters.getHightlight(), highlightParameters);
|
||||||
|
}
|
||||||
|
|
||||||
private SearchQuery minimalQuery()
|
private SearchQuery minimalQuery()
|
||||||
{
|
{
|
||||||
Query query = new Query("cmis", "foo", "");
|
Query query = new Query("cmis", "foo", "");
|
||||||
SearchQuery sq = new SearchQuery(query,null, null, null, null, null, null, null, null, null, null, null, null);
|
SearchQuery sq = new SearchQuery(query,null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
return sq;
|
return sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ 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.tests.api.mocks.Farmer;
|
import org.alfresco.rest.framework.tests.api.mocks.Farmer;
|
||||||
|
import org.alfresco.service.cmr.search.FieldHighlightParameters;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -109,6 +110,32 @@ public class SearchQuerySerializerTests
|
|||||||
assertEquals(2, searchQuery.getFields().size());
|
assertEquals(2, searchQuery.getFields().size());
|
||||||
assertTrue(searchQuery.getFields().contains("id"));
|
assertTrue(searchQuery.getFields().contains("id"));
|
||||||
assertTrue(searchQuery.getFields().contains("name"));
|
assertTrue(searchQuery.getFields().contains("name"));
|
||||||
|
|
||||||
|
//Highlight
|
||||||
|
assertEquals("]", searchQuery.getHighlight().getPostfix());
|
||||||
|
assertEquals("[", searchQuery.getHighlight().getPrefix());
|
||||||
|
assertEquals(20, searchQuery.getHighlight().getSnippetCount().intValue());
|
||||||
|
assertEquals(10, searchQuery.getHighlight().getFragmentSize().intValue());
|
||||||
|
assertEquals(true, searchQuery.getHighlight().getMergeContiguous());
|
||||||
|
assertEquals(40, searchQuery.getHighlight().getMaxAnalyzedChars().intValue());
|
||||||
|
assertEquals(true, searchQuery.getHighlight().getUsePhraseHighlighter());
|
||||||
|
|
||||||
|
assertEquals(2, searchQuery.getHighlight().getFields().size());
|
||||||
|
FieldHighlightParameters high1 = searchQuery.getHighlight().getFields().get(0);
|
||||||
|
assertEquals("my", high1.getField());
|
||||||
|
assertEquals("¡", high1.getPostfix());
|
||||||
|
assertEquals("?", high1.getPrefix());
|
||||||
|
assertEquals(23, high1.getSnippetCount().intValue());
|
||||||
|
assertEquals(5, high1.getFragmentSize().intValue());
|
||||||
|
assertEquals(true,high1.getMergeContiguous());
|
||||||
|
|
||||||
|
FieldHighlightParameters high2 = searchQuery.getHighlight().getFields().get(1);
|
||||||
|
assertEquals("your", high2.getField());
|
||||||
|
assertEquals(")", high2.getPostfix());
|
||||||
|
assertEquals("(", high2.getPrefix());
|
||||||
|
assertEquals(3, high2.getSnippetCount().intValue());
|
||||||
|
assertEquals(15, high2.getFragmentSize().intValue());
|
||||||
|
assertEquals(false,high2.getMergeContiguous());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -66,6 +66,12 @@ public class SerializerTestHelper implements RequestReader
|
|||||||
+ "\"limits\": {\"permissionEvaluationCount\": \"2000\",\"permissionEvaluationTime\": \"5000\"},"
|
+ "\"limits\": {\"permissionEvaluationCount\": \"2000\",\"permissionEvaluationTime\": \"5000\"},"
|
||||||
+ "\"scope\": { \"stores\": [\"workspace://SpacesStore\"]},"
|
+ "\"scope\": { \"stores\": [\"workspace://SpacesStore\"]},"
|
||||||
+ "\"fields\": [\"id\", \"name\"],"
|
+ "\"fields\": [\"id\", \"name\"],"
|
||||||
|
+ "\"highlight\": {\"prefix\": \"[\",\"postfix\": \"]\",\"snippetCount\": \"20\","
|
||||||
|
+ "\"fragmentSize\": \"10\",\"mergeContiguous\": \"true\",\"maxAnalyzedChars\": \"40\", \"usePhraseHighlighter\": \"true\","
|
||||||
|
+ "\"fields\": [ "
|
||||||
|
+" {\"field\": \"my\", \"snippetCount\": \"23\", \"fragmentSize\": \"5\", \"mergeContiguous\": \"true\", \"prefix\": \"?\", \"postfix\": \"¡\" }, "
|
||||||
|
+" {\"field\": \"your\", \"snippetCount\": \"3\", \"fragmentSize\": \"15\", \"mergeContiguous\": \"false\", \"prefix\": \"(\", \"postfix\": \")\" } "
|
||||||
|
+ " ]" + " },"
|
||||||
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
+ "\"include\": [\"aspectNames\", \"properties\"]}";
|
||||||
|
|
||||||
public SerializerTestHelper()
|
public SerializerTestHelper()
|
||||||
|
Reference in New Issue
Block a user