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.2) to HEAD (5.2)
136081 gjames: Merged searchbcr (5.2.1) to 5.2.N (5.2.1) 135511 gjames: SEARCH-372: Adding filterQuery to facetQueries result git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137453 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -99,7 +99,7 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP
|
||||
ResultSet results = searchService.query(searchParams);
|
||||
|
||||
//Turn solr results into JSON
|
||||
CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, results);
|
||||
CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, searchQuery, results);
|
||||
//Post-process the request and pass in params, eg. params.getFilter()
|
||||
Object toRender = helper.processAdditionsToTheResponse(null, null, null, params, resultJson);
|
||||
|
||||
|
@@ -31,7 +31,6 @@ import static org.alfresco.rest.api.search.impl.StoreMapper.LIVE_NODES;
|
||||
import static org.alfresco.rest.api.search.impl.StoreMapper.VERSIONS;
|
||||
import org.alfresco.repo.search.impl.lucene.SolrJSONResultSet;
|
||||
import org.alfresco.repo.version.Version2Model;
|
||||
import org.alfresco.repo.version.VersionBaseModel;
|
||||
import org.alfresco.rest.api.DeletedNodes;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.lookups.PropertyLookupRegistry;
|
||||
@@ -43,20 +42,20 @@ import org.alfresco.rest.api.search.context.FacetFieldContext.Bucket;
|
||||
import org.alfresco.rest.api.search.context.FacetQueryContext;
|
||||
import org.alfresco.rest.api.search.context.SearchContext;
|
||||
import org.alfresco.rest.api.search.context.SpellCheckContext;
|
||||
import org.alfresco.rest.api.search.model.FacetQuery;
|
||||
import org.alfresco.rest.api.search.model.HighlightEntry;
|
||||
import org.alfresco.rest.api.search.model.SearchEntry;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.ResultSetRow;
|
||||
import org.alfresco.service.cmr.search.SpellCheckResult;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -68,6 +67,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Maps from a ResultSet to a json public api representation.
|
||||
@@ -121,10 +121,10 @@ public class ResultMapper
|
||||
/**
|
||||
* Turns the results into a CollectionWithPagingInfo
|
||||
* @param params
|
||||
* @param results
|
||||
* @return CollectionWithPagingInfo<Node>
|
||||
* @param searchQuery
|
||||
*@param results @return CollectionWithPagingInfo<Node>
|
||||
*/
|
||||
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, ResultSet results)
|
||||
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, SearchQuery searchQuery, ResultSet results)
|
||||
{
|
||||
SearchContext context = null;
|
||||
Integer total = null;
|
||||
@@ -166,7 +166,7 @@ public class ResultMapper
|
||||
if (solrResultSet != null)
|
||||
{
|
||||
//We used Solr for this query
|
||||
context = toSearchContext(solrResultSet, notFound);
|
||||
context = toSearchContext(solrResultSet, searchQuery, notFound);
|
||||
total = setTotal(solrResultSet);
|
||||
}
|
||||
else
|
||||
@@ -260,9 +260,10 @@ public class ResultMapper
|
||||
/**
|
||||
* Uses the results from Solr to set the Search Context
|
||||
* @param SolrJSONResultSet
|
||||
* @param searchQuery
|
||||
* @return SearchContext
|
||||
*/
|
||||
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet, int notFound)
|
||||
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet, SearchQuery searchQuery, int notFound)
|
||||
{
|
||||
SearchContext context = null;
|
||||
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
|
||||
@@ -276,7 +277,13 @@ public class ResultMapper
|
||||
facetResults = new ArrayList<>(facetQueries.size());
|
||||
for (Entry<String, Integer> fq:facetQueries.entrySet())
|
||||
{
|
||||
facetResults.add(new FacetQueryContext(fq.getKey(), ":NOT_DONE", fq.getValue()));
|
||||
String filterQuery = null;
|
||||
if (searchQuery != null)
|
||||
{
|
||||
Optional<FacetQuery> found = searchQuery.getFacetQueries().stream().filter(facetQuery -> fq.getKey().equals(facetQuery.getLabel())).findFirst();
|
||||
if (found.isPresent()) filterQuery = found.get().getQuery();
|
||||
}
|
||||
facetResults.add(new FacetQueryContext(fq.getKey(), filterQuery, fq.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -54,6 +54,7 @@ import org.alfresco.rest.api.search.context.SpellCheckContext;
|
||||
import org.alfresco.rest.api.search.impl.ResultMapper;
|
||||
import org.alfresco.rest.api.search.impl.StoreMapper;
|
||||
import org.alfresco.rest.api.search.model.HighlightEntry;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
@@ -110,6 +111,8 @@ public class ResultMapperTests
|
||||
public static final String FROZEN_VER = "1.1";
|
||||
private static final long VERSIONED_ID = 521l;
|
||||
|
||||
private static SerializerTestHelper helper;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupTests() throws Exception
|
||||
{
|
||||
@@ -205,12 +208,14 @@ public class ResultMapperTests
|
||||
nodeVersionsRelation.setServiceRegistry(sr);
|
||||
nodeVersionsRelation.afterPropertiesSet();
|
||||
mapper.setNodeVersions(nodeVersionsRelation);
|
||||
|
||||
helper = new SerializerTestHelper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoResults() throws Exception
|
||||
{
|
||||
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS,new EmptyResultSet());
|
||||
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS, null, new EmptyResultSet());
|
||||
assertNotNull(collection);
|
||||
assertFalse(collection.hasMoreItems());
|
||||
assertTrue(collection.getTotalItems() < 1);
|
||||
@@ -221,7 +226,7 @@ public class ResultMapperTests
|
||||
public void testToCollectionWithPagingInfo() throws Exception
|
||||
{
|
||||
ResultSet results = mockResultset(Arrays.asList(514l), Arrays.asList(566l, VERSIONED_ID));
|
||||
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS,results);
|
||||
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS, null, results);
|
||||
assertNotNull(collectionWithPage);
|
||||
Long found = results.getNumberFound();
|
||||
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
|
||||
@@ -249,11 +254,13 @@ public class ResultMapperTests
|
||||
public void testToSearchContext() throws Exception
|
||||
{
|
||||
ResultSet results = mockResultset(Collections.emptyList(),Collections.emptyList());
|
||||
SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, 0);
|
||||
SearchQuery searchQuery = helper.searchQueryFromJson();
|
||||
SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchQuery, 0);
|
||||
assertEquals(34l, searchContext.getConsistency().getlastTxId());
|
||||
assertEquals(6, searchContext.getFacetQueries().size());
|
||||
// assertEquals("{!afts}creator:admin",searchContext.getFacetQueries().get(0).getLabel());
|
||||
// assertEquals(1,searchContext.getFacetQueries().get(0).getCount());
|
||||
assertEquals(0,searchContext.getFacetQueries().get(0).getCount());
|
||||
assertEquals("cm:created:bob",searchContext.getFacetQueries().get(0).getFilterQuery());
|
||||
assertEquals("small",searchContext.getFacetQueries().get(0).getLabel());
|
||||
assertEquals("searchInsteadFor",searchContext.getSpellCheck().getType());
|
||||
assertEquals(1,searchContext.getSpellCheck().getSuggestions().size());
|
||||
assertEquals("alfresco",searchContext.getSpellCheck().getSuggestions().get(0));
|
||||
@@ -319,13 +326,5 @@ public class ResultMapperTests
|
||||
ResultSet results = new SolrJSONResultSet(json,sp,nodeService, null, LimitBy.FINAL_SIZE, 10);
|
||||
return results;
|
||||
}
|
||||
/**
|
||||
private Params mockParams(SearchQuery searchQuery)
|
||||
{
|
||||
Params params = mock(Params.class);
|
||||
when(params.getInclude()).thenReturn(new ArrayList<String>());
|
||||
when(params.getPassedIn()).thenReturn(searchQuery);
|
||||
return params;
|
||||
}
|
||||
**/
|
||||
|
||||
}
|
||||
|
@@ -95,8 +95,8 @@ public class SearchQuerySerializerTests
|
||||
assertEquals(2, searchQuery.getFilterQueries().get(0).getTags().size());
|
||||
assertEquals("myquery2",searchQuery.getFilterQueries().get(1).getQuery());
|
||||
assertEquals(1, searchQuery.getFacetQueries().size());
|
||||
assertEquals("facquery",searchQuery.getFacetQueries().get(0).getQuery());
|
||||
assertEquals("facnoused",searchQuery.getFacetQueries().get(0).getLabel());
|
||||
assertEquals("cm:created:bob",searchQuery.getFacetQueries().get(0).getQuery());
|
||||
assertEquals("small",searchQuery.getFacetQueries().get(0).getLabel());
|
||||
assertEquals("alfrezco", searchQuery.getSpellcheck().getQuery());
|
||||
assertEquals(1, searchQuery.getScope().getLocations().size());
|
||||
assertEquals(StoreMapper.LIVE_NODES, searchQuery.getScope().getLocations().get(0));
|
||||
|
@@ -61,7 +61,7 @@ public class SerializerTestHelper implements RequestReader
|
||||
+ "\"defaults\": {\"namespace\": \"namesp\",\"defaultFieldName\": \"myfield\",\"defaultFTSOperator\": \"AND\", \"textAttributes\": [\"roy\", \"king\"]},"
|
||||
+ "\"filterQueries\": [{\"query\": \"myquery\",\"tags\": [\"tag1\", \"tag2\"]},{\"query\": \"myquery2\"}],"
|
||||
+ "\"facetFields\": {\"facets\": [{\"field\": \"cm:creator\",\"prefix\": \"myquery2\",\"sort\": \"COUNT\",\"missing\": \"false\"}, {\"field\": \"modifier\",\"label\": \"mylabel\",\"method\": \"FC\",\"mincount\": \"5\"}]},"
|
||||
+ "\"facetQueries\": [{\"query\": \"facquery\",\"label\": \"facnoused\"}],"
|
||||
+ "\"facetQueries\": [{\"query\": \"cm:created:bob\",\"label\": \"small\"}],"
|
||||
+ "\"facetIntervals\": {\"sets\": [{ \"label\": \"king\", \"start\": \"1\", \"end\": \"2\",\"startInclusive\": true,\"endInclusive\": false}]"
|
||||
+ ",\"intervals\": [{\"field\": \"creator\",\"label\": \"Creator\","
|
||||
+ "\"sets\": [{\"label\": \"bob\",\"start\": \"a\",\"end\": \"b\",\"startInclusive\": false}]"
|
||||
|
Reference in New Issue
Block a user