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

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

Introduction

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

Prototype

String CLASS_NAME_ID

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

Click Source Link

Usage

From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java

License:Open Source License

@Override
public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext)
        throws Exception {

    addStatus(contextBooleanFilter, searchContext);

    boolean discussion = GetterUtil.getBoolean(searchContext.getAttribute("discussion"));

    contextBooleanFilter.addRequiredTerm("discussion", discussion);

    if (searchContext.isIncludeDiscussions()) {
        addRelatedClassNames(contextBooleanFilter, searchContext);
    }/*from w  w  w .  j a v a 2 s  .c o m*/

    String classNameId = GetterUtil.getString(searchContext.getAttribute(Field.CLASS_NAME_ID));

    if (Validator.isNotNull(classNameId)) {
        contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId);
    }

    long threadId = GetterUtil.getLong((String) searchContext.getAttribute("threadId"));

    if (threadId > 0) {
        contextBooleanFilter.addRequiredTerm("threadId", threadId);
    }

    long[] categoryIds = searchContext.getCategoryIds();

    if ((categoryIds != null) && (categoryIds.length > 0)
            && (categoryIds[0] != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) {

        TermsFilter categoriesTermsFilter = new TermsFilter(Field.CATEGORY_ID);

        for (long categoryId : categoryIds) {
            try {
                mbCategoryService.getCategory(categoryId);
            } catch (PortalException pe) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Unable to get message boards category " + categoryId, pe);
                }

                continue;
            }

            categoriesTermsFilter.addValue(String.valueOf(categoryId));
        }

        if (!categoriesTermsFilter.isEmpty()) {
            contextBooleanFilter.add(categoriesTermsFilter, BooleanClauseOccur.MUST);
        }
    }
}

From source file:com.liferay.message.boards.internal.search.MBThreadIndexer.java

License:Open Source License

public MBThreadIndexer() {
    setDefaultSelectedFieldNames(Field.CLASS_NAME_ID, Field.CLASS_PK, Field.COMPANY_ID, Field.ENTRY_CLASS_NAME,
            Field.ENTRY_CLASS_PK, Field.UID);
    setFilterSearch(true);/*from   w  ww.j a  v  a2  s. c om*/
    setPermissionAware(true);
}

