use of org.alfresco.service.cmr.search.SpellCheckResult 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;
}
Aggregations