Search in sources :

Example 1 with FacetConfiguration

use of com.liferay.portal.kernel.search.facet.config.FacetConfiguration in project liferay-ide by liferay.

the class AssetEntriesFacet method initFacetClause.

protected void initFacetClause() {
    SearchContext searchContext = getSearchContext();
    FacetConfiguration facetConfiguration = getFacetConfiguration();
    JSONObject dataJSONObject = facetConfiguration.getData();
    String[] entryClassNames = null;
    if (dataJSONObject.has("values")) {
        JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values");
        entryClassNames = new String[valuesJSONArray.length()];
        for (int i = 0; i < valuesJSONArray.length(); i++) {
            entryClassNames[i] = valuesJSONArray.getString(i);
        }
    }
    if (ArrayUtil.isEmpty(entryClassNames)) {
        entryClassNames = searchContext.getEntryClassNames();
    }
    if (!isStatic()) {
        String[] entryClassNameParam = StringUtil.split(GetterUtil.getString(searchContext.getAttribute(getFieldName())));
        if (ArrayUtil.isNotEmpty(entryClassNameParam)) {
            entryClassNames = entryClassNameParam;
        }
    }
    if (ArrayUtil.isEmpty(entryClassNames)) {
        entryClassNames = SearchEngineUtil.getEntryClassNames();
        if (!dataJSONObject.has("values")) {
            JSONArray entriesJSONArray = JSONFactoryUtil.createJSONArray();
            for (String entryClassName : entryClassNames) {
                entriesJSONArray.put(entryClassName);
            }
            dataJSONObject.put("values", entriesJSONArray);
        }
    }
    searchContext.setEntryClassNames(entryClassNames);
}
Also used : FacetConfiguration(com.liferay.portal.kernel.search.facet.config.FacetConfiguration) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) SearchContext(com.liferay.portal.kernel.search.SearchContext)

Aggregations

JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 SearchContext (com.liferay.portal.kernel.search.SearchContext)1 FacetConfiguration (com.liferay.portal.kernel.search.facet.config.FacetConfiguration)1