use of org.alfresco.rest.api.search.context.FacetQueryContext in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testIsNullContext.
@Test
public void testIsNullContext() throws Exception {
assertTrue(mapper.isNullContext(new SearchContext(0l, null, null, null, null, null)));
assertFalse(mapper.isNullContext(new SearchContext(1l, null, null, null, null, null)));
assertFalse(mapper.isNullContext(new SearchContext(0l, null, null, null, new SpellCheckContext(null, null), null)));
assertFalse(mapper.isNullContext(new SearchContext(0l, null, Arrays.asList(new FacetQueryContext(null, null, 0)), null, null, null)));
assertFalse(mapper.isNullContext(new SearchContext(0l, null, null, Arrays.asList(new FacetFieldContext(null, null)), null, null)));
assertFalse(mapper.isNullContext(new SearchContext(0l, Arrays.asList(new GenericFacetResponse(null, null, null)), null, null, null, null)));
}
use of org.alfresco.rest.api.search.context.FacetQueryContext in project alfresco-remote-api by Alfresco.
the class ResultMapper method toSearchContext.
/**
* Uses the results from Solr to set the Search Context
* @param SolrJSONResultSet
* @param searchQuery
* @return SearchContext
*/
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet, SearchRequestContext searchRequestContext, SearchQuery searchQuery, int notFound) {
SearchContext context = null;
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
List<GenericFacetResponse> facets = new ArrayList<>();
List<FacetQueryContext> facetResults = null;
SpellCheckContext spellCheckContext = null;
List<FacetFieldContext> ffcs = new ArrayList<FacetFieldContext>();
if (searchQuery == null) {
throw new IllegalArgumentException("searchQuery can't be null");
}
// Facet queries
if (facetQueries != null && !facetQueries.isEmpty()) {
// If group by field populated in query facet return bucketing into facet field.
List<GenericFacetResponse> facetQueryForFields = getFacetBucketsFromFacetQueries(facetQueries, searchQuery);
if (hasGroup(searchQuery) || FacetFormat.V2 == searchQuery.getFacetFormat()) {
facets.addAll(facetQueryForFields);
} else {
// Return the old way facet query with no bucketing.
facetResults = new ArrayList<>(facetQueries.size());
for (Entry<String, Integer> fq : facetQueries.entrySet()) {
String filterQuery = null;
if (searchQuery.getFacetQueries() != null) {
Optional<FacetQuery> found = searchQuery.getFacetQueries().stream().filter(facetQuery -> fq.getKey().equals(facetQuery.getLabel())).findFirst();
filterQuery = found.isPresent() ? found.get().getQuery() : fq.getKey();
}
facetResults.add(new FacetQueryContext(fq.getKey(), filterQuery, fq.getValue()));
}
}
}
// Field Facets
Map<String, List<Pair<String, Integer>>> facetFields = solrResultSet.getFieldFacets();
if (FacetFormat.V2 == searchQuery.getFacetFormat()) {
facets.addAll(getFacetBucketsForFacetFieldsAsFacets(facetFields, searchQuery));
} else {
ffcs.addAll(getFacetBucketsForFacetFields(facetFields, searchQuery));
}
Map<String, List<Pair<String, Integer>>> facetInterval = solrResultSet.getFacetIntervals();
facets.addAll(getGenericFacetsForIntervals(facetInterval, searchQuery));
Map<String, List<Map<String, String>>> facetRanges = solrResultSet.getFacetRanges();
facets.addAll(RangeResultMapper.getGenericFacetsForRanges(facetRanges, searchQuery.getFacetRanges()));
List<GenericFacetResponse> stats = getFieldStats(searchRequestContext, solrResultSet.getStats());
List<GenericFacetResponse> pimped = getPivots(searchRequestContext, solrResultSet.getPivotFacets(), stats);
facets.addAll(pimped);
facets.addAll(stats);
// Spelling
SpellCheckResult spell = solrResultSet.getSpellCheckResult();
if (spell != null && spell.getResultName() != null && !spell.getResults().isEmpty()) {
spellCheckContext = new SpellCheckContext(spell.getResultName(), spell.getResults());
}
// Put it all together
context = new SearchContext(solrResultSet.getLastIndexedTxId(), facets, facetResults, ffcs, spellCheckContext, searchRequestContext.includeRequest() ? searchQuery : null);
return isNullContext(context) ? null : context;
}
use of org.alfresco.rest.api.search.context.FacetQueryContext in project alfresco-remote-api by Alfresco.
the class SearchQuerySerializerTests method testSerializeContext.
@Test
public void testSerializeContext() throws IOException {
ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", "name:b1", 23, "displayText1"), new Bucket("b2", null, 34, "displayText2"), new Bucket("", null, 42, "displayText3")));
SearchContext searchContext = new SearchContext(23l, null, Arrays.asList(new FacetQueryContext("f1", "creator:bob", 15), new FacetQueryContext("f2", null, 20)), Arrays.asList(ffc), new SpellCheckContext("aFlag", Arrays.asList("bish", "bash")), null);
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
String out = helper.writeResponse(coll);
assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}"));
assertTrue("There must 'facetQueries' json output", out.contains("\"facetQueries\":"));
assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"filterQuery\":\"creator:bob\",\"count\":15}"));
assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}"));
assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}"));
assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":[{\"label\":\"theLabel\",\"buckets\""));
assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"filterQuery\":\"name:b1\",\"count\":23,\"display\":\"displayText1\"}"));
assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34,\"display\":\"displayText2\"}"));
assertTrue("There must 'bucket3' json output", out.contains("{\"label\":\"\",\"count\":42,\"display\":\"displayText3\"}"));
searchContext = new SearchContext(-1, null, null, null, null, null);
coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
out = helper.writeResponse(coll);
assertTrue("There must NOT BE a 'context' json output", out.contains("\"context\":{}"));
assertFalse("There must NOT BE a 'facetsFields' json output", out.contains("\"facetsFields\":{}"));
}
Aggregations