@Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

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

    if (classNameId != null) {
      contextQuery.addRequiredTerm("classNameId", classNameId.toString());
    }

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
      if (folderIds[0] == JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return;
      }

      BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long folderId : folderIds) {
        try {
          JournalFolderServiceUtil.getFolder(folderId);
        } catch (Exception e) {
          continue;
        }

        folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
      }

      contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }

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

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

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

    if (Validator.isNotNull(structureId)) {
      contextQuery.addRequiredTerm("structureId", structureId);
    }

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

    if (Validator.isNotNull(templateId)) {
      contextQuery.addRequiredTerm("templateId", templateId);
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    addStatus(contextQuery, searchContext);

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

    contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());

    addSearchClassTypeIds(contextQuery, searchContext);

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

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

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

      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) {
      }

      contextQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

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

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext);

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

      contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST);
    }
  }
  @Override
  protected void addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return;
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return;
    }

    field = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    if (searchContext.isAndSearch()) {
      searchQuery.addRequiredTerm(field, value, like);
    } else {
      searchQuery.addTerm(field, value, like);
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
      if (folderIds[0] == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return;
      }

      BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long folderId : folderIds) {
        try {
          BookmarksFolderServiceUtil.getFolder(folderId);
        } catch (Exception e) {
          continue;
        }

        folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
      }

      contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    addStatus(contextQuery, searchContext);

    contextQuery.addRequiredTerm(Field.HIDDEN, false);
  }
  @Override
  protected void addSearchLayout(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    String layoutUuid = (String) searchContext.getAttribute(Field.LAYOUT_UUID);

    if (Validator.isNotNull(layoutUuid)) {
      contextQuery.addRequiredTerm(Field.LAYOUT_UUID, layoutUuid);
    }
  }
  public Hits search(
      long companyId,
      String keywords,
      String sortField,
      int sortType,
      boolean reverse,
      int start,
      int end)
      throws SystemException {
    try {
      BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
      contextQuery.addRequiredTerm(Field.COMPANY_ID, companyId);

      if (Validator.isNotNull(ContactBookIndexer.PORTLET_ID)) {
        contextQuery.addRequiredTerm(Field.PORTLET_ID, ContactBookIndexer.PORTLET_ID);
      }

      BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

      if (Validator.isNotNull(keywords)) {
        searchQuery.addTerm(Field.TITLE, keywords);
        searchQuery.addTerm("contactBookCode", keywords + "*");
        searchQuery.addTerm("contactBookName", keywords + "*");
        searchQuery.addTerm("contactDescription", keywords + "*");
      }

      BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
      fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

      if (searchQuery.clauses().size() > 0) {
        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
      }

      Sort sort;
      sort = new Sort(sortField, sortType, reverse);
      Hits hits = SearchEngineUtil.search(companyId, fullQuery, sort, start, end);
      return hits;
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  public Hits search(
      long companyId,
      String contactBookCode,
      String contactBookName,
      String contactDescription,
      String sortField,
      int sortType,
      boolean reverse,
      int start,
      int end)
      throws SystemException {
    try {
      BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
      contextQuery.addRequiredTerm(Field.PORTLET_ID, ContactBookIndexer.PORTLET_ID);

      BooleanQuery contactBookCodeQuery = BooleanQueryFactoryUtil.create();
      BooleanQuery contactBookNameQuery = BooleanQueryFactoryUtil.create();
      BooleanQuery contactDescriptionQuery = BooleanQueryFactoryUtil.create();

      List<BooleanQuery> booleanQueries = new ArrayList<BooleanQuery>();

      if (Validator.isNotNull(contactBookCode)) {
        contactBookCodeQuery.addTerm(ContactBookDisplayTerms.CODE, contactBookCode);
        booleanQueries.add(contactBookCodeQuery);
      }

      if (Validator.isNotNull(contactBookName)) {
        contactBookNameQuery.addTerm(ContactBookDisplayTerms.NAME, contactBookName);
        booleanQueries.add(contactBookNameQuery);
      }

      if (Validator.isNotNull(contactDescription)) {
        contactDescriptionQuery.addTerm(ContactBookDisplayTerms.DESCRIPTION, contactDescription);
        booleanQueries.add(contactDescriptionQuery);
      }

      BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
      fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

      for (int i = 0; i < booleanQueries.size(); i++) {
        fullQuery.add(booleanQueries.get(i), BooleanClauseOccur.MUST);
      }

      Sort sort;
      sort = new Sort(sortField, sortType, reverse);
      Hits hits = SearchEngineUtil.search(companyId, fullQuery, sort, start, end);
      return hits;
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

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

    if (classNameId != null) {
      contextQuery.addRequiredTerm("classNameId", classNameId.toString());
    }

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }

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

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

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

    if (Validator.isNotNull(structureId)) {
      contextQuery.addRequiredTerm("structureId", structureId);
    }

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

    if (Validator.isNotNull(templateId)) {
      contextQuery.addRequiredTerm("templateId", templateId);
    }
  }
  public List<Document> searchAllDocuments(
      SearchContext searchContext,
      List<Query> filterQueries,
      long companyId,
      Sort sort,
      int start,
      int end) {

    LOGGER.info("FilterQueries size: " + filterQueries.size());
    final BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
    final BooleanQuery allEntriesBooleanQuery = BooleanQueryFactoryUtil.create(searchContext);

    allEntriesBooleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, EmpDiscipline.class.getName());

    try {
      // add filter queries
      fullQuery.add(allEntriesBooleanQuery, BooleanClauseOccur.MUST);
      if (filterQueries != null && filterQueries.size() > 0) {
        for (Query query : filterQueries) {
          fullQuery.add(query, BooleanClauseOccur.MUST);
        }
      }

      final List<Document> documents =
          SearchEngineUtil.search(
                  SearchEngineUtil.getDefaultSearchEngineId(),
                  companyId,
                  fullQuery,
                  sort,
                  start,
                  end)
              .toList();
      LOGGER.info("RESULT SIZE: " + documents.size());

      return documents;

    } catch (SearchException e) {
      LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e);
    } catch (ParseException e) {
      LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e);
    }
    return new ArrayList<>();
  }
  public Document getIndexedDocument(long id, SearchContext searchContext) {
    searchContext.setPortletIds(new String[] {EMInfo.PORTLET_ID});
    BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
    BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);
    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, EmpDiscipline.class.getName());
    booleanQuery.addExactTerm(EmpDisciplineField.ID, id);

    try {
      fullQuery.add(booleanQuery, BooleanClauseOccur.MUST);
      Hits hits = SearchEngineUtil.search(searchContext, fullQuery);
      return !hits.toList().isEmpty() ? hits.toList().get(0) : null;
    } catch (ParseException e) {
      LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e);
    } catch (SearchException e) {
      LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e);
    }

    return null;
  }
