I have the following REST controller.
@RepositoryRestController
@RequestMapping(value = \"/booksCustom\")
public class BooksController extends ResourceSupport {
Ok, here is how I did it: I wrote mine HighlightPagedResources
public class HighlightPagedResources extends PagedResources {
private List> phrases;
public HighlightPagedResources(Collection content, PageMetadata metadata, List> highlightPhrases, Link... links) {
super(content, metadata, links);
this.phrases = highlightPhrases;
}
@JsonProperty("highlighting")
public List> getHighlightedPhrases() {
return phrases;
}
}
and HighlightPagedResourcesAssembler:
public class HighlightPagedResourcesAssembler extends PagedResourcesAssembler {
public HighlightPagedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, UriComponents baseUri) {
super(resolver, baseUri);
}
public HighlightPagedResources toResource(HighlightPage page, ResourceAssembler assembler) {
final PagedResources rs = super.toResource(page, assembler);
final Link[] links = new Link[rs.getLinks().size()];
return new HighlightPagedResources(rs.getContent(), rs.getMetadata(), page.getHighlighted(), rs.getLinks().toArray(links));
}
}
I had to add to my spring RepositoryRestMvcConfiguration.java:
@Primary
@Bean
public HighlightPagedResourcesAssembler solrPagedResourcesAssembler() {
return new HighlightPagedResourcesAssembler
In cotroller I had to change PagedResourcesAssembler for newly implemented one and also use new HighlightPagedResources in request method:
@Autowired
private HighlightPagedResourcesAssembler
RESULT:
{
"_embedded": {
"conversations": [
..our stuff..
]
},
"_links": {
...as you know them...
},
"page": {
"size": 1,
"totalElements": 25,
"totalPages": 25,
"number": 0
},
"highlighting": [
{
"entity": {
"conversationId": "a2127d01-747e-4312-b230-01c63dacac5a",
...
},
"highlights": [
{
"field": {
"name": "textBody"
},
"snipplets": [
"Additional XXX License for YYY Servers DCL-2016-PO0422 \n \nhi bodgan \n \nwe urgently need the",
"Additional XXX License for YYY Servers DCL-2016-PO0422\n \nhi bodgan\n \nwe urgently need the permanent"
]
}
]
}
]
}