I'm trying to develop a custom web content search portlet for Liferay 7.3.5 GA6, using SearchContext, IndexSearcherHelperUtil and all the other stuff.
I have some DDMStructure with different fields and, from what I've seen on the elasticsearch index, this fields are indexed in a nested document, like this:
"ddmFieldArray": [
{
"ddmFieldName": "ddm__text__37702__nome_it_IT",
"ddmValueFieldName": "ddmFieldValueText_it_IT",
"ddmFieldValueText_it_IT": "Nome esempio",
"ddmFieldValueText_it_IT_String_sortable": "nome esempio"
}
,
{
"ddmFieldName": "ddm__text__37702__descrizione_breve_it_IT",
"ddmValueFieldName": "ddmFieldValueText_it_IT",
"ddmFieldValueText_it_IT": "Esempio di descrizione breve da indicizzare",
"ddmFieldValueText_it_IT_String_sortable": "esempio di descrizione breve da indicizzare"
}
]
which is different from the old way I used to know, where the custom fields were indexed like ddm__[keyword/text]__[structure_id]__[field_name]
Now, I understand this different way of indexing is due to an improvement to avoid elastic issues (Limit of total fields has been exceeded) but...After executing the search, there is no ddmFieldArray in the com.liferay.portal.kernel.search.Document .getFields, so I'm unable to get the ddmstructure fields values from the elastic search index.
Here's the code:
long journalArticleClassId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class.getName());
SearchContext searchContext = new SearchContext();
searchContext.setClassTypeIds(new long[] {journalArticleClassId});
searchContext.setCompanyId(companyId);
searchContext.setStart(QueryUtil.ALL_POS);
searchContext.setEnd(QueryUtil.ALL_POS);
BooleanQuery query = new BooleanQueryImpl();
MatchQuery approvedQuery = new MatchQuery(Field.STATUS, String.valueOf(WorkflowConstants.STATUS_APPROVED));
query.add(approvedQuery, BooleanClauseOccur.MUST.getName());
Hits resultHits = IndexSearcherHelperUtil.search(searchContext, query);
for (Document doc: resultHits.getDocs()) {
doc.getFields().forEach((k, v) -> _log.debug(k)); //No ddm structure field
}
Is this still an improvement or just an unexpected behaviour?
Any way to solve or extend this?
Thanks