@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());

    if (!entry.isInTrash() && entry.isInTrashContainer()) {
      BookmarksFolder folder = entry.getTrashContainer();

      addTrashFields(
          document,
          BookmarksFolder.class.getName(),
          folder.getFolderId(),
          null,
          null,
          BookmarksEntryAssetRendererFactory.TYPE);

      document.addKeyword(Field.ROOT_ENTRY_CLASS_NAME, BookmarksFolder.class.getName());
      document.addKeyword(Field.ROOT_ENTRY_CLASS_PK, folder.getFolderId());
      document.addKeyword(Field.STATUS, WorkflowConstants.STATUS_IN_TRASH);
    }

    return document;
  }
  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"));
  }
Ejemplo n.º 3
0
  protected void indexField(Document document, Element element, String elType, String elIndexType) {

    if (Validator.isNull(elIndexType)) {
      return;
    }

    com.liferay.portal.kernel.xml.Document structureDocument = element.getDocument();

    Element rootElement = structureDocument.getRootElement();

    String defaultLocale = GetterUtil.getString(rootElement.attributeValue("default-locale"));

    String name = encodeFieldName(element.attributeValue("name"));

    List<Element> dynamicContentElements = element.elements("dynamic-content");

    for (Element dynamicContentElement : dynamicContentElements) {
      String contentLocale =
          GetterUtil.getString(dynamicContentElement.attributeValue("language-id"));

      String[] value = new String[] {dynamicContentElement.getText()};

      if (elType.equals("multi-list")) {
        List<Element> optionElements = dynamicContentElement.elements("option");

        value = new String[optionElements.size()];

        for (int i = 0; i < optionElements.size(); i++) {
          value[i] = optionElements.get(i).getText();
        }
      }

      if (elIndexType.equals("keyword")) {
        if (Validator.isNull(contentLocale)) {
          document.addKeyword(name, value);
        } else {
          if (defaultLocale.equals(contentLocale)) {
            document.addKeyword(name, value);
          }

          document.addKeyword(name.concat(StringPool.UNDERLINE).concat(contentLocale), value);
        }
      } else if (elIndexType.equals("text")) {
        if (Validator.isNull(contentLocale)) {
          document.addText(name, StringUtil.merge(value, StringPool.SPACE));
        } else {
          if (defaultLocale.equals(contentLocale)) {
            document.addText(name, StringUtil.merge(value, StringPool.SPACE));
          }

          document.addText(
              name.concat(StringPool.UNDERLINE).concat(contentLocale),
              StringUtil.merge(value, StringPool.SPACE));
        }
      }
    }
  }
  @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);
  }
Ejemplo n.º 5
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.addKeyword(Field.ROOT_ENTRY_CLASS_PK, kbArticle.getRootResourcePrimKey());
    document.addText(Field.TITLE, kbArticle.getTitle());

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

    return document;
  }
  protected void addDDMStructureAttributes(Document document, JournalArticle article)
      throws Exception {

    DDMStructure ddmStructure =
        _ddmStructureLocalService.fetchStructure(
            article.getGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class),
            article.getDDMStructureKey(),
            true);

    if (ddmStructure == null) {
      return;
    }

    document.addKeyword(Field.CLASS_TYPE_ID, ddmStructure.getStructureId());

    DDMFormValues ddmFormValues = null;

    try {
      Fields fields = JournalConverterUtil.getDDMFields(ddmStructure, article.getDocument());

      ddmFormValues = FieldsToDDMFormValuesConverterUtil.convert(ddmStructure, fields);
    } catch (Exception e) {
      return;
    }

    if (ddmFormValues != null) {
      DDMIndexerUtil.addAttributes(document, ddmStructure, ddmFormValues);
    }
  }
  protected void populateTimeZone(Document document, Map<String, Serializable> settingsMap) {

    TimeZone timeZone = (TimeZone) settingsMap.get("timeZone");

    if (timeZone != null) {
      document.addKeyword(_PREFIX_SETTING + "timeZone", timeZone.getDisplayName());
    }
  }
  @Override
  public void postProcessDocument(Document document, Object obj) throws Exception {

    User user = (User) obj;

    List<ProjectsEntry> projectsEntries =
        ProjectsEntryLocalServiceUtil.getUserProjectsEntries(user.getUserId());

    String[] projectTitles = new String[projectsEntries.size()];

    for (int i = 0; i < projectTitles.length; i++) {
      ProjectsEntry projectEntry = projectsEntries.get(i);

      projectTitles[i] = StringUtil.toLowerCase(projectEntry.getTitle());
    }

    document.addKeyword("projectTitles", projectTitles);

    int count =
        UserLocalServiceUtil.getSocialUsersCount(
            user.getUserId(), SocialRelationConstants.TYPE_BI_CONNECTION, StringPool.EQUAL);

    List<Long> socialRelationshipUserIds = new ArrayList<>();

    int pages = count / Indexer.DEFAULT_INTERVAL;

    for (int i = 0; i <= pages; i++) {
      int start = (i * Indexer.DEFAULT_INTERVAL);
      int end = start + Indexer.DEFAULT_INTERVAL;

      List<User> socialRelationshipUsers =
          UserLocalServiceUtil.getSocialUsers(
              user.getUserId(),
              SocialRelationConstants.TYPE_BI_CONNECTION,
              StringPool.EQUAL,
              start,
              end,
              new UserFirstNameComparator(true));

      for (User socialRelationshipUser : socialRelationshipUsers) {
        socialRelationshipUserIds.add(socialRelationshipUser.getUserId());
      }
    }

    document.addKeyword("socialRelationships", ArrayUtil.toLongArray(socialRelationshipUserIds));
  }
