@Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    Locale snippetLocale = getSnippetLocale(document, locale);

    String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE);

    if ((snippetLocale == null) && (document.getField(localizedTitleName) == null)) {

      snippetLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId"));
    } else {
      snippetLocale = locale;
    }

    String title =
        document.get(
            snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE);

    String content = getDDMContentSummary(document, snippetLocale, portletRequest, portletResponse);

    return new Summary(snippetLocale, title, content);
  }
Esempio n. 2
0
  @Override
  protected Summary doGetSummary(
      Document document, Locale locale, String snippet, PortletURL portletURL) {

    LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL;

    liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);

    try {
      liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    } catch (WindowStateException wse) {
    }

    String title = document.get(Field.TITLE);

    String content = snippet;

    if (Validator.isNull(snippet)) {
      content = StringUtil.shorten(document.get(Field.CONTENT), 200);
    }

    String fileEntryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/document_library/get_file");
    portletURL.setParameter("fileEntryId", fileEntryId);

    return new Summary(title, content, portletURL);
  }
  @Override
  public List<AssetVocabulary> getVocabularies(Hits hits) throws PortalException {

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

    List<AssetVocabulary> vocabularies = new ArrayList<>(documents.size());

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

      AssetVocabulary vocabulary = fetchAssetVocabulary(vocabularyId);

      if (vocabulary == null) {
        vocabularies = null;

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

        long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

        indexer.delete(companyId, document.getUID());
      } else if (vocabularies != null) {
        vocabularies.add(vocabulary);
      }
    }

    return vocabularies;
  }
Esempio n. 4
0
  public void recordHits(Hits hits, long groupId, boolean privateLayout) throws Exception {

    setSearcher(((HitsImpl) hits).getSearcher());

    // This can later be optimized according to LEP-915.

    List docs = new ArrayList(hits.getLength());
    List scores = new ArrayList(hits.getLength());

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

      String articleId = doc.get("articleId");
      long articleGroupId = GetterUtil.getLong(doc.get(LuceneFields.GROUP_ID));

      if (JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId)
          > 0) {

        docs.add(hits.doc(i));
        scores.add(new Float(hits.score(i)));
      } else if (!isShowListed() && (articleGroupId == groupId)) {
        docs.add(hits.doc(i));
        scores.add(new Float(hits.score(i)));
      }
    }

    setLength(docs.size());
    setDocs((Document[]) docs.toArray(new Document[0]));
    setScores((Float[]) scores.toArray(new Float[0]));

    setSearchTime((float) (System.currentTimeMillis() - getStart()) / Time.SECOND);
  }
  @Override
  public List<AssetCategory> getCategories(Hits hits) throws PortalException {
    List<Document> documents = hits.toList();

    List<AssetCategory> categories = new ArrayList<>(documents.size());

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

      AssetCategory category = fetchCategory(categoryId);

      if (category == null) {
        categories = null;

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

        long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

        indexer.delete(companyId, document.getUID());
      } else if (categories != null) {
        categories.add(category);
      }
    }

    return categories;
  }
  protected String getJournalURL(ThemeDisplay themeDisplay, long groupId, Document result)
      throws Exception {

    Layout layout = themeDisplay.getLayout();

    String articleId = result.get(Field.ENTRY_CLASS_PK);
    String version = result.get("version");

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            layout.getGroupId(), layout.isPrivateLayout(), articleId);

    if (hitLayoutIds.size() > 0) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    } else {
      StringBundler sb = new StringBundler(7);

      sb.append(themeDisplay.getPathMain());
      sb.append("/journal/view_article_content?groupId=");
      sb.append(groupId);
      sb.append("&articleId=");
      sb.append(articleId);
      sb.append("&version=");
      sb.append(version);

      return sb.toString();
    }
  }
  @Test
  public void testSearchAndVerifyDocs() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    BookmarksFolder folder =
        BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    BookmarksEntry entry = BookmarksTestUtil.addEntry(folder.getFolderId(), true, serviceContext);

    SearchContext searchContext =
        BookmarksTestUtil.getSearchContext(
            entry.getCompanyId(), entry.getGroupId(), entry.getFolderId(), "test");

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

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(1, hits.getLength());

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

    for (Document doc : results) {
      Assert.assertEquals(entry.getCompanyId(), GetterUtil.getLong(doc.get(Field.COMPANY_ID)));
      Assert.assertEquals(BookmarksEntry.class.getName(), doc.get(Field.ENTRY_CLASS_NAME));
      Assert.assertEquals(entry.getEntryId(), GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK)));
      AssertUtils.assertEqualsIgnoreCase(entry.getName(), doc.get(Field.TITLE));
      Assert.assertEquals(entry.getUrl(), doc.get(Field.URL));
    }
  }
