public static String getEntryUID(long entryId) {
    Document doc = new DocumentImpl();

    doc.addUID(PORTLET_ID, entryId);

    return doc.get(Field.UID);
  }
Exemplo 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);
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
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);
  }
Exemplo n.º 6
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);
  }
  @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;
  }
  @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);
  }
  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;
  }
Exemplo n.º 10
0
  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();
    }
  }
  @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;
  }
  public static void updateEntry(long companyId, PlanItem plan)
      throws SearchException, SystemException {

    Document doc = getEntryDocument(companyId, plan);

    SearchEngineUtil.updateDocument(companyId, doc.get(Field.UID), doc);
  }
  @Override
  public void addDocuments(
      String searchEngineId,
      long companyId,
      Collection<Document> documents,
      boolean commitImmediately)
      throws SearchException {

    if (isIndexReadOnly() || (documents == null) || documents.isEmpty()) {
      return;
    }

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    for (Document document : documents) {
      if (_log.isDebugEnabled()) {
        _log.debug("Add document " + document.toString());
      }

      _searchPermissionChecker.addPermissionFields(companyId, document);
    }

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setSearchEngineId(searchEngineId);

    setCommitImmediately(searchContext, commitImmediately);

    indexWriter.addDocuments(searchContext, documents);
  }
Exemplo n.º 14
0
 @Override
 protected Document doGetDocument(Object arg0) throws Exception {
   FAQEntry faq = (FAQEntry) arg0;
   Document document = getBaseModelDocument(getPortletId(), faq);
   document.addText(Field.TITLE, faq.getQuestion());
   document.addText("answer", faq.getAnswer());
   return document;
 }
  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 void populateSiteInformation(Document document, Map<String, Serializable> settingsMap) {

    document.addKeyword(
        _PREFIX_SETTING + "privateLayout", MapUtil.getBoolean(settingsMap, "privateLayout"));
    document.addKeyword(
        _PREFIX_SETTING + "sourceGroupId", MapUtil.getLong(settingsMap, "sourceGroupId"));
    document.addKeyword(
        _PREFIX_SETTING + "targetGroupId", MapUtil.getLong(settingsMap, "targetGroupId"));
  }
  @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());
  }
Exemplo n.º 18
0
  @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));
  }
  @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
  public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    MBMessage message = (MBMessage) obj;

    DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(message.getClassPK());

    document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
    document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
    document.addKeyword(Field.RELATED_ENTRY, true);
  }
  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 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;
  }
Exemplo n.º 23
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    BookmarksEntry entry = (BookmarksEntry) obj;

    Document document = getBaseModelDocument(PORTLET_ID, entry);

    document.addText(Field.DESCRIPTION, entry.getDescription());
    document.addKeyword(Field.FOLDER_ID, entry.getFolderId());
    document.addText(Field.TITLE, entry.getName());
    document.addText(Field.URL, entry.getUrl());

    return document;
  }
Exemplo n.º 24
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    KBArticle kbArticle = (KBArticle) obj;

    Document document = getBaseModelDocument(PORTLET_ID, kbArticle);

    document.addText(Field.CONTENT, HtmlUtil.extractText(kbArticle.getContent()));
    document.addText(Field.DESCRIPTION, kbArticle.getDescription());
    document.addText(Field.TITLE, kbArticle.getTitle());

    document.addKeyword("titleKeyword", kbArticle.getTitle(), true);

    return document;
  }
  protected void populateDates(Document document, Map<String, Serializable> settingsMap) {

    if (settingsMap.containsKey("endDate")) {
      Date endDate = (Date) settingsMap.get("endDate");

      document.addDate(_PREFIX_SETTING + "endDate", endDate);
    }

    if (settingsMap.containsKey("startDate")) {
      Date startDate = (Date) settingsMap.get("startDate");

      document.addDate(_PREFIX_SETTING + "startDate", startDate);
    }
  }
  @Override
  protected void doReindex(JournalArticle article) throws Exception {
    if (PortalUtil.getClassNameId(DDMStructure.class) == article.getClassNameId()) {

      Document document = getDocument(article);

      IndexWriterHelperUtil.deleteDocument(
          getSearchEngineId(), article.getCompanyId(),
          document.get(Field.UID), isCommitImmediately());

      return;
    }

    reindexArticleVersions(article);
  }
Exemplo n.º 27
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);
  }
  @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;
  }
Exemplo n.º 29
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 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;
  }
  @Override
  public void updateDocument(
      String searchEngineId, long companyId, Document document, boolean commitImmediately)
      throws SearchException {

    if (isIndexReadOnly() || (document == null)) {
      return;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Document " + document.toString());
    }

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    _searchPermissionChecker.addPermissionFields(companyId, document);

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setSearchEngineId(searchEngineId);

    setCommitImmediately(searchContext, commitImmediately || ProxyModeThreadLocal.isForceSync());

    indexWriter.updateDocument(searchContext, document);
  }