public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { if (_log.isDebugEnabled()) { _log.debug(" postProcessContextQuery()"); } Map<String, Object> params = (Map<String, Object>) searchContext.getAttribute("params"); if (params == null) { return; } Map<String, Serializable> searchByFields = (Map<String, Serializable>) params.get(SampleConstants.STRUCTURE_FIELDS); String structureKey = (String) params.get(SampleConstants.STRUCTURE_KEY); Long groupId = (Long) params.get(SampleConstants.STRUCTURE_GROUP_ID); Locale locale = searchContext.getLocale(); DDMStructure structure = DDMStructureLocalServiceUtil.fetchStructure( groupId, PortalUtil.getClassNameId(JournalArticle.class), structureKey, true); if (!isCustomSearch(structure, groupId, searchByFields)) { return; } for (String fieldName : searchByFields.keySet()) { try { Serializable value = searchByFields.get(fieldName); String indexType = structure.getFieldProperty(fieldName, "indexType"); if (Validator.isNull(indexType)) { if (_log.isDebugEnabled()) { _log.debug("fieldName " + fieldName + " is not indexable"); } continue; } // some types are stored in a special way try { value = DDMUtil.getIndexedFieldValue(value, structure.getFieldType(fieldName)); } catch (StructureFieldException sfe) { _log.error(sfe); continue; } contextQuery.addRequiredTerm( DDMIndexerUtil.encodeName(structure.getStructureId(), fieldName, locale), StringPool.QUOTE + value + StringPool.QUOTE); } catch (Exception e) { _log.error("Error processing custom search", e); } } _log.debug(contextQuery); }
public AssetEntryQuery getAssetEntryQuery() throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); long[] groupIds = getGroupIds(); if (!ArrayUtil.contains(groupIds, themeDisplay.getScopeGroupId())) { groupIds = ArrayUtil.append(groupIds, themeDisplay.getScopeGroupId()); } AssetEntryQuery assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(_portletPreferences, groupIds); long[] classNameIds = getClassNameIds(); long[] classTypeIds = getClassTypeIds(); if (isSubtypeFieldsFilterEnabled() && (classNameIds.length == 1) && (classTypeIds.length == 1) && Validator.isNotNull(getDDMStructureFieldName()) && Validator.isNotNull(getDDMStructureFieldValue())) { AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName( PortalUtil.getClassName(classNameIds[0])); Tuple classTypeFieldName = assetRendererFactory.getClassTypeFieldName( classTypeIds[0], getDDMStructureFieldName(), themeDisplay.getLocale()); long ddmStructureId = GetterUtil.getLong(classTypeFieldName.getObject(3)); assetEntryQuery.setAttribute( "ddmStructureFieldName", DDMIndexerUtil.encodeName( ddmStructureId, getDDMStructureFieldName(), themeDisplay.getLocale())); assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue()); } AssetPublisherUtil.processAssetEntryQuery( themeDisplay.getUser(), _portletPreferences, assetEntryQuery); assetEntryQuery.setAllCategoryIds(getAllAssetCategoryIds()); if (hasLayoutGroup(groupIds)) { assetEntryQuery.setAllTagIds( AssetTagLocalServiceUtil.getTagIds(groupIds, getAllAssetTagNames())); } else { assetEntryQuery.setAllTagIds( AssetTagLocalServiceUtil.getTagIds(getGroupIds(), getAllAssetTagNames())); } assetEntryQuery.setClassTypeIds(classTypeIds); assetEntryQuery.setEnablePermissions(isEnablePermissions()); assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount()); String portletName = getPortletName(); if (!portletName.equals(PortletKeys.RELATED_ASSETS)) { assetEntryQuery.setGroupIds(getGroupIds()); } if (isShowOnlyLayoutAssets()) { assetEntryQuery.setLayout(themeDisplay.getLayout()); } if (portletName.equals(PortletKeys.RELATED_ASSETS)) { AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY); if (layoutAssetEntry != null) { assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId()); } } assetEntryQuery.setPaginationType(getPaginationType()); assetEntryQuery.setOrderByCol1(getOrderByColumn1()); assetEntryQuery.setOrderByCol2(getOrderByColumn2()); assetEntryQuery.setOrderByType1(getOrderByType1()); assetEntryQuery.setOrderByType2(getOrderByType2()); return assetEntryQuery; }