Esempio n. 8
0
  @Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletURL portletURL,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String title = document.get(Field.TITLE);

    String content = snippet;

    if (Validator.isNull(snippet)) {
      content = document.get(Field.DESCRIPTION);

      if (Validator.isNull(content)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
      }
    }

    String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("mvcPath", "/admin/view_article.jsp");
    portletURL.setParameter("resourcePrimKey", resourcePrimKey);

    return new Summary(title, content, portletURL);
  }
Esempio n. 9
0
  @Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletURL portletURL,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String firstName = document.get("firstName");
    String middleName = document.get("middleName");
    String lastName = document.get("lastName");

    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    String title = fullNameGenerator.getFullName(firstName, middleName, lastName);

    String content = null;

    String userId = document.get(Field.USER_ID);

    portletURL.setParameter("struts_action", "/users_admin/edit_user");
    portletURL.setParameter("p_u_i_d", userId);

    return new Summary(title, content, portletURL);
  }
  public DocumentSummary getDocumentSummary(
      com.liferay.portal.kernel.search.Document doc, PortletURL portletURL) {

    String title = doc.get(Field.TITLE);
    String url = doc.get(Field.URL);

    return new DocumentSummary(title, url, portletURL);
  }
  protected AssetEntry getEntry(Document document) throws PortalException, SystemException {

    String portletId = GetterUtil.getString(document.get(Field.PORTLET_ID));

    if (portletId.equals(PortletKeys.BLOGS)) {
      long entryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      long classNameId = PortalUtil.getClassNameId(BlogsEntry.class.getName());
      long classPK = entryId;

      return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.BOOKMARKS)) {
      long entryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      long classNameId = PortalUtil.getClassNameId(BookmarksEntry.class.getName());
      long classPK = entryId;

      return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
      long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      long classNameId = PortalUtil.getClassNameId(DLFileEntry.class.getName());
      long classPK = fileEntryId;

      return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.JOURNAL)) {
      long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
      String articleId = document.get("articleId");
      // double version = GetterUtil.getDouble(document.get("version"));

      long articleResourcePrimKey =
          journalArticleResourceLocalService.getArticleResourcePrimKey(groupId, articleId);

      long classNameId = PortalUtil.getClassNameId(JournalArticle.class.getName());
      long classPK = articleResourcePrimKey;

      return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
      long messageId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      long classNameId = PortalUtil.getClassNameId(MBMessage.class.getName());
      long classPK = messageId;

      return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.WIKI)) {
      long nodeId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
      String title = document.get(Field.TITLE);

      long pageResourcePrimKey = wikiPageResourceLocalService.getPageResourcePrimKey(nodeId, title);

      long classNameId = PortalUtil.getClassNameId(WikiPage.class.getName());
      long classPK = pageResourcePrimKey;

      return assetEntryPersistence.findByC_C(classNameId, classPK);
    }

    return null;
  }
Esempio n. 12
0
  @Override
  public List<TrashEntry> getEntries(Hits hits) {
    List<TrashEntry> entries = new ArrayList<>();

    for (Document document : hits.getDocs()) {
      String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        TrashEntry entry = TrashEntryLocalServiceUtil.fetchEntry(entryClassName, classPK);

        if (entry == null) {
          String userName = GetterUtil.getString(document.get(Field.REMOVED_BY_USER_NAME));

          Date removedDate = document.getDate(Field.REMOVED_DATE);

          entry = new TrashEntryImpl();

          entry.setUserName(userName);
          entry.setCreateDate(removedDate);

          TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entryClassName);

          TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

          entry.setClassName(trashRenderer.getClassName());
          entry.setClassPK(trashRenderer.getClassPK());

          String rootEntryClassName =
              GetterUtil.getString(document.get(Field.ROOT_ENTRY_CLASS_NAME));
          long rootEntryClassPK = GetterUtil.getLong(document.get(Field.ROOT_ENTRY_CLASS_PK));

          TrashEntry rootTrashEntry =
              TrashEntryLocalServiceUtil.fetchEntry(rootEntryClassName, rootEntryClassPK);

          if (rootTrashEntry != null) {
            entry.setRootEntry(rootTrashEntry);
          }
        }

        entries.add(entry);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to find trash entry for " + entryClassName + " with primary key " + classPK);
        }
      }
    }

    return entries;
  }
