protected SearchContext buildSearchContext(
      long companyId,
      long[] groupIds,
      String title,
      long[] parentCategoryIds,
      long[] vocabularyIds,
      int start,
      int end,
      Sort sort) {

    SearchContext searchContext = new SearchContext();

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ASSET_PARENT_CATEGORY_IDS, parentCategoryIds);
    attributes.put(Field.ASSET_VOCABULARY_IDS, vocabularyIds);
    attributes.put(Field.TITLE, title);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setGroupIds(groupIds);
    searchContext.setKeywords(title);
    searchContext.setSorts(sort);
    searchContext.setStart(start);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    return searchContext;
  }
  protected SearchContext buildSearchContext(
      long companyId,
      String name,
      String description,
      LinkedHashMap<String, Object> params,
      boolean andSearch,
      int start,
      int end,
      Sort sort) {

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andSearch);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put("description", description);
    attributes.put("name", name);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);

    if (params != null) {
      String keywords = (String) params.remove("keywords");

      if (Validator.isNotNull(keywords)) {
        searchContext.setKeywords(keywords);
      }
    }

    if (sort != null) {
      searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    return searchContext;
  }
  protected static AssetSearcher getAssetSearcher(
      SearchContext searchContext, AssetEntryQuery assetEntryQuery, int start, int end)
      throws Exception {

    Indexer<?> searcher = AssetSearcher.getInstance();

    AssetSearcher assetSearcher = (AssetSearcher) searcher;

    assetSearcher.setAssetEntryQuery(assetEntryQuery);

    Layout layout = assetEntryQuery.getLayout();

    if (layout != null) {
      searchContext.setAttribute(Field.LAYOUT_UUID, layout.getUuid());
    }

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

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

      searchContext.setAttribute("ddmStructureFieldName", ddmStructureFieldName);
      searchContext.setAttribute("ddmStructureFieldValue", ddmStructureFieldValue);
    }

    String paginationType = GetterUtil.getString(assetEntryQuery.getPaginationType(), "more");

    if (!paginationType.equals("none") && !paginationType.equals("simple")) {

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

    searchContext.setClassTypeIds(assetEntryQuery.getClassTypeIds());
    searchContext.setEnd(end);
    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    if (Validator.isNotNull(assetEntryQuery.getKeywords())) {
      searchContext.setLike(true);
    }

    searchContext.setSorts(getSorts(assetEntryQuery, searchContext.getLocale()));
    searchContext.setStart(start);

    return assetSearcher;
  }
  @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);
  }