Ejemplo n.º 9
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    Message message = (Message) obj;

    Document document = getBaseModelDocument(PORTLET_ID, message);

    ExpandoBridge expandoBridge = message.getExpandoBridge();

    document.addText(Field.CONTENT, HtmlUtil.extractText(message.getBody()));
    document.addKeyword(Field.FOLDER_ID, message.getFolderId());
    document.addText(Field.TITLE, message.getSubject());

    document.addKeyword("accountId", message.getAccountId());
    document.addKeyword("remoteMessageId", message.getRemoteMessageId());

    ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

    return document;
  }
  public static Document getEntryDocument(long companyId, PlanItem plan) throws SystemException {

    Document doc = new DocumentImpl();

    doc.addUID(PORTLET_ID, plan.getPlanId());

    doc.addModifiedDate(plan.getUpdated());

    doc.addKeyword(Field.COMPANY_ID, companyId);
    doc.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    doc.addKeyword(Field.GROUP_ID, plan.getCategoryGroupId());

    doc.addText(Field.TITLE, plan.getName());
    doc.addText(Field.CONTENT, plan.getDescription());

    doc.addKeyword(Field.ENTRY_CLASS_NAME, PlanItem.class.getName());
    doc.addKeyword(Field.ENTRY_CLASS_PK, plan.getPlanId());
    // doc.addText(Field.URL, Plan);
    return doc;
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    AssetCategory category = (AssetCategory) obj;

    if (_log.isDebugEnabled()) {
      _log.debug("Indexing category " + category);
    }

    Document document = getBaseModelDocument(PORTLET_ID, category);

    document.addKeyword(Field.ASSET_CATEGORY_ID, category.getCategoryId());
    document.addKeyword(Field.ASSET_VOCABULARY_ID, category.getVocabularyId());
    document.addLocalizedText(Field.DESCRIPTION, category.getDescriptionMap());
    document.addText(Field.NAME, category.getName());
    document.addLocalizedText(Field.TITLE, category.getTitleMap());

    if (_log.isDebugEnabled()) {
      _log.debug("Document " + category + " indexed successfully");
    }

    return document;
  }
  @Override
  public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    MBMessage message = (MBMessage) obj;

    FileEntry fileEntry = null;

    try {
      fileEntry = DLAppLocalServiceUtil.getFileEntry(message.getClassPK());
    } catch (Exception e) {
      return;
    }

    if (fileEntry instanceof LiferayFileEntry) {
      DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

      document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
      document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
      document.addKeyword(
          Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));
    }
  }
Ejemplo n.º 13
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;
  }
  protected void populateLayoutIds(Document document, Map<String, Serializable> settingsMap) {

    if (!settingsMap.containsKey("layoutIdMap")) {
      return;
    }

    Map<Long, Boolean> layoutIdMap = (Map<Long, Boolean>) settingsMap.get("layoutIdMap");

    Set<Long> layoutIdSet = layoutIdMap.keySet();

    Long[] layoutIds = layoutIdSet.toArray(new Long[layoutIdSet.size()]);

    document.addKeyword("layoutIds", layoutIds);
  }
