Skip to content

Instantly share code, notes, and snippets.

@kgolebiowski
Created February 23, 2015 21:51
Show Gist options
  • Save kgolebiowski/b4a26f869a411fb701b7 to your computer and use it in GitHub Desktop.
Save kgolebiowski/b4a26f869a411fb701b7 to your computer and use it in GitHub Desktop.
package scripts.ddl
import com.liferay.portal.kernel.dao.orm.QueryUtil
import com.liferay.portal.kernel.search.*
import com.liferay.portal.kernel.util.GetterUtil
import com.liferay.portal.kernel.util.LocaleUtil
import com.liferay.portal.service.GroupLocalServiceUtil
import com.liferay.portal.util.PortalUtil
import com.liferay.portlet.dynamicdatalists.model.DDLRecord
import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil
import com.liferay.portlet.dynamicdatamapping.util.DDMIndexerUtil
def groupId = GroupLocalServiceUtil.getGroup(
PortalUtil.defaultCompanyId, "somesite")?.groupId
if(!groupId)
println "Group has not been found..."
else {
// This is the structure ID obtained from Control Panel
long structureId = 17802;
// The name of the field visible in Liferay's structure editor
String fieldName = "textfield";
// String we want to search for
String searchText = "foo";
Indexer indexer = IndexerRegistryUtil.getIndexer(DDLRecord.class.name);
SearchContext sc = new SearchContext([
companyId: PortalUtil.defaultCompanyId,
groupIds: groupId
]);
String testTextField = DDMIndexerUtil.encodeName(
structureId, fieldName, LocaleUtil.fromLanguageId("en_EN"));
BooleanClause testTextClause = BooleanClauseFactoryUtil.create(
sc, testTextField, searchText, BooleanClauseOccur.MUST.getName())
sc.setBooleanClauses(testTextClause)
sc.setStart(QueryUtil.ALL_POS);
sc.setEnd(QueryUtil.ALL_POS);
sc.setAttribute("paginationType", "none");
hits = indexer.search(sc);
println "Found ${hits.length} DDLRecords"
hits.toList().each { Document doc ->
println "\nFields stored in FT index:"
doc.fields.each { String key, Field value ->
println "${key} : ${value.value}"
}
println "\nDDLRecord dump: ${DDLRecordLocalServiceUtil.getDDLRecord(GetterUtil.getLong(doc.get("entryClassPK")))}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment