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

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

Introduction

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

Prototype

String GROUP_ID

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

Click Source Link

Usage

From source file:com.vportal.portlet.vcms.service.impl.VcmsArticleServiceImpl.java

License:Open Source License

public Hits search(long companyId, long groupId, long userId, String keywords, int start, int end)
        throws SystemException {
    try {/*  w  w  w  . j  a va  2 s . com*/
        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();

        contextQuery.addRequiredTerm(Field.PORTLET_ID, PortletKeysExt.VCMS);

        if (groupId > 0) {
            contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if (userId > 0) {
            contextQuery.addRequiredTerm(Field.USER_ID, userId);
        }

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(keywords)) {
            searchQuery.addTerm(Field.TITLE, keywords);
            searchQuery.addTerm(Field.DESCRIPTION, keywords);
            searchQuery.addTerm(Field.CONTENT, keywords);
            /*searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);*/
            searchQuery.addTerm(Field.ASSET_TAG_NAMES, keywords);
        }

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

        if (searchQuery.clauses().size() > 0) {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        }

        return SearchEngineUtil.search(companyId, fullQuery, start, end);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.vportal.portlet.vcms.util.SearchIndexer.java

License:Open Source License

public static Document getAddArticleDocument(long companyId, long groupId, String articleId, String title,
        String description, String content) throws NumberFormatException, PortalException, SystemException {

    InputStream is = null;//ww  w .j  ava2 s. co m
    List addedAttachments = AttachmentLocalServiceUtil.getAttachments(Long.parseLong(articleId),
            VcmsArticle.class);
    for (int i = 0; i < addedAttachments.size(); i++) {
        Attachment attachment = (Attachment) addedAttachments.get(i);
        DLFileEntry entry = null;
        try {
            entry = (DLFileEntry) DLFileEntryLocalServiceUtil.getFileEntry(attachment.getFileEntryId());
            /*String fileExtension = entry.getTitleWithExtension();
            String extension = fileExtension.substring(fileExtension.lastIndexOf(".")+1,fileExtension.length());*/
            String extension = entry.getExtension();
            is = DLLocalServiceUtil.getFileAsStream(companyId, entry.getFolderId(), entry.getName());
            content = FileUtilExt.getContentFile(is, content, extension);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }
    content = HtmlUtil.extractText(content);
    Document doc = new DocumentImpl();
    doc.addUID(PORTLET_ID, articleId);

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

    doc.addText(Field.TITLE, title);
    doc.addText(Field.CONTENT, content);
    doc.addText(Field.DESCRIPTION, description);
    doc.addModifiedDate();

    doc.addKeyword(Field.ENTRY_CLASS_NAME, VcmsArticle.class.getName());
    doc.addKeyword(Field.ENTRY_CLASS_PK, articleId);
    return doc;
}

From source file:com.vportal.portlet.vfaq.service.impl.FAQQuestionLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, long groupId, long userId, String keywords, int start, int end)
        throws SystemException {
    try {//  ww w.  j av  a 2s .c om
        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();

        contextQuery.addRequiredTerm(Field.PORTLET_ID, PortletKeysExt.FAQ_QUESTION);

        if (groupId > 0) {
            contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if (userId > 0) {
            contextQuery.addRequiredTerm(Field.USER_ID, userId);
        }

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(keywords)) {
            searchQuery.addTerm(Field.TITLE, keywords);
            searchQuery.addTerm(Field.CONTENT, keywords);
            /*searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);*/
        }

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

        if (searchQuery.clauses().size() > 0) {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        }

        return SearchEngineUtil.search(companyId, fullQuery, start, end);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.vportal.portlet.vlegal.service.impl.VLegalDocumentServiceImpl.java

License:Open Source License

public Hits search(long companyId, long groupId, long userId, String keywords, int start, int end)
        throws SystemException {
    try {/*w w w.  j av a 2 s  .c  om*/
        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();

        contextQuery.addRequiredTerm(Field.PORTLET_ID, PortletKeysExt.VLEGAL);

        if (groupId > 0) {
            contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if (userId > 0) {
            contextQuery.addRequiredTerm(Field.USER_ID, userId);
        }

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(keywords)) {
            searchQuery.addTerm(Field.TITLE, keywords);
            searchQuery.addTerm(Field.CONTENT, keywords);
            searchQuery.addTerm(Field.ASSET_TAG_NAMES, keywords);
        }

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

        if (searchQuery.clauses().size() > 0) {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        }

        return SearchEngineUtil.search(companyId, fullQuery, start, end);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:gr.open.loglevelsmanager.loglevel.util.LogLevelIndexer.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;//  w  w  w. j  a  v a 2s .co  m

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

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

    long plid = 0;

    try {
        plid = LogLevelUtil.getPlid(Long.parseLong(groupId));
    } catch (Exception e) {
    }

    portletURL.setParameter("p_l_id", String.valueOf(plid));
    portletURL.setParameter("view", "editLogLevel");
    portletURL.setParameter("LogLevelId", String.valueOf(entryId));
    portletURL.setParameter("editType", "view");

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

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) {//from  w  ww.  j  a  v  a  2s  .  c  o 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.opencps.dossiermgt.search.DossierFileIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    // TODO Auto-generated method stub
    DossierFile dossierFile = (DossierFile) obj;

    Document document = getBaseModelDocument(PORTLET_ID, dossierFile);

    if (dossierFile.getDisplayName() != null && !Validator.isBlank(dossierFile.getDisplayName())) {
        Field field = new Field(DossierFileDisplayTerms.DISPLAY_NAME,
                dossierFile.getDisplayName().toLowerCase().split("\\s+"));
        field.setBoost(5);// w  w w .j a va2 s .  co  m
        document.add(field);
    }

    if (dossierFile.getModifiedDate() != null) {
        document.addDate(Field.MODIFIED_DATE, dossierFile.getModifiedDate());
    }
    if (dossierFile.getFormData() != null && !Validator.isBlank(dossierFile.getFormData())) {
        document.addText(DossierFileDisplayTerms.FORM_DATA,
                dossierFile.getFormData().toLowerCase().split("\\s+"));
    }
    if (dossierFile.getDossierFileNo() != null && !Validator.isBlank(dossierFile.getDossierFileNo())) {
        document.addText(DossierFileDisplayTerms.DOSSIER_FILE_NO, dossierFile.getDossierFileNo());
    }
    document.addNumber(DossierFileDisplayTerms.DOSSIER_FILE_ID, dossierFile.getDossierFileId());
    document.addKeyword(Field.GROUP_ID, getSiteGroupId(dossierFile.getGroupId()));
    document.addKeyword(Field.SCOPE_GROUP_ID, dossierFile.getGroupId());

    return document;
}

From source file:org.opencps.dossiermgt.search.DossierIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    // TODO Auto-generated method stub
    Dossier dossier = (Dossier) obj;/*  www .  j  a  va2 s. com*/

    Document document = getBaseModelDocument(PORTLET_ID, dossier);

    if (dossier.getReceptionNo() != null && !Validator.isBlank(dossier.getReceptionNo())) {
        Field field = new Field(DossierDisplayTerms.RECEPTION_NO, dossier.getReceptionNo());
        field.setBoost(5);
        document.add(field);
    }
    if (dossier.getModifiedDate() != null) {
        document.addDate(Field.MODIFIED_DATE, dossier.getModifiedDate());
    }
    if (dossier.getCityName() != null && !Validator.isBlank(dossier.getCityName())) {
        document.addText(DossierDisplayTerms.CITY_NAME, dossier.getCityName().toLowerCase().split("\\s+"));
    }
    if (dossier.getExternalRefNo() != null && !Validator.isBlank(dossier.getExternalRefNo())) {
        document.addText(DossierDisplayTerms.EXTERNALREF_NO, dossier.getExternalRefNo());
    }
    if (dossier.getExternalRefUrl() != null && !Validator.isBlank(dossier.getExternalRefUrl())) {
        document.addText(DossierDisplayTerms.EXTERNALREF_URL, dossier.getExternalRefUrl());
    }
    if (dossier.getGovAgencyName() != null && !Validator.isBlank(dossier.getGovAgencyName())) {
        document.addText(DossierDisplayTerms.GOVAGENCY_NAME,
                dossier.getGovAgencyName().toLowerCase().split("\\s+"));
    }
    if (dossier.getSubjectName() != null && !Validator.isBlank(dossier.getSubjectName())) {
        document.addText(DossierDisplayTerms.SUBJECT_NAME,
                dossier.getSubjectName().toLowerCase().split("\\s+"));
    }
    if (dossier.getAddress() != null && !Validator.isBlank(dossier.getAddress())) {
        document.addText(DossierDisplayTerms.ADDRESS, dossier.getAddress().toLowerCase().split("\\s+"));
    }
    if (dossier.getCityCode() != null && !Validator.isBlank(dossier.getCityCode())) {
        document.addText(DossierDisplayTerms.CITY_CODE, dossier.getCityCode());
    }
    if (dossier.getDistrictCode() != null && !Validator.isBlank(dossier.getDistrictCode())) {
        document.addText(DossierDisplayTerms.DISTRICT_CODE, dossier.getDistrictCode());
    }
    if (dossier.getDistrictName() != null && !Validator.isBlank(dossier.getDistrictName())) {
        document.addText(DossierDisplayTerms.DISTRICT_NAME,
                dossier.getDistrictName().toLowerCase().split("\\s+"));
    }
    if (dossier.getWardCode() != null && !Validator.isBlank(dossier.getWardCode())) {
        document.addText(DossierDisplayTerms.WARD_CODE, dossier.getWardCode());
    }
    if (dossier.getWardName() != null && !Validator.isBlank(dossier.getWardName())) {
        document.addText(DossierDisplayTerms.WARD_NAME, dossier.getWardName().toLowerCase().split("\\s+"));
    }
    if (dossier.getContactName() != null && !Validator.isBlank(dossier.getContactName())) {
        document.addText(DossierDisplayTerms.CONTACT_NAME,
                dossier.getContactName().toLowerCase().split("\\s+"));
    }
    if (dossier.getContactTelNo() != null && !Validator.isBlank(dossier.getContactTelNo())) {
        document.addText(DossierDisplayTerms.CONTACT_TEL_NO, dossier.getContactTelNo());
    }
    if (dossier.getContactEmail() != null && !Validator.isBlank(dossier.getContactEmail())) {
        document.addText(DossierDisplayTerms.CONTACT_EMAIL, dossier.getContactEmail());
    }
    if (dossier.getNote() != null && !Validator.isBlank(dossier.getNote())) {
        document.addText(DossierDisplayTerms.NOTE, dossier.getNote().toLowerCase().split("\\s+"));
    }
    document.addNumber(DossierDisplayTerms.DOSSIER_ID, dossier.getDossierId());

    document.addKeyword(Field.GROUP_ID, getSiteGroupId(dossier.getGroupId()));
    document.addKeyword(Field.SCOPE_GROUP_ID, dossier.getGroupId());

    return document;
}

From source file:org.xcolab.portlets.discussions.Indexer.java

License:Open Source License

@Override
public Document getDocument(Object obj) throws SearchException {

    DiscussionMessage message = (DiscussionMessage) obj;

    Document doc = new DocumentImpl();

    doc.addUID(PORTLET_ID, message.getMessageId());

    doc.addModifiedDate(message.getCreateDate());

    doc.addKeyword(Field.COMPANY_ID, 10112L);
    doc.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    doc.addKeyword(Field.GROUP_ID, message.getCategoryGroupId());

    doc.addText(Field.TITLE, message.getSubject());
    doc.addText(Field.CONTENT, message.getBody());

    doc.addKeyword(Field.ENTRY_CLASS_NAME, DiscussionMessage.class.getName());
    doc.addKeyword(Field.ENTRY_CLASS_PK, message.getMessageId());
    return doc;//from  w w w.  ja  v a  2  s .c  o  m
}

From source file:org.xcolab.portlets.search.Indexer.java

License:Open Source License

public static Document getArticleDocument(long companyId, long groupId, String articleId, double version,
        String title, String description, String content, String type, Date displayDate,
        String[] tagsCategories, String[] tagsEntries, ExpandoBridge expandoBridge) {

    if ((content != null)
            && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) {

        content = _getIndexableContent(content);

        content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK);
        content = StringUtil.replace(content, "]]>", StringPool.BLANK);
    }//from   w  w  w.j a  va2 s  .c o m

    content = StringUtil.replace(content, "&amp;", "&");
    content = StringUtil.replace(content, "&lt;", "<");
    content = StringUtil.replace(content, "&gt;", ">");

    content = HtmlUtil.extractText(content);

    Document doc = new DocumentImpl();

    // check if this is an most recent version of an article
    JournalArticle article;
    boolean isOld = false;
    try {
        article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId);
        if (article.getVersion() != version) {
            isOld = true;
        }
    } catch (Exception e1) {
        e1.printStackTrace();
        // ignore
    }

    if (isOld) {
        doc.addUID(PORTLET_ID, articleId, "old");
    } else {
        doc.addUID(PORTLET_ID, articleId);
    }

    doc.addModifiedDate(displayDate);

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

    doc.addText(Field.TITLE, title);
    doc.addText(Field.CONTENT, content);
    doc.addText(Field.DESCRIPTION, description);

    doc.addKeyword(Field.ENTRY_CLASS_PK, articleId);
    doc.addKeyword(Field.VERSION, version);
    doc.addKeyword(Field.TYPE, type);

    ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge);

    try {
        Layout pageLayout = getLayoutForContent(articleId);

        if (pageLayout != null) {
            Layout tmp = pageLayout;
            boolean isAbout = false;
            while (tmp != null && !isAbout) {
                if (tmp.getFriendlyURL().toLowerCase().contains("/about")
                        || tmp.getFriendlyURL().toLowerCase().contains("/contests")) {
                    isAbout = true;
                }
                if (tmp.getParentLayoutId() > 0) {
                    try {
                        tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(),
                                tmp.getParentLayoutId());

                    } catch (com.liferay.portal.NoSuchLayoutException e) {
                        tmp = null;
                    } catch (PortalException e) {
                        tmp = null;
                    }
                } else {
                    tmp = null;
                }
            }

            if (isAbout) {
                doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL());
                doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index");
            }
        } else {
            doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
        }
    } catch (SystemException e) {
        doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
        e.printStackTrace();
    }
    return doc;
}