Ejemplo n.º 15
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    DLFolder dlFolder = (DLFolder) obj;

    if (_log.isDebugEnabled()) {
      _log.debug("Indexing folder " + dlFolder);
    }

    Document document = getBaseModelDocument(PORTLET_ID, dlFolder);

    document.addText(Field.DESCRIPTION, dlFolder.getDescription());
    document.addKeyword(Field.FOLDER_ID, dlFolder.getParentFolderId());
    document.addKeyword(Field.HIDDEN, (dlFolder.isHidden() || dlFolder.isInHiddenFolder()));
    document.addText(Field.TITLE, dlFolder.getName());
    document.addKeyword(Field.TREE_PATH, dlFolder.getTreePath());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(dlFolder.getTreePath(), CharPool.SLASH));

    if (_log.isDebugEnabled()) {
      _log.debug("Document " + dlFolder + " indexed successfully");
    }

    return document;
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    ExportImportConfiguration exportImportConfiguration = (ExportImportConfiguration) obj;

    Document document = getBaseModelDocument(PORTLET_ID, exportImportConfiguration);

    document.addText(Field.DESCRIPTION, exportImportConfiguration.getDescription());
    document.addText(Field.NAME, exportImportConfiguration.getName());
    document.addKeyword(Field.TYPE, exportImportConfiguration.getType());

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    populateDates(document, settingsMap);
    populateLayoutIds(document, settingsMap);
    populateLocale(document, settingsMap);
    populateParameterMap(document, settingsMap);
    populateSiteInformation(document, settingsMap);
    populateTimeZone(document, settingsMap);

    document.addKeyword(_PREFIX_SETTING + Field.USER_ID, MapUtil.getLong(settingsMap, "userId"));

    return document;
  }
Ejemplo n.º 17
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    JournalArticle article = (JournalArticle) obj;

    Document document = getBaseModelDocument(PORTLET_ID, article);

    document.addUID(PORTLET_ID, article.getGroupId(), article.getArticleId());

    Locale defaultLocale = LocaleUtil.getDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    String[] languageIds = getLanguageIds(defaultLanguageId, article.getContent());

    for (String languageId : languageIds) {
      String content = extractContent(article, languageId);

      if (languageId.equals(defaultLanguageId)) {
        document.addText(Field.CONTENT, content);
      }

      document.addText(Field.CONTENT.concat(StringPool.UNDERLINE).concat(languageId), content);
    }

    document.addLocalizedText(Field.DESCRIPTION, article.getDescriptionMap());
    document.addKeyword(Field.FOLDER_ID, article.getFolderId());
    document.addLocalizedText(Field.TITLE, article.getTitleMap());
    document.addKeyword(Field.TYPE, article.getType());
    document.addKeyword(Field.VERSION, article.getVersion());

    document.addKeyword("articleId", article.getArticleId());
    document.addDate("displayDate", article.getDisplayDate());
    document.addKeyword("layoutUuid", article.getLayoutUuid());
    document.addKeyword("structureId", article.getStructureId());
    document.addKeyword("templateId", article.getTemplateId());

    JournalStructure structure = null;

    if (Validator.isNotNull(article.getStructureId())) {
      try {
        structure =
            JournalStructureLocalServiceUtil.getStructure(
                article.getGroupId(), article.getStructureId(), true);
      } catch (NoSuchStructureException nsse) {
      }
    }

    processStructure(structure, document, article.getContent());

    return document;
  }
Ejemplo n.º 18
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    JournalFolder folder = (JournalFolder) obj;

    if (_log.isDebugEnabled()) {
      _log.debug("Indexing folder " + folder);
    }

    Document document = getBaseModelDocument(PORTLET_ID, folder);

    document.addText(Field.DESCRIPTION, folder.getDescription());
    document.addKeyword(Field.FOLDER_ID, folder.getParentFolderId());
    document.addText(Field.TITLE, folder.getName());

    if (_log.isDebugEnabled()) {
      _log.debug("Document " + folder + " indexed successfully");
    }

    return document;
  }
