public Hits search(
      long companyId,
      long[] groupIds,
      long userId,
      String className,
      String keywords,
      int status,
      int start,
      int end)
      throws SystemException {

    try {
      SearchContext searchContext = new SearchContext();

      Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);

      assetEntriesFacet.setStatic(true);

      searchContext.addFacet(assetEntriesFacet);

      Facet scopeFacet = new ScopeFacet(searchContext);

      scopeFacet.setStatic(true);

      searchContext.addFacet(scopeFacet);

      searchContext.setAttribute("paginationType", "regular");
      searchContext.setAttribute("status", status);
      searchContext.setCompanyId(companyId);
      searchContext.setEnd(end);
      searchContext.setEntryClassNames(getClassNames(className));
      searchContext.setGroupIds(groupIds);
      searchContext.setKeywords(keywords);

      QueryConfig queryConfig = new QueryConfig();

      queryConfig.setHighlightEnabled(false);
      queryConfig.setScoreEnabled(false);

      searchContext.setQueryConfig(queryConfig);

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

      Indexer indexer = FacetedSearcher.getInstance();

      return indexer.search(searchContext);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
Ejemplo n.º 2
0
  protected void testUserPermissions(
      boolean addBaseModelPermission, boolean addParentBaseModelPermission) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    serviceContext.setAddGroupPermissions(addParentBaseModelPermission);
    serviceContext.setAddGuestPermissions(addParentBaseModelPermission);

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    serviceContext.setAddGroupPermissions(addBaseModelPermission);
    serviceContext.setAddGuestPermissions(addBaseModelPermission);

    baseModel = addBaseModel(parentBaseModel, true, getSearchKeywords(), serviceContext);

    User user = UserTestUtil.addUser(null, 0);

    PermissionChecker originalPermissionChecker = PermissionThreadLocal.getPermissionChecker();

    try {
      PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

      PermissionThreadLocal.setPermissionChecker(permissionChecker);

      searchContext.setUserId(user.getUserId());

      int baseModelsCount = initialBaseModelsSearchCount;

      if (addBaseModelPermission && !isCheckBaseModelPermission()) {
        baseModelsCount++;
      }

      Assert.assertEquals(
          baseModelsCount,
          searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
    } finally {
      PermissionThreadLocal.setPermissionChecker(originalPermissionChecker);
    }
  }
  @Override
  public Hits search(
      long groupId,
      long userId,
      long creatorUserId,
      long startDate,
      long endDate,
      int status,
      int start,
      int end)
      throws PortalException {

    Indexer<MBThread> indexer = IndexerRegistryUtil.getIndexer(MBThread.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (endDate > 0) {
      searchContext.setAttribute("endDate", endDate);
    }

    searchContext.setAttribute("paginationType", "none");

    if (creatorUserId > 0) {
      searchContext.setAttribute("participantUserId", String.valueOf(creatorUserId));
    }

    if (startDate > 0) {
      searchContext.setAttribute("startDate", startDate);
    }

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] {groupId});
    searchContext.setSorts(new Sort("lastPostDate", true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    return indexer.search(searchContext);
  }
Ejemplo n.º 4
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);
    }
  }
  public Hits search(
      long companyId,
      long[] groupIds,
      long userId,
      String className,
      String userName,
      String title,
      String description,
      String assetCategoryIds,
      String assetTagNames,
      int status,
      boolean andSearch,
      int start,
      int end)
      throws SystemException {

    try {
      SearchContext searchContext = new SearchContext();

      Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);

      assetEntriesFacet.setStatic(true);

      searchContext.addFacet(assetEntriesFacet);

      Facet scopeFacet = new ScopeFacet(searchContext);

      scopeFacet.setStatic(true);

      searchContext.addFacet(scopeFacet);

      searchContext.setAndSearch(andSearch);
      searchContext.setAssetCategoryIds(StringUtil.split(assetCategoryIds, 0L));
      searchContext.setAssetTagNames(StringUtil.split(assetTagNames));
      searchContext.setAttribute(Field.DESCRIPTION, description);
      searchContext.setAttribute(Field.TITLE, title);
      searchContext.setAttribute(Field.USER_NAME, userName);
      searchContext.setAttribute("paginationType", "regular");
      searchContext.setAttribute("status", status);
      searchContext.setCompanyId(companyId);
      searchContext.setEnd(end);
      searchContext.setEntryClassNames(getClassNames(className));
      searchContext.setGroupIds(groupIds);

      QueryConfig queryConfig = new QueryConfig();

      queryConfig.setHighlightEnabled(false);
      queryConfig.setScoreEnabled(false);

      searchContext.setQueryConfig(queryConfig);

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

      Indexer indexer = FacetedSearcher.getInstance();

      return indexer.search(searchContext);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }