protected void searchByDDMStructureField() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

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

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

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

    baseModel = addBaseModelWithDDMStructure(parentBaseModel, getSearchKeywords(), serviceContext);

    searchContext.setAttribute("ddmStructureFieldName", getDDMStructureFieldName());
    searchContext.setAttribute("ddmStructureFieldValue", getSearchKeywords());

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    updateDDMStructure(serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException {

    SearchContainer<MBMessage> searchContainer =
        new SearchContainer(
            _liferayPortletRequest, _liferayPortletResponse.createRenderURL(), null, null);

    SearchContext searchContext =
        SearchContextFactory.getInstance(_liferayPortletRequest.getHttpServletRequest());

    searchContext.setAttribute(
        Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class));

    searchContext.setAttribute("discussion", true);

    List<MBMessage> mbMessages = new ArrayList<>();

    Indexer indexer = IndexerRegistryUtil.getIndexer(MBMessage.class);

    Hits hits = indexer.search(searchContext);

    for (Document document : hits.getDocs()) {
      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK);

      mbMessages.add(mbMessage);
    }

    searchContainer.setResults(mbMessages);

    searchContainer.setTotal(hits.getLength());

    return searchContainer;
  }
  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);
    }
  }
  @Test
  public void testLocalizedSearch() throws Exception {
    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

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

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

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

    Map<Locale, String> keywordsMap = new HashMap<Locale, String>();

    keywordsMap.put(LocaleUtil.getDefault(), "entity title");
    keywordsMap.put(LocaleUtil.HUNGARY, "entitas neve");

    baseModel = addBaseModelWithWorkflow(parentBaseModel, true, keywordsMap, serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    searchContext.setAttribute(Field.TITLE, "nev");
    searchContext.setKeywords("nev");
    searchContext.setLocale(LocaleUtil.HUNGARY);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
Пример #5
0
  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);
  }
  protected void search(
      FileEntry fileEntry, boolean rootFolder, String keywords, boolean assertTrue)
      throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute("paginationType", "regular");
    searchContext.setCompanyId(fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] {fileEntry.getFolderId()});
    searchContext.setGroupIds(new long[] {fileEntry.getRepositoryId()});
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

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

    searchContext.setQueryConfig(queryConfig);

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

    Hits hits = indexer.search(searchContext);

    List<Document> documents = hits.toList();

    boolean found = false;

    for (Document document : documents) {
      long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      if (fileEntryId == fileEntry.getFileEntryId()) {
        found = true;

        break;
      }
    }

    String message = "Search engine could not find ";

    if (rootFolder) {
      message += "root file entry by " + keywords;
    } else {
      message += "file entry by " + keywords;
    }

    message += " using query " + hits.getQuery();

    if (assertTrue) {
      Assert.assertTrue(message, found);
    } else {
      Assert.assertFalse(message, found);
    }
  }
  protected SearchContext buildSearchContext(
      long companyId, long groupId, String title, int start, int end) {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.TITLE, title);
    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] {groupId});
    searchContext.setKeywords(title);
    searchContext.setStart(start);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

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