コード例 #1
0
  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);
    }
  }
コード例 #2
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);
    }
  }
コード例 #3
0
  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);
    }
  }