Ejemplo n.º 19
0
  @Override
  protected Document doGetDocument(Calendar calendar) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, calendar);

    document.addLocalizedText(Field.DESCRIPTION, calendar.getDescriptionMap());
    document.addLocalizedText(Field.NAME, calendar.getNameMap());
    document.addKeyword("calendarId", calendar.getCalendarId());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    document.addText("defaultLanguageId", defaultLanguageId);

    CalendarResource calendarResource = calendar.getCalendarResource();

    document.addLocalizedText("resourceName", calendarResource.getNameMap());

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

    if (!settingsMap.containsKey("parameterMap")) {
      return;
    }

    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");

    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
      String[] parameterValues = ArrayUtil.clone(entry.getValue());

      for (int i = 0; i < parameterValues.length; i++) {
        String parameterValue = parameterValues[i];

        if (parameterValue.equals(StringPool.TRUE)) {
          parameterValues[i] = "on";
        } else if (parameterValue.equals(StringPool.FALSE)) {
          parameterValues[i] = "off";
        }
      }

      document.addKeyword(_PREFIX_PARAMETER + entry.getKey(), parameterValues);
    }
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    if (_log.isDebugEnabled()) {
      _log.debug("Indexing document " + dlFileEntry);
    }

    boolean indexContent = true;

    InputStream is = null;

    try {
      if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) {
        indexContent = false;
      } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) {
        if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) {

          indexContent = false;
        }
      }

      if (indexContent) {
        String[] ignoreExtensions =
            PrefsPropsUtil.getStringArray(
                PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);

        if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) {

          indexContent = false;
        }
      }

      if (indexContent) {
        is = dlFileEntry.getFileVersion().getContentStream(false);
      }
    } catch (Exception e) {
    }

    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

    try {
      Document document = getBaseModelDocument(PORTLET_ID, dlFileEntry, dlFileVersion);

      if (indexContent) {
        if (is != null) {
          try {
            document.addFile(Field.CONTENT, is, dlFileEntry.getTitle());
          } catch (IOException ioe) {
            throw new SearchException("Cannot extract text from file" + dlFileEntry);
          }
        } else if (_log.isDebugEnabled()) {
          _log.debug("Document " + dlFileEntry + " does not have any content");
        }
      }

      document.addKeyword(Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId());
      document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
      document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
      document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
      document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties());
      document.addText(Field.TITLE, dlFileEntry.getTitle());
      document.addKeyword(
          Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));

      document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId());
      document.addText("ddmContent", extractDDMContent(dlFileVersion, LocaleUtil.getSiteDefault()));
      document.addKeyword("extension", dlFileEntry.getExtension());
      document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
      document.addKeyword(
          "mimeType",
          StringUtil.replace(
              dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      document.addKeyword("path", dlFileEntry.getTitle());
      document.addKeyword("readCount", dlFileEntry.getReadCount());
      document.addKeyword("size", dlFileEntry.getSize());

      ExpandoBridge expandoBridge =
          ExpandoBridgeFactoryUtil.getExpandoBridge(
              dlFileEntry.getCompanyId(),
              DLFileEntry.class.getName(),
              dlFileVersion.getFileVersionId());

      ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

      addFileEntryTypeAttributes(document, dlFileVersion);

      if (dlFileEntry.isInHiddenFolder()) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(dlFileEntry.getClassName());

        if (indexer != null) {
          indexer.addRelatedEntryFields(document, obj);

          DocumentHelper documentHelper = new DocumentHelper(document);

          documentHelper.setAttachmentOwnerKey(
              PortalUtil.getClassNameId(dlFileEntry.getClassName()), dlFileEntry.getClassPK());

          document.addKeyword(Field.RELATED_ENTRY, true);
        }
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Document " + dlFileEntry + " indexed successfully");
      }

      return document;
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
        }
      }
    }
  }
  @Override
  protected Document doGetDocument(JournalArticle journalArticle) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, journalArticle);

    long classPK = journalArticle.getId();

    if (!isIndexAllArticleVersions()) {
      classPK = journalArticle.getResourcePrimKey();
    }

    document.addUID(CLASS_NAME, classPK);

    String articleDefaultLanguageId =
        LocalizationUtil.getDefaultLanguageId(journalArticle.getDocument());

    String[] languageIds = LocalizationUtil.getAvailableLanguageIds(journalArticle.getDocument());

    for (String languageId : languageIds) {
      String content = extractDDMContent(journalArticle, languageId);

      String description = journalArticle.getDescription(languageId);

      String title = journalArticle.getTitle(languageId);

      if (languageId.equals(articleDefaultLanguageId)) {
        document.addText(Field.CONTENT, content);
        document.addText(Field.DESCRIPTION, description);
        document.addText("defaultLanguageId", languageId);
      }

      document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content);
      document.addText(
          LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description);
      document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, journalArticle.getFolderId());

    String articleId = journalArticle.getArticleId();

    if (journalArticle.isInTrash()) {
      articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeyword(Field.ARTICLE_ID, articleId);

    document.addKeyword(Field.LAYOUT_UUID, journalArticle.getLayoutUuid());
    document.addKeyword(
        Field.TREE_PATH, StringUtil.split(journalArticle.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.VERSION, journalArticle.getVersion());

    document.addKeyword("ddmStructureKey", journalArticle.getDDMStructureKey());
    document.addKeyword("ddmTemplateKey", journalArticle.getDDMTemplateKey());
    document.addDate("displayDate", journalArticle.getDisplayDate());
    document.addKeyword("head", JournalUtil.isHead(journalArticle));

    boolean headListable = JournalUtil.isHeadListable(journalArticle);

    document.addKeyword("headListable", headListable);

    // Scheduled listable articles should be visible in asset browser

    if (journalArticle.isScheduled() && headListable) {
      boolean visible = GetterUtil.getBoolean(document.get("visible"));

      if (!visible) {
        document.addKeyword("visible", true);
      }
    }

    addDDMStructureAttributes(document, journalArticle);

    return document;
  }
  @Override
  public Hits search(SearchContext searchContext, Query query) throws SearchException {

    long startTime = System.currentTimeMillis();

    List<ExtRepositorySearchResult<?>> extRepositorySearchResults = null;

    try {
      extRepositorySearchResults =
          _extRepository.search(searchContext, query, new ExtRepositoryQueryMapperImpl(this));
    } catch (PortalException | SystemException e) {
      throw new SearchException("Unable to perform search", e);
    }

    QueryConfig queryConfig = searchContext.getQueryConfig();

    List<Document> documents = new ArrayList<>();
    List<String> snippets = new ArrayList<>();
    List<Float> scores = new ArrayList<>();

    int total = 0;

    for (ExtRepositorySearchResult<?> extRepositorySearchResult : extRepositorySearchResults) {

      try {
        ExtRepositoryObjectAdapter<?> extRepositoryEntryAdapter =
            _toExtRepositoryObjectAdapter(
                ExtRepositoryObjectAdapterType.OBJECT, extRepositorySearchResult.getObject());

        Document document = new DocumentImpl();

        document.addKeyword(Field.ENTRY_CLASS_NAME, extRepositoryEntryAdapter.getModelClassName());
        document.addKeyword(Field.ENTRY_CLASS_PK, extRepositoryEntryAdapter.getPrimaryKey());
        document.addKeyword(Field.TITLE, extRepositoryEntryAdapter.getName());

        documents.add(document);

        if (queryConfig.isScoreEnabled()) {
          scores.add(extRepositorySearchResult.getScore());
        } else {
          scores.add(1.0F);
        }

        snippets.add(extRepositorySearchResult.getSnippet());

        total++;
      } catch (PortalException | SystemException e) {
        if (_log.isWarnEnabled()) {
          _log.warn("Invalid entry returned from search", e);
        }
      }
    }

    float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND;

    Hits hits = new HitsImpl();

    hits.setDocs(documents.toArray(new Document[documents.size()]));
    hits.setLength(total);
    hits.setQueryTerms(new String[0]);
    hits.setScores(ArrayUtil.toFloatArray(scores));
    hits.setSearchTime(searchTime);
    hits.setSnippets(snippets.toArray(new String[snippets.size()]));
    hits.setStart(startTime);

    return hits;
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    JournalArticle article = (JournalArticle) obj;

    Document document = getBaseModelDocument(CLASS_NAME, article);

    long classPK = article.getId();

    if (!JournalServiceConfigurationValues.JOURNAL_ARTICLE_INDEX_ALL_VERSIONS) {

      classPK = article.getResourcePrimKey();
    }

    document.addUID(CLASS_NAME, classPK);

    String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(article.getDocument());

    String[] languageIds = LocalizationUtil.getAvailableLanguageIds(article.getDocument());

    for (String languageId : languageIds) {
      String content = extractDDMContent(article, languageId);

      String description = article.getDescription(languageId);

      String title = article.getTitle(languageId);

      if (languageId.equals(articleDefaultLanguageId)) {
        document.addText(Field.CONTENT, content);
        document.addText(Field.DESCRIPTION, description);
        document.addText(Field.TITLE, title);
        document.addText("defaultLanguageId", languageId);
      }

      document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content);
      document.addText(
          LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description);
      document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, article.getFolderId());

    String articleId = article.getArticleId();

    if (article.isInTrash()) {
      articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeyword(Field.ARTICLE_ID, articleId);

    document.addKeyword(Field.LAYOUT_UUID, article.getLayoutUuid());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(article.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.VERSION, article.getVersion());

    document.addKeyword("ddmStructureKey", article.getDDMStructureKey());
    document.addKeyword("ddmTemplateKey", article.getDDMTemplateKey());
    document.addDate("displayDate", article.getDisplayDate());
    document.addKeyword("head", isHead(article));

    addDDMStructureAttributes(document, article);

    return document;
  }
  protected void doAddPermissionFields_6(
      long companyId, long groupId, String className, String classPK, Document doc)
      throws Exception {

    Group group = null;

    if (groupId > 0) {
      group = GroupLocalServiceUtil.getGroup(groupId);
    }

    List<Role> roles =
        ListUtil.copy(ResourceActionsUtil.getRoles(companyId, group, className, null));

    if (groupId > 0) {
      List<Role> teamRoles = RoleLocalServiceUtil.getTeamRoles(groupId);

      roles.addAll(teamRoles);
    }

    long[] roleIdsArray = new long[roles.size()];

    for (int i = 0; i < roleIdsArray.length; i++) {
      Role role = roles.get(i);

      roleIdsArray[i] = role.getRoleId();
    }

    boolean[] hasResourcePermissions = null;

    if (ResourceBlockLocalServiceUtil.isSupported(className)) {
      ResourceBlockIdsBag resourceBlockIdsBag =
          ResourceBlockLocalServiceUtil.getResourceBlockIdsBag(
              companyId, groupId, className, roleIdsArray);

      long actionId = ResourceBlockLocalServiceUtil.getActionId(className, ActionKeys.VIEW);

      List<Long> resourceBlockIds = resourceBlockIdsBag.getResourceBlockIds(actionId);

      hasResourcePermissions = new boolean[roleIdsArray.length];

      for (long resourceBlockId : resourceBlockIds) {
        for (int i = 0; i < roleIdsArray.length; i++) {
          int count =
              ResourceBlockPermissionLocalServiceUtil.getResourceBlockPermissionsCount(
                  resourceBlockId, roleIdsArray[i]);

          hasResourcePermissions[i] = (count > 0);
        }
      }
    } else {
      hasResourcePermissions =
          ResourcePermissionLocalServiceUtil.hasResourcePermissions(
              companyId,
              className,
              ResourceConstants.SCOPE_INDIVIDUAL,
              classPK,
              roleIdsArray,
              ActionKeys.VIEW);
    }

    List<Long> roleIds = new ArrayList<Long>();
    List<String> groupRoleIds = new ArrayList<String>();

    for (int i = 0; i < hasResourcePermissions.length; i++) {
      if (!hasResourcePermissions[i]) {
        continue;
      }

      Role role = roles.get(i);

      if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
          || (role.getType() == RoleConstants.TYPE_SITE)) {

        groupRoleIds.add(groupId + StringPool.DASH + role.getRoleId());
      } else {
        roleIds.add(role.getRoleId());
      }
    }

    doc.addKeyword(Field.ROLE_ID, roleIds.toArray(new Long[roleIds.size()]));
    doc.addKeyword(Field.GROUP_ROLE_ID, groupRoleIds.toArray(new String[groupRoleIds.size()]));
  }
  protected void addAttribute(
      Document document, ExpandoColumn expandoColumn, List<ExpandoValue> expandoValues)
      throws PortalException {

    UnicodeProperties unicodeProperties = expandoColumn.getTypeSettingsProperties();

    int indexType =
        GetterUtil.getInteger(unicodeProperties.getProperty(ExpandoColumnConstants.INDEX_TYPE));

    String fieldName = encodeFieldName(expandoColumn.getName(), indexType);

    ExpandoValue expandoValue = new ExpandoValueImpl();

    expandoValue.setColumnId(expandoColumn.getColumnId());
    expandoValue.setData(expandoColumn.getDefaultData());

    boolean defaultValue = true;

    for (ExpandoValue curExpandoValue : expandoValues) {
      if (curExpandoValue.getColumnId() == expandoColumn.getColumnId()) {
        expandoValue = curExpandoValue;

        defaultValue = false;

        break;
      }
    }

    int type = expandoColumn.getType();

    if (type == ExpandoColumnConstants.BOOLEAN) {
      document.addKeyword(fieldName, expandoValue.getBoolean());
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getBooleanArray());
      } else {
        document.addKeyword(fieldName, new boolean[0]);
      }
    } else if (type == ExpandoColumnConstants.DATE) {
      document.addDate(fieldName, expandoValue.getDate());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
      document.addKeyword(fieldName, expandoValue.getDouble());
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getDoubleArray());
      } else {
        document.addKeyword(fieldName, new double[0]);
      }
    } else if (type == ExpandoColumnConstants.FLOAT) {
      document.addKeyword(fieldName, expandoValue.getFloat());
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getFloatArray());
      } else {
        document.addKeyword(fieldName, new float[0]);
      }
    } else if (type == ExpandoColumnConstants.INTEGER) {
      document.addKeyword(fieldName, expandoValue.getInteger());
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getIntegerArray());
      } else {
        document.addKeyword(fieldName, new int[0]);
      }
    } else if (type == ExpandoColumnConstants.LONG) {
      document.addKeyword(fieldName, expandoValue.getLong());
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getLongArray());
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.NUMBER) {
      document.addKeyword(fieldName, expandoValue.getNumber().toString());
    } else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, ArrayUtil.toStringArray(expandoValue.getNumberArray()));
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.SHORT) {
      document.addKeyword(fieldName, expandoValue.getShort());
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getShortArray());
      } else {
        document.addKeyword(fieldName, new short[0]);
      }
    } else if (type == ExpandoColumnConstants.STRING) {
      if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
        document.addKeyword(fieldName, expandoValue.getString());
      } else {
        document.addText(fieldName, expandoValue.getString());
      }
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, expandoValue.getStringArray());
        } else {
          document.addText(
              fieldName, StringUtil.merge(expandoValue.getStringArray(), StringPool.SPACE));
        }
      } else {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, StringPool.BLANK);
        } else {
          document.addText(fieldName, StringPool.BLANK);
        }
      }
    } else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addLocalizedKeyword(fieldName, expandoValue.getStringMap());
        } else {
          document.addLocalizedText(fieldName, expandoValue.getStringMap());
        }
      }
    }
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    if (_log.isDebugEnabled()) {
      _log.debug("Indexing document " + dlFileEntry);
    }

    boolean indexContent = true;

    InputStream is = null;

    try {
      if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) {
        indexContent = false;
      } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) {
        if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) {

          indexContent = false;
        }
      }

      if (indexContent) {
        String[] ignoreExtensions =
            PrefsPropsUtil.getStringArray(
                PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);

        if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) {

          indexContent = false;
        }
      }

      if (indexContent) {
        is = dlFileEntry.getFileVersion().getContentStream(false);
      }
    } catch (Exception e) {
    }

    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

    try {
      Document document = getBaseModelDocument(PORTLET_ID, dlFileEntry, dlFileVersion);

      if (indexContent) {
        if (is != null) {
          try {
            document.addFile(Field.CONTENT, is, dlFileEntry.getTitle());
          } catch (IOException ioe) {
            throw new SearchException("Cannot extract text from file" + dlFileEntry);
          }
        } else if (_log.isDebugEnabled()) {
          _log.debug("Document " + dlFileEntry + " does not have any content");
        }
      }

      document.addKeyword(Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId());
      document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
      document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
      document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
      document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties());
      document.addText(Field.TITLE, dlFileEntry.getTitle());

      document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId());
      document.addKeyword("extension", dlFileEntry.getExtension());
      document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
      document.addKeyword(
          "mimeType",
          StringUtil.replace(
              dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      document.addKeyword("path", dlFileEntry.getTitle());
      document.addKeyword("readCount", dlFileEntry.getReadCount());
      document.addKeyword("size", dlFileEntry.getSize());

      ExpandoBridge expandoBridge =
          ExpandoBridgeFactoryUtil.getExpandoBridge(
              dlFileEntry.getCompanyId(),
              DLFileEntry.class.getName(),
              dlFileVersion.getFileVersionId());

      ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

      addFileEntryTypeAttributes(document, dlFileVersion);

      if (dlFileEntry.isInHiddenFolder()) {
        try {
          Repository repository =
              RepositoryLocalServiceUtil.getRepository(dlFileEntry.getRepositoryId());

          String portletId = repository.getPortletId();

          for (Indexer indexer : IndexerRegistryUtil.getIndexers()) {
            if (portletId.equals(indexer.getPortletId())) {
              indexer.addRelatedEntryFields(document, obj);
            }
          }
        } catch (Exception e) {
        }
      }

      if (!dlFileVersion.isInTrash() && dlFileVersion.isInTrashContainer()) {

        DLFolder folder = dlFileVersion.getTrashContainer();

        addTrashFields(
            document,
            DLFolder.class.getName(),
            folder.getFolderId(),
            null,
            null,
            DLFileEntryAssetRendererFactory.TYPE);

        document.addKeyword(Field.ROOT_ENTRY_CLASS_NAME, DLFolder.class.getName());
        document.addKeyword(Field.ROOT_ENTRY_CLASS_PK, folder.getFolderId());
        document.addKeyword(Field.STATUS, WorkflowConstants.STATUS_IN_TRASH);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Document " + dlFileEntry + " indexed successfully");
      }

      return document;
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
        }
      }
    }
  }
