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

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

Introduction

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

Prototype

String TITLE

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

Click Source Link

Usage

From source file:org.xmlportletfactory.olafk.customer.util.InvoicesIndexer.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 . ja v a2 s .  com

    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 = InvoicesUtil.getPlid(Long.parseLong(groupId));
    } catch (Exception e) {
    }

    portletURL.setParameter("p_l_id", String.valueOf(plid));
    portletURL.setParameter("view", "editInvoices");
    portletURL.setParameter("invoiceId", String.valueOf(entryId));
    portletURL.setParameter("editType", "view");

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

From source file:se.gothiaforum.controller.actorssearch.ActorsSearchController.java

License:Open Source License

private void setArticleContentAndTitle(ThemeDisplay themeDisplay, QueryResponse queryResponse, SolrDocument doc,
        ActorArticle actorArticle) throws PortalException, SystemException {
    StringBuilder sb = new StringBuilder();

    Map<String, Map<String, List<String>>> highlighting = queryResponse.getHighlighting();

    String highlightTitle = null;
    String highlightName = null;//from   w w  w  .j  a va 2 s  . c o m
    String highlightOrg = null;
    List<String> highlightDetailedDescriptionList = null;
    List<String> highlightIntroList = null;
    List<String> highlightTagsList = null;

    // System.out.println("highlighting " + highlighting);

    if (highlighting != null) {

        Map<String, List<String>> highlightedFields = highlighting.get(doc.get("uid"));

        // Title highlighting
        List<String> title = highlightedFields.get(Field.TITLE);
        if (title != null && title.size() > 0) {
            highlightTitle = title.get(0); // Probably rare with more than one but first should always be enough.
        }

        // Name highlighting
        List<String> name = highlightedFields.get(ActorsConstants.ARTICLE_XML_COMPANY_NAME);
        if (name != null && name.size() > 0) {
            highlightName = name.get(0); // Probably rare with more than one but first should always be
            // enough.
        }

        // Organisation name highlighting
        List<String> orgName = highlightedFields.get(ActorsConstants.ARTICLE_XML_ORGANIZATION_NAME);

        if (orgName != null && orgName.size() > 0) {
            highlightOrg = orgName.get(0); // Probably rare with more than one but first should always be
            // enough.
        }

        // Detailed Description highlighting
        highlightDetailedDescriptionList = highlightedFields
                .get(ActorsConstants.ARTICLE_XML_DETAILED_DISCRIPTION);

        // Detailed Description highlighting
        highlightIntroList = highlightedFields.get(ActorsConstants.ARTICLE_XML_INTRO);

        // If no highlighting in highlightIntroList use highlightDetailedDescriptionList if if there is anyone
        // there.
        if (highlightIntroList == null && highlightDetailedDescriptionList != null) {
            highlightIntroList = highlightDetailedDescriptionList;
        }

        // Asset tag highlighting
        highlightTagsList = highlightedFields.get(Field.ASSET_TAG_NAMES);
    }

    if (highlightTitle != null) {
        actorArticle.setTitle(stripLanguageSuffix(highlightTitle));
    } else {
        actorArticle.setTitle(stripLanguageSuffix((String) doc.getFieldValue(Field.TITLE)));
    }

    if (highlightName != null) {
        actorArticle.setName(highlightName);
    } else {
        String name = (String) doc.getFieldValue(ActorsConstants.ARTICLE_XML_COMPANY_NAME);
        actorArticle.setName(name);
    }

    if (highlightOrg != null) {
        actorArticle.setOrganizationName(highlightOrg);
    } else {
        String organisationName = (String) doc.getFieldValue(ActorsConstants.ARTICLE_XML_ORGANIZATION_NAME);
        actorArticle.setOrganizationName(organisationName);
    }

    if (highlightIntroList != null && highlightIntroList.size() > 0) {
        Iterator<String> iterator = highlightIntroList.iterator();
        while (true) {
            String content = iterator.next();

            // Remove all html start and closing tags except span tags which may hold the highlighting info. If another span tag is
            // included we may have a problem but this is the best we got for now. The highlighting info is created
            // by Solr for the response so those tags will never cause illegal html.
            content = content.replaceAll("</?+(?!span)([^>]*)>", "");

            sb.append(content);
            if (iterator.hasNext()) {
                sb.append("<b>... </b> ");
            } else {
                break;
            }
        }
        actorArticle.setIntro(sb.toString());
    } else {
        // No intro highlighting. Set article intro instead.
        actorArticle.setIntro((String) doc.getFieldValue(ActorsConstants.ARTICLE_XML_INTRO));
    }

    if (highlightDetailedDescriptionList != null && highlightDetailedDescriptionList.size() > 0) {
        Iterator<String> iterator = highlightDetailedDescriptionList.iterator();
        while (true) {
            String content = iterator.next();
            sb.append(content);
            if (iterator.hasNext()) {
                sb.append("<b>... </b> ");
            } else {
                break;
            }
        }
        actorArticle.setDetailedDescription(sb.toString());
    } else {
        // No detailed description highlighting. Set article detailed description instead.
        actorArticle.setDetailedDescription(
                (String) doc.getFieldValue(ActorsConstants.ARTICLE_XML_DETAILED_DISCRIPTION));
    }

    if (highlightTagsList != null && highlightTagsList.size() > 0) {
        StringBuilder tagsStr = new StringBuilder();
        for (String tag : highlightTagsList) {
            String commaOrNot = tagsStr.length() > 0 ? "," : ""; // If empty we don't add a comma before next tag.
            tagsStr.append(commaOrNot + tag);
        }

        addTheNonHighlightedTags(doc, tagsStr);

        actorArticle.setTagsStr(tagsStr.toString());
    } else {

        Object tags = doc.getFieldValue(Field.ASSET_TAG_NAMES);

        if (tags != null) {

            List<String> allTagsOfArticle = extractTags(tags);

            String tagsStr = StringUtils.join(allTagsOfArticle, ',');
            actorArticle.setTagsStr(tagsStr);
        }
    }
}