/** * Append highlighting parameters to {@link SolrQuery} * * @param solrQuery * @param query */ protected void processHighlightOptions(SolrQuery solrQuery, HighlightQuery query) { if (query.hasHighlightOptions()) { HighlightOptions highlightOptions = query.getHighlightOptions(); solrQuery.setHighlight(true); if (!highlightOptions.hasFields()) { solrQuery.addHighlightField(HighlightOptions.ALL_FIELDS.getName()); } else { for (Field field : highlightOptions.getFields()) { solrQuery.addHighlightField(field.getName()); } for (FieldWithHighlightParameters fieldWithHighlightParameters : highlightOptions.getFieldsWithHighlightParameters()) { addPerFieldHighlightParameters(solrQuery, fieldWithHighlightParameters); } } for (HighlightParameter option : highlightOptions.getHighlightParameters()) { addOptionToSolrQuery(solrQuery, option); } if (highlightOptions.hasQuery()) { solrQuery.add(HighlightParams.Q, getQueryString(highlightOptions.getQuery())); } } }
@Override public <T> HighlightPage<T> queryForHighlightPage(HighlightQuery query, Class<T> clazz) { Assert.notNull(query, "Query must not be 'null'."); Assert.notNull(clazz, "Target class must not be 'null'."); QueryResponse response = query(query); List<T> beans = convertQueryResponseToBeans(response, clazz); SolrDocumentList results = response.getResults(); SolrResultPage<T> page = new SolrResultPage<T>( beans, query.getPageRequest(), results.getNumFound(), results.getMaxScore()); ResultHelper.convertAndAddHighlightQueryResponseToResultPage(response, page); return page; }