示例#12
0
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }

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

    if (params == null) {
      return;
    }

    for (Map.Entry<String, Object> entry : params.entrySet()) {
      String key = entry.getKey();
      Object value = entry.getValue();

      if (value == null) {
        continue;
      }

      Class<?> clazz = value.getClass();

      if (clazz.isArray()) {
        Object[] values = (Object[]) value;

        if (values.length == 0) {
          continue;
        }
      }

      addContextQueryParams(contextQuery, searchContext, key, value);
    }
  }
示例#13
0
  protected void addContextQueryParams(
      BooleanQuery contextQuery, SearchContext searchContext, String key, Object value)
      throws Exception {

    if (key.equals("usersGroups")) {
      if (value instanceof Long[]) {
        Long[] values = (Long[]) value;

        BooleanQuery usersGroupsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long groupId : values) {
          usersGroupsQuery.addTerm("groupIds", groupId);
        }

        contextQuery.add(usersGroupsQuery, BooleanClauseOccur.MUST);
      } else {
        contextQuery.addRequiredTerm("groupIds", String.valueOf(value));
      }
    } else if (key.equals("usersOrgs")) {
      if (value instanceof Long[]) {
        Long[] values = (Long[]) value;

        BooleanQuery usersOrgsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long organizationId : values) {
          usersOrgsQuery.addTerm("organizationIds", organizationId);
          usersOrgsQuery.addTerm("ancestorOrganizationIds", organizationId);
        }

        contextQuery.add(usersOrgsQuery, BooleanClauseOccur.MUST);
      } else {
        contextQuery.addRequiredTerm("organizationIds", String.valueOf(value));
      }
    } else if (key.equals("usersOrgsCount")) {
      contextQuery.addRequiredTerm("organizationCount", String.valueOf(value));
    } else if (key.equals("usersRoles")) {
      contextQuery.addRequiredTerm("roleIds", String.valueOf(value));
    } else if (key.equals("usersTeams")) {
      contextQuery.addRequiredTerm("teamIds", String.valueOf(value));
    } else if (key.equals("usersUserGroups")) {
      contextQuery.addRequiredTerm("userGroupIds", String.valueOf(value));
    }
  }
  @Override
  protected void doDelete(Object obj) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(getSearchEngineId());

    if (obj instanceof Account) {
      Account account = (Account) obj;

      BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

      booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

      booleanQuery.addRequiredTerm("accountId", account.getAccountId());

      Hits hits =
          SearchEngineUtil.search(
              getSearchEngineId(),
              account.getCompanyId(),
              booleanQuery,
              QueryUtil.ALL_POS,
              QueryUtil.ALL_POS);

      for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        SearchEngineUtil.deleteDocument(
            getSearchEngineId(), account.getCompanyId(), document.get(Field.UID));
      }
    } else if (obj instanceof Folder) {
      Folder folder = (Folder) obj;

      BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

      booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

      booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

      Hits hits =
          SearchEngineUtil.search(
              getSearchEngineId(),
              folder.getCompanyId(),
              booleanQuery,
              QueryUtil.ALL_POS,
              QueryUtil.ALL_POS);

      for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        SearchEngineUtil.deleteDocument(
            getSearchEngineId(), folder.getCompanyId(), document.get(Field.UID));
      }
    } else if (obj instanceof Message) {
      Message message = (Message) obj;

      Document document = new DocumentImpl();

      document.addUID(PORTLET_ID, message.getMessageId());

      SearchEngineUtil.deleteDocument(
          getSearchEngineId(), message.getCompanyId(), document.get(Field.UID));
    }
  }
  @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);
    }
  }