Esempio n. 13
0
  @Override
  protected Summary doGetSummary(
      Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String url = document.get(Field.URL);

    String entryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/bookmarks/view_entry");
    portletURL.setParameter("entryId", entryId);

    return new Summary(title, url, portletURL);
  }
  public static String getEntryUID(long entryId) {
    Document doc = new DocumentImpl();

    doc.addUID(PORTLET_ID, entryId);

    return doc.get(Field.UID);
  }
  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;
  }
  @Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletURL portletURL,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL;

    liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);

    try {
      liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    } catch (WindowStateException wse) {
    }

    String fileEntryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/document_library/get_file");
    portletURL.setParameter("fileEntryId", fileEntryId);

    Summary summary = createSummary(document, Field.TITLE, Field.CONTENT);

    summary.setMaxContentLength(200);
    summary.setPortletURL(portletURL);

    return summary;
  }
  @Override
  protected Summary doGetSummary(
      Document document, Locale locale, String snippet, PortletURL portletURL) {

    LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL;

    liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);

    try {
      liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    } catch (WindowStateException wse) {
    }

    String folderId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/journal/view");
    portletURL.setParameter("folderId", folderId);

    Summary summary = createSummary(document, Field.TITLE, Field.DESCRIPTION);

    summary.setMaxContentLength(200);
    summary.setPortletURL(portletURL);

    return summary;
  }
Esempio n. 18
0
  public List<BaseModel<?>> getBaseModels() throws Exception {
    if (baseModels != null) {
      return baseModels;
    }

    List<BaseModel<?>> baseModels = new ArrayList<BaseModel<?>>();

    Document[] documents = hits.getDocs();

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

      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      BaseModel<?> baseModel = alloyServiceInvoker.fetchModel(entryClassPK);

      if (baseModel == null) {
        continue;
      }

      baseModels.add(baseModel);
    }

    this.baseModels = baseModels;

    return baseModels;
  }
  public static void updateEntry(long companyId, PlanItem plan)
      throws SearchException, SystemException {

    Document doc = getEntryDocument(companyId, plan);

    SearchEngineUtil.updateDocument(companyId, doc.get(Field.UID), doc);
  }
  protected String getDDMContentSummary(
      Document document,
      Locale snippetLocale,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
      return content;
    }

    try {
      String articleId = document.get(Field.ARTICLE_ID);
      long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
      double version = GetterUtil.getDouble(document.get(Field.VERSION));
      PortletRequestModel portletRequestModel =
          new PortletRequestModel(portletRequest, portletResponse);
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      JournalArticleDisplay articleDisplay =
          _journalContent.getDisplay(
              groupId,
              articleId,
              version,
              null,
              Constants.VIEW,
              LocaleUtil.toLanguageId(snippetLocale),
              1,
              portletRequestModel,
              themeDisplay);

      content = articleDisplay.getDescription();

      content = HtmlUtil.replaceNewLine(content);

      if (Validator.isNull(content)) {
        content = HtmlUtil.extractText(articleDisplay.getContent());
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug(e, e);
      }
    }

    return content;
  }
