Getting Custom fields from Confluence V2 Searches
If you use an extractor module in your Confluence plugin to add additional information to the Lucene search index there is currently no way to access these fields using the V2 Search API. You can use these fields in custom search queries or sorts, but actually reading these fields from the returned data is not possible with the current API.
Limitations of the Current API
When you do a search using the V2 Search API the
SearchManager.search(..) method Confluence will give you back a SearchResults object. You can then retrieve each of the individual
SearchResult objects that matched your search.
SearchResult interface contains a
getExtraFields() method which is supposed to return additional fields that cannot be directly accessed by this interface. Unfortunately the
LuceneSearchResult implementation has hardcoded the fields that are returned. This means that if you have an extractor module that has added custom fields to the index they can not be retrieved using the SearchResult interface.
Wrapping the SearchResult Object with custom implementation
If you look at the source code for the LuceneSearchResult class, you will see that all of the index document fields are stored in a private map called results. You can use java reflection to get access to this field within your own plugin classes.
The following example wraps the
LuceneSearchResult providing access to the internal results field.