Ejemplo n.º 28
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    User user = (User) obj;

    Document document = getBaseModelDocument(CLASS_NAME, user);

    long[] organizationIds = user.getOrganizationIds();

    document.addKeyword(Field.COMPANY_ID, user.getCompanyId());
    document.addKeyword(Field.GROUP_ID, user.getGroupIds());
    document.addDate(Field.MODIFIED_DATE, user.getModifiedDate());
    document.addKeyword(Field.SCOPE_GROUP_ID, user.getGroupIds());
    document.addKeyword(Field.STATUS, user.getStatus());
    document.addKeyword(Field.USER_ID, user.getUserId());
    document.addKeyword(Field.USER_NAME, user.getFullName());

    document.addKeyword(
        "ancestorOrganizationIds", getAncestorOrganizationIds(user.getOrganizationIds()));
    document.addText("emailAddress", user.getEmailAddress());
    document.addText("firstName", user.getFirstName());
    document.addText("fullName", user.getFullName());
    document.addKeyword("groupIds", user.getGroupIds());
    document.addText("jobTitle", user.getJobTitle());
    document.addText("lastName", user.getLastName());
    document.addText("middleName", user.getMiddleName());
    document.addKeyword("organizationIds", organizationIds);
    document.addKeyword("organizationCount", String.valueOf(organizationIds.length));
    document.addKeyword("roleIds", user.getRoleIds());
    document.addText("screenName", user.getScreenName());
    document.addKeyword("teamIds", user.getTeamIds());
    document.addKeyword("userGroupIds", user.getUserGroupIds());

    populateAddresses(document, user.getAddresses(), 0, 0);

    return document;
  }
