@Override
  public void postProcessContextBooleanFilter(
      BooleanFilter booleanFilter, SearchContext searchContext) throws Exception {

    LinkedHashMap<String, Object> params =
        (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
      Object projectTitles = params.get("projectTitles");

      if (Validator.isNotNull(projectTitles)) {
        booleanFilter.addRequiredTerm("projectTitles", String.valueOf(projectTitles));
      }

      Object socialRelationType = params.get("socialRelationType");

      if (Validator.isNotNull(socialRelationType)) {
        Long[] socialRelationTypeValues = (Long[]) socialRelationType;

        booleanFilter.addRequiredTerm("socialRelationships", socialRelationTypeValues[0]);
      }
    }
  }
  @Override
  public void postProcessContextBooleanFilter(
      BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if ((classNameId != null) && (classNameId != 0)) {
      contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId.toString());
    }

    addStatus(contextBooleanFilter, searchContext);

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      QueryFilter queryFilter =
          _ddmIndexer.createFieldValueQueryFilter(
              ddmStructureFieldName, ddmStructureFieldValue, searchContext.getLocale());

      contextBooleanFilter.add(queryFilter, BooleanClauseOccur.MUST);
    }

    String ddmStructureKey = (String) searchContext.getAttribute("ddmStructureKey");

    if (Validator.isNotNull(ddmStructureKey)) {
      contextBooleanFilter.addRequiredTerm("ddmStructureKey", ddmStructureKey);
    }

    String ddmTemplateKey = (String) searchContext.getAttribute("ddmTemplateKey");

    if (Validator.isNotNull(ddmTemplateKey)) {
      contextBooleanFilter.addRequiredTerm("ddmTemplateKey", ddmTemplateKey);
    }

    boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE);
    boolean relatedClassName =
        GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName"));
    boolean showNonindexable =
        GetterUtil.getBoolean(searchContext.getAttribute("showNonindexable"));

    if (head && !relatedClassName && !showNonindexable) {
      contextBooleanFilter.addRequiredTerm("head", Boolean.TRUE);
    }

    if (!relatedClassName && showNonindexable) {
      contextBooleanFilter.addRequiredTerm("headListable", Boolean.TRUE);
    }
  }
  @Override
  public void postProcessContextBooleanFilter(
      BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception {

    addStatus(contextBooleanFilter, searchContext);

    if (searchContext.isIncludeAttachments()) {
      addRelatedClassNames(contextBooleanFilter, searchContext);
    }

    if (ArrayUtil.contains(
        searchContext.getFolderIds(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      contextBooleanFilter.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());
    }

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, DDMIndexer.DDM_FIELD_SEPARATOR);

      DDMStructure structure =
          DDMStructureLocalServiceUtil.getStructure(
              GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      try {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      } catch (StructureFieldException sfe) {
        if (_log.isDebugEnabled()) {
          _log.debug(sfe, sfe);
        }
      }

      BooleanQuery booleanQuery = new BooleanQueryImpl();

      booleanQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);

      contextBooleanFilter.add(new QueryFilter(booleanQuery));
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanFilter mimeTypesBooleanFilter = new BooleanFilter();

      for (String mimeType : mimeTypes) {
        mimeTypesBooleanFilter.addTerm(
            "mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      }

      contextBooleanFilter.add(mimeTypesBooleanFilter, BooleanClauseOccur.MUST);
    }
  }
  @Override
  public void postProcessContextBooleanFilter(
      BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if ((classNameId != null) && (classNameId != 0)) {
      contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId.toString());
    }

    addStatus(contextBooleanFilter, searchContext);

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, DDMIndexer.DDM_FIELD_SEPARATOR);

      DDMStructure structure =
          _ddmStructureLocalService.getStructure(GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      if (structure.hasField(fieldName)) {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      }

      BooleanQuery booleanQuery = new BooleanQueryImpl();

      booleanQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);

      contextBooleanFilter.add(new QueryFilter(booleanQuery));
    }

    String articleType = (String) searchContext.getAttribute("articleType");

    if (Validator.isNotNull(articleType)) {
      contextBooleanFilter.addRequiredTerm(Field.TYPE, articleType);
    }

    String ddmStructureKey = (String) searchContext.getAttribute("ddmStructureKey");

    if (Validator.isNotNull(ddmStructureKey)) {
      contextBooleanFilter.addRequiredTerm("ddmStructureKey", ddmStructureKey);
    }

    String ddmTemplateKey = (String) searchContext.getAttribute("ddmTemplateKey");

    if (Validator.isNotNull(ddmTemplateKey)) {
      contextBooleanFilter.addRequiredTerm("ddmTemplateKey", ddmTemplateKey);
    }

    boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE);
    boolean relatedClassName =
        GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName"));

    if (head && !relatedClassName) {
      contextBooleanFilter.addRequiredTerm("head", Boolean.TRUE);
    }
  }