Esempio n. 21
0
  protected String getURL(
      ThemeDisplay themeDisplay, long groupId, Document result, PortletURL portletURL)
      throws Exception {

    portletURL.setParameter("jspPage", "/html/eprintview/detail.jsp");
    long eprintId = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK));
    portletURL.setParameter("eprintId", String.valueOf(eprintId));
    return super.getURL(themeDisplay, groupId, result, portletURL);
  }
  @Override
  protected void doDelete(DLFileEntry dlFileEntry) throws Exception {
    Document document = new DocumentImpl();

    document.addUID(CLASS_NAME, dlFileEntry.getFileEntryId());

    SearchEngineUtil.deleteDocument(
        getSearchEngineId(), dlFileEntry.getCompanyId(),
        document.get(Field.UID), isCommitImmediately());
  }
  @Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    Locale defaultLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId"));

    Locale snippetLocale = getSnippetLocale(document, locale);

    String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE);

    if ((snippetLocale == null) && (document.getField(localizedTitleName) == null)) {

      snippetLocale = defaultLocale;
    } else {
      snippetLocale = locale;
    }

    String title =
        document.get(
            snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE);

    if (Validator.isNull(title) && !snippetLocale.equals(defaultLocale)) {
      title =
          document.get(
              defaultLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE);
    }

    String content = getDDMContentSummary(document, snippetLocale, portletRequest, portletResponse);

    if (Validator.isNull(content) && !snippetLocale.equals(defaultLocale)) {
      content = getDDMContentSummary(document, defaultLocale, portletRequest, portletResponse);
    }

    Summary summary = new Summary(snippetLocale, title, content);

    summary.setMaxContentLength(200);

    return summary;
  }
  public void recordHits(Hits hits, long groupId, boolean privateLayout, int start, int end)
      throws Exception {

    // This can later be optimized according to LEP-915.

    List<Document> docs = new ArrayList<Document>();
    List<Float> scores = new ArrayList<Float>();

    Document[] docsArray = hits.getDocs();

    for (int i = 0; i < docsArray.length; i++) {
      Document doc = hits.doc(i);

      String articleId = doc.get(Field.ARTICLE_ID);
      long articleGroupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));

      int layoutIdsCount =
          JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId);

      if ((layoutIdsCount > 0) || (!isShowListed() && (articleGroupId == groupId))) {

        docs.add(hits.doc(i));
        scores.add(hits.score(i));
      }
    }

    int length = docs.size();

    hits.setLength(length);

    if (end > length) {
      end = length;
    }

    docs = docs.subList(start, end);
    scores = scores.subList(start, end);

    hits.setDocs(docs.toArray(new Document[docs.size()]));
    hits.setScores(ArrayUtil.toFloatArray(scores));

    hits.setSearchTime((float) (System.currentTimeMillis() - hits.getStart()) / Time.SECOND);
  }
  @Override
  protected void doDelete(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, dlFileEntry.getFileEntryId());

    SearchEngineUtil.deleteDocument(
        getSearchEngineId(), dlFileEntry.getCompanyId(), document.get(Field.UID));
  }
  @Override
  protected void doDelete(Object obj) throws Exception {
    JournalFolder folder = (JournalFolder) obj;

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, folder.getFolderId());

    SearchEngineUtil.deleteDocument(
        getSearchEngineId(), folder.getCompanyId(), document.get(Field.UID));
  }
Esempio n. 27
0
  public static List<AssetEntry> getAssetEntries(Hits hits) {
    List<AssetEntry> assetEntries = new ArrayList<>();

    if (hits.getDocs() == null) {
      return assetEntries;
    }

    for (Document document : hits.getDocs()) {
      String className = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(className, classPK);

        assetEntries.add(assetEntry);
      } catch (Exception e) {
      }
    }

    return assetEntries;
  }
  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);
    }
  }
Esempio n. 29
0
  @Override
  public List<Object> getEntries(Hits hits) {
    List<Object> entries = new ArrayList<Object>();

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

      try {
        Object obj = null;

        if (entryClassName.equals(DLFileEntry.class.getName())) {
          obj = DLAppLocalServiceUtil.getFileEntry(entryClassPK);
        } else if (entryClassName.equals(MBMessage.class.getName())) {
          long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));

          DLAppLocalServiceUtil.getFileEntry(classPK);

          obj = MBMessageLocalServiceUtil.getMessage(entryClassPK);
        }

        entries.add(obj);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Documents and Media search index is stale and "
                  + "contains entry {className="
                  + entryClassName
                  + ", classPK="
                  + entryClassPK
                  + "}");
        }
      }
    }

    return entries;
  }
  @Override
  protected Summary doGetSummary(
      Document document, Locale locale, String snippet, PortletURL portletURL) {

    String entryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/bookmarks/view_entry");
    portletURL.setParameter("entryId", entryId);

    Summary summary = createSummary(document, Field.TITLE, Field.URL);

    summary.setPortletURL(portletURL);

    return summary;
  }