From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, long groupId, long classNameId, String articleId, String title,
        String description, String content, String type, String status, String structureId, String templateId,
        LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort)
        throws SystemException {

    try {//from w  w  w . j a v  a 2  s  .com
        Map<String, Serializable> attributes = new HashMap<String, Serializable>();

        attributes.put(Field.CLASS_NAME_ID, classNameId);
        attributes.put(Field.CONTENT, content);
        attributes.put(Field.DESCRIPTION, description);
        attributes.put(Field.STATUS, status);
        attributes.put(Field.TITLE, title);
        attributes.put(Field.TYPE, type);
        attributes.put("articleId", articleId);
        attributes.put("params", params);
        attributes.put("structureId", structureId);
        attributes.put("templateId", templateId);

        SearchContext searchContext = new SearchContext();

        searchContext.setAndSearch(andSearch);
        searchContext.setAttributes(attributes);
        searchContext.setCompanyId(companyId);
        searchContext.setGroupIds(new long[] { groupId });
        searchContext.setEnd(end);

        String keywords = (String) params.remove("keywords");

        if (Validator.isNotNull(keywords)) {
            searchContext.setKeywords(keywords);
        }

        searchContext.setSorts(new Sort[] { sort });

        QueryConfig queryConfig = new QueryConfig();

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

        searchContext.setQueryConfig(queryConfig);

        searchContext.setStart(start);

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

        return indexer.search(searchContext);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if ((classNameId != null) && (classNameId.longValue() != 0)) {
        contextQuery.addRequiredTerm("classNameId", classNameId.toString());
    }/*w w w. jav  a  2 s .c  o  m*/

    addStatus(contextQuery, searchContext);

    addSearchClassTypeIds(contextQuery, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

        String[] ddmStructureFieldNameParts = StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

        DDMStructure structure = DDMStructureLocalServiceUtil
                .getStructure(GetterUtil.getLong(ddmStructureFieldNameParts[1]));

        String fieldName = StringUtil.replaceLast(ddmStructureFieldNameParts[2],
                StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
                StringPool.BLANK);

        try {
            ddmStructureFieldValue = DDMUtil.getIndexedFieldValue(ddmStructureFieldValue,
                    structure.getFieldType(fieldName));
        } catch (StructureFieldException sfe) {
        }

        contextQuery.addRequiredTerm(ddmStructureFieldName,
                StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

    String articleType = (String) searchContext.getAttribute("articleType");

    if (Validator.isNotNull(articleType)) {
        contextQuery.addRequiredTerm(Field.TYPE, articleType);
    }

    String ddmStructureKey = (String) searchContext.getAttribute("ddmStructureKey");

    if (Validator.isNotNull(ddmStructureKey)) {
        contextQuery.addRequiredTerm("ddmStructureKey", ddmStructureKey);
    }

    String ddmTemplateKey = (String) searchContext.getAttribute("ddmTemplateKey");

    if (Validator.isNotNull(ddmTemplateKey)) {
        contextQuery.addRequiredTerm("ddmTemplateKey", ddmTemplateKey);
    }
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if (classNameId != null) {
        contextQuery.addRequiredTerm("classNameId", classNameId.toString());
    }/*from  w w  w. java  2s .  c  o  m*/

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS),
            WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }

    String articleType = (String) searchContext.getAttribute("articleType");

    if (Validator.isNotNull(articleType)) {
        contextQuery.addRequiredTerm(Field.TYPE, articleType);
    }

    String structureId = (String) searchContext.getAttribute("structureId");

    if (Validator.isNotNull(structureId)) {
        contextQuery.addRequiredTerm("structureId", structureId);
    }

    String templateId = (String) searchContext.getAttribute("templateId");

    if (Validator.isNotNull(templateId)) {
        contextQuery.addRequiredTerm("templateId", templateId);
    }
}

From source file:org.fit.portlet.service.service.impl.InserFitxaPersonalLocalServiceImpl.java

License:Open Source License

private Hits searchFitxaPersonalHits(long companyId, long groupId, long[] organizationIds, String searchText,
        long tecnicReferent, long codiProjecte, long serveiSocial, int start, int end, String orderByCol,
        String orderByType) {//w w w. j  av a2  s .co  m

    try {
        String searchEngineId = SearchEngineUtil.getDefaultSearchEngineId();

        SearchEngine searchEngine = SearchEngineUtil.getSearchEngine(searchEngineId);

        BooleanQueryFactory booleanQueryFactory = searchEngine.getBooleanQueryFactory();

        BooleanQuery query = booleanQueryFactory.create();

        // Context query
        query.addRequiredTerm(Field.COMPANY_ID, companyId);

        query.addRequiredTerm(Field.CLASS_NAME_ID, InserFitxaPersonal.class.getName());

        if (groupId > -1) {
            query.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if (Validator.isNotNull(organizationIds)) {

            BooleanQuery organizationQuery = booleanQueryFactory.create();

            if (organizationIds.length > 1 && organizationIds[0] == -2) {

                BooleanQuery q = booleanQueryFactory.create();

                SearchContext searchContext = new SearchContext();
                TermRangeQuery oq = TermRangeQueryFactoryUtil.create(searchContext, Field.ORGANIZATION_ID, "-1",
                        "0", true, false);

                q.add(oq, BooleanClauseOccur.SHOULD);

                // L'usuari vol veure tots els que estan sense localitzaci
                query.add(q, BooleanClauseOccur.MUST);
            } else {

                for (long idorg : organizationIds) {
                    if (idorg > -1) {
                        organizationQuery.addTerm(Field.ORGANIZATION_ID, idorg);
                    }
                }
            }

            if (organizationQuery.hasClauses()) {
                query.add(organizationQuery, BooleanClauseOccur.MUST);
            }

        }

        if (Validator.isNotNull(searchText)) {

            BooleanQuery searchTextQuery = booleanQueryFactory.create();

            searchTextQuery.addExactTerm(GestioPersonesIndexConstants.NUM_EXPEDIENT, searchText);
            searchTextQuery.addExactTerm(GestioPersonesIndexConstants.DNI, searchText);
            searchTextQuery.addTerm(Field.DESCRIPTION, searchText);
            searchTextQuery.addTerm(Field.TITLE, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.TECNIC_REFERENT, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.OBSERVACIONS, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.SEGUIMENT_ITINERARI, searchText);
            searchTextQuery.addTerm(GestioPersonesIndexConstants.SEGUIMENT_ITINERARI, searchText);

            query.add(searchTextQuery, BooleanClauseOccur.MUST);

        }
        // Cerca avanada
        if (tecnicReferent > -1) {
            query.addRequiredTerm(GestioPersonesIndexConstants.TECNIC_REFERENT_ID, tecnicReferent);
        }

        if (codiProjecte > -1) {
            query.addRequiredTerm(GestioPersonesIndexConstants.CODI_PROJECTE_ID, codiProjecte);
        }

        if (serveiSocial > -1) {
            query.addRequiredTerm(GestioPersonesIndexConstants.SERVEI_SOCIAL_ID, serveiSocial);
        }

        Sort sort = new Sort();
        sort.setReverse(false);

        if (Validator.isNotNull(orderByCol)) {

            int type = getType(orderByCol);

            sort.setType(type);

            sort.setFieldName(orderByCol);

            if (Validator.isNotNull(orderByType)) {

                if (orderByType.equalsIgnoreCase("desc")) {
                    sort.setReverse(true);
                }

            }

        }

        log.info(query.toString() + " " + sort.toString());

        Hits search = SearchEngineUtil.search(searchEngineId, companyId, query, sort, start, end);

        return search;
    } catch (SearchException e) {
        log.error(e);
    } catch (ParseException e) {
        log.error(e);
    }

    return null;
}

From source file:org.liferay.jukebox.util.AlbumIndexer.java

License:Open Source License

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

    if (obj instanceof DLFileEntry) {
        DLFileEntry dlFileEntry = (DLFileEntry) obj;

        Album album = AlbumLocalServiceUtil.getAlbum(GetterUtil.getLong(dlFileEntry.getTitle()));

        document.addKeyword(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(Album.class.getName()));
        document.addKeyword(Field.CLASS_PK, album.getAlbumId());
        document.addKeyword(Field.RELATED_ENTRY, true);
    }/*w w  w.  j  a  v a 2s.com*/
}

From source file:org.liferay.jukebox.util.ArtistIndexer.java

License:Open Source License

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

    if (obj instanceof DLFileEntry) {
        DLFileEntry dlFileEntry = (DLFileEntry) obj;

        Artist artist = ArtistLocalServiceUtil.getArtist(GetterUtil.getLong(dlFileEntry.getTitle()));

        document.addKeyword(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(Artist.class.getName()));
        document.addKeyword(Field.CLASS_PK, artist.getArtistId());
        document.addKeyword(Field.RELATED_ENTRY, true);
    }/*from  w ww  . j ava2  s  .  c  o  m*/
}

From source file:org.liferay.jukebox.util.SongIndexer.java

License:Open Source License

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

    if (obj instanceof DLFileEntry) {
        DLFileEntry dlFileEntry = (DLFileEntry) obj;

        Song song = SongLocalServiceUtil.getSong(GetterUtil.getLong(dlFileEntry.getTitle()));

        document.addKeyword(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(Song.class.getName()));
        document.addKeyword(Field.CLASS_PK, song.getSongId());
        document.addKeyword(Field.RELATED_ENTRY, true);
    }/*from ww  w.j  av a2  s .c o  m*/
}