示例#16
0
  public Hits search(
      long companyId,
      long userId,
      String portletId,
      long groupId,
      long[] repositoryIds,
      String keywords,
      int start,
      int end) {

    try {
      SearchContext searchContext = new SearchContext();

      searchContext.setCompanyId(companyId);
      searchContext.setEnd(end);
      searchContext.setEntryClassNames(new String[] {DLFileEntryConstants.getClassName()});
      searchContext.setGroupIds(new long[] {groupId});

      Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

      searchContext.setSearchEngineId(indexer.getSearchEngineId());

      searchContext.setStart(start);
      searchContext.setUserId(userId);

      BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);

      contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);

      if (groupId > 0) {
        Group group = groupLocalService.getGroup(groupId);

        if (group.isLayout()) {
          contextQuery.addRequiredTerm(Field.SCOPE_GROUP_ID, groupId);

          groupId = group.getParentGroupId();
        }

        contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
      }

      if (ArrayUtil.isNotEmpty(repositoryIds)) {
        BooleanQuery repositoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long repositoryId : repositoryIds) {
          try {
            if (userId > 0) {
              PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

              DLFolderPermission.check(permissionChecker, groupId, repositoryId, ActionKeys.VIEW);
            }

            if (repositoryId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

              repositoryId = groupId;
            }

            TermQuery termQuery =
                TermQueryFactoryUtil.create(searchContext, "repositoryId", repositoryId);

            repositoryIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
          } catch (Exception e) {
          }
        }

        contextQuery.add(repositoryIdsQuery, BooleanClauseOccur.MUST);
      }

      BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

      searchQuery.addTerms(_KEYWORDS_FIELDS, keywords);

      BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);

      fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

      List<BooleanClause> clauses = searchQuery.clauses();

      if (!clauses.isEmpty()) {
        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
      }

      return SearchEngineUtil.search(searchContext, fullQuery);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  @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);
    }
  }
示例#18
0
  @Override
  protected void postProcessFullQuery(BooleanQuery fullQuery, SearchContext searchContext)
      throws Exception {

    fullQuery.addRequiredTerm("visible", true);
  }
  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);
  }