Ejemplo n.º 29
0
  public void addAttributes(Document document, DDMStructure ddmStructure, Fields fields) {

    Iterator<Field> itr = fields.iterator();

    while (itr.hasNext()) {
      Field field = itr.next();

      try {
        String indexType = ddmStructure.getFieldProperty(field.getName(), "indexType");

        if (Validator.isNull(indexType)) {
          continue;
        }

        for (Locale locale : LanguageUtil.getAvailableLocales()) {
          String name = encodeName(ddmStructure.getStructureId(), field.getName(), locale);

          Serializable value = field.getValue(locale);

          if (value instanceof Boolean) {
            document.addKeyword(name, (Boolean) value);
          } else if (value instanceof Boolean[]) {
            document.addKeyword(name, (Boolean[]) value);
          } else if (value instanceof Date) {
            document.addDate(name, (Date) value);
          } else if (value instanceof Date[]) {
            document.addDate(name, (Date[]) value);
          } else if (value instanceof Double) {
            document.addKeyword(name, (Double) value);
          } else if (value instanceof Double[]) {
            document.addKeyword(name, (Double[]) value);
          } else if (value instanceof Integer) {
            document.addKeyword(name, (Integer) value);
          } else if (value instanceof Integer[]) {
            document.addKeyword(name, (Integer[]) value);
          } else if (value instanceof Object[]) {
            String[] valuesString = ArrayUtil.toStringArray((Object[]) value);

            if (indexType.equals("keyword")) {
              document.addKeyword(name, valuesString);
            } else {
              document.addText(name, valuesString);
            }
          } else {
            String valueString = String.valueOf(value);

            String type = field.getType();

            if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

              JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

              String[] stringArray = ArrayUtil.toStringArray(jsonArray);

              if (indexType.equals("keyword")) {
                document.addKeyword(name, stringArray);
              } else {
                document.addText(name, stringArray);
              }
            } else {
              if (indexType.equals("keyword")) {
                document.addKeyword(name, valueString);
              } else {
                document.addText(name, valueString);
              }
            }
          }
        }
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }
    }
  }