Example usage for com.liferay.portal.kernel.search Field CONTENT

List of usage examples for com.liferay.portal.kernel.search Field CONTENT

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Field CONTENT.

Prototype

String CONTENT

To view the source code for com.liferay.portal.kernel.search Field CONTENT.

Click Source Link

Usage

From source file:com.liferay.docs.guestbook.search.GuestbookSearchRegistrar.java

License:Open Source License

@Activate
protected void activate(BundleContext bundleContext) {

    _serviceRegistration = modelSearchRegistrarHelper.register(Guestbook.class, bundleContext,
            modelSearchDefinition -> {
                modelSearchDefinition.setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.COMPANY_ID,
                        Field.CONTENT, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
                        Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);

                modelSearchDefinition.setModelIndexWriteContributor(modelIndexWriterContributor);
                modelSearchDefinition.setModelSummaryContributor(modelSummaryContributor);
            });/*from   ww  w. j  av  a  2  s .c  o m*/
}

From source file:com.liferay.document.library.repository.cmis.search.BaseCmisSearchQueryBuilder.java

License:Open Source License

private boolean _isContentFieldQueryTerm(QueryTerm queryTerm) {
    String fieldName = queryTerm.getField();

    return fieldName.equals(Field.CONTENT);
}

From source file:com.liferay.document.library.repository.search.internal.RepositorySearchQueryBuilderImpl.java

License:Open Source License

protected void addSearchKeywords(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
        return;/*from  www . j a v a  2  s. c o m*/
    }

    BooleanQuery titleQuery = new BooleanQueryImpl();

    _repositorySearchQueryTermBuilder.addTerm(titleQuery, searchContext, Field.TITLE, keywords);

    if (titleQuery.hasClauses() && !contains(searchQuery, titleQuery)) {
        searchQuery.add(titleQuery, BooleanClauseOccur.SHOULD);
    }

    BooleanQuery userNameQuery = new BooleanQueryImpl();

    _repositorySearchQueryTermBuilder.addTerm(userNameQuery, searchContext, Field.USER_NAME, keywords);

    if (userNameQuery.hasClauses() && !contains(searchQuery, userNameQuery)) {

        searchQuery.add(userNameQuery, BooleanClauseOccur.SHOULD);
    }

    BooleanQuery contentQuery = new BooleanQueryImpl();

    _repositorySearchQueryTermBuilder.addTerm(contentQuery, searchContext, Field.CONTENT, keywords);

    if (contentQuery.hasClauses() && !contains(searchQuery, contentQuery)) {
        searchQuery.add(contentQuery, BooleanClauseOccur.SHOULD);
    }
}

From source file:com.liferay.experts.questions.util.QuestionsIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    Question question = (Question) obj;//from w  w  w . ja  v  a 2  s.  c o m

    Document document = getBaseModelDocument(PORTLET_ID, question);

    document.addText(Field.CONTENT, question.getContent());
    document.addText(Field.TITLE, question.getTitle());
    document.addText("answers", getAnswers(question.getQuestionId()));

    return document;
}

From source file:com.liferay.experts.questions.util.QuestionsIndexer.java

License:Open Source License

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

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

    String content = snippet;/*from  w  ww .ja va 2 s  . com*/

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

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

    portletURL.setParameter("mvcPath", "/question/view_question.jsp");
    portletURL.setParameter("questionId", questionId);

    return new Summary(title, content, portletURL);
}

From source file:com.liferay.hook.indexer.MBMessageIndexerPostProcessor.java

License:Open Source License

@Override
public void postProcessDocument(Document document, Object object) throws Exception {

    MBMessage mbMessage = (MBMessage) object;

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

    // Get all avilable languages of this site to create indexs for all of
    // them.//from  w w  w .j  ava 2  s.co  m
    //
    // To get Site Language, use LocaleThreadLocal.getSiteDefaultLocale()
    // To get Display language, use
    // LocaleThreadLocal.getThemeDisplayLocale()
    Long groupId = mbMessage.getGroupId();
    Locale locales[] = LanguageUtil.getAvailableLocales(groupId);

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

    if (content.length() <= 0) {
        return;
    }

    for (int i = 0; i < locales.length; i++) {
        contentsMap.put(locales[i], content);
        titleMap.put(locales[i], title);
    }
    document.addLocalizedText(Field.TITLE, titleMap);
    document.addLocalizedText(Field.CONTENT, contentsMap);
}

From source file:com.liferay.hook.indexer.MBMessageIndexerPostProcessor.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    String[] fields = { Field.CONTENT, Field.TITLE };
    addSearchTerms(searchQuery, searchContext, fields, false);

}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

public JournalArticleIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.ARTICLE_ID, Field.COMPANY_ID,
            Field.DEFAULT_LANGUAGE_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
            Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.VERSION, Field.UID);
    setDefaultSelectedLocalizedFieldNames(Field.CONTENT, Field.DESCRIPTION, Field.TITLE);
    setFilterSearch(true);/*from  w  w  w  . j  av  a2s  .c o  m*/
    setPermissionAware(true);
    setSelectAllLocales(true);
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
        SearchContext searchContext) throws Exception {

    addSearchTerm(searchQuery, searchContext, Field.ARTICLE_ID, false);
    addSearchTerm(searchQuery, searchContext, Field.CLASS_PK, false);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.CONTENT, false);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
    addSearchTerm(searchQuery, searchContext, Field.ENTRY_CLASS_PK, false);
    addSearchLocalizedTerm(searchQuery, searchContext, Field.TITLE, false);
    addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
        String expandoAttributes = (String) params.get("expandoAttributes");

        if (Validator.isNotNull(expandoAttributes)) {
            addSearchExpando(searchQuery, searchContext, expandoAttributes);
        }/*from ww  w  .j a  va2s  .  co  m*/
    }
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(JournalArticle journalArticle) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, journalArticle);

    long classPK = journalArticle.getId();

    if (!isIndexAllArticleVersions()) {
        classPK = journalArticle.getResourcePrimKey();
    }// ww w . ja  va  2 s . com

    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.addKeywordSortable(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;
}