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.portlet.sample.service.impl.SampleEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long companyId, String title, String content, int start, int end)
        throws PortalException, SystemException {

    Indexer indexer = IndexerRegistryUtil.getIndexer(SampleEntry.class.getName());
    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    searchContext.setStart(start);//from w  w w  .  j  ava2  s .  co m
    searchContext.setEnd(end);
    searchContext.setAttribute(Field.TITLE, title);
    searchContext.setAttribute(Field.CONTENT, content);
    return indexer.search(searchContext);

}

From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java

License:Open Source License

private void addHighlights(Query query, SearchRequestBuilder searchRequestBuilder) {
    QueryConfig queryConfig = query.getQueryConfig();
    if (queryConfig.isHighlightEnabled()) {

        String localizedContentName = DocumentImpl.getLocalizedName(queryConfig.getLocale(), Field.CONTENT);

        String localizedTitleName = DocumentImpl.getLocalizedName(queryConfig.getLocale(), Field.TITLE);

        int fragmentSize = queryConfig.getHighlightFragmentSize();
        int numberOfFragments = queryConfig.getHighlightSnippetSize();
        searchRequestBuilder.addHighlightedField(Field.CONTENT, fragmentSize, numberOfFragments);
        searchRequestBuilder.addHighlightedField(Field.TITLE, fragmentSize, numberOfFragments);
        searchRequestBuilder.addHighlightedField(localizedContentName, fragmentSize, numberOfFragments);
        searchRequestBuilder.addHighlightedField(localizedTitleName, fragmentSize, numberOfFragments);

    }//from ww w. ja v  a2s . co  m
}

From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java

License:Open Source License

protected Hits processSearchHits(SearchResponse searchResponse, QueryConfig queryConfig) {

    Hits hits = new HitsImpl();
    List<Document> documents = new ArrayList<Document>();
    Set<String> queryTerms = new HashSet<String>();
    List<Float> scores = new ArrayList<Float>();
    List<String> snippets = new ArrayList<String>();
    SearchHits searchHits = searchResponse.getHits();

    if (searchHits.totalHits() > 0) {
        SearchHit[] searchHitsArray = searchHits.getHits();

        for (SearchHit searchHit : searchHitsArray) {
            Document document = processSearchHit(searchHit);
            documents.add(document);/*w ww. j  av a2  s. c  om*/
            scores.add(searchHit.getScore());

            String snippet = StringPool.BLANK;

            if (queryConfig.isHighlightEnabled()) {
                snippet = getSnippet(searchHit, queryConfig, queryTerms, searchHit.highlightFields(),
                        Field.CONTENT);

                if (Validator.isNull(snippet)) {
                    snippet = getSnippet(searchHit, queryConfig, queryTerms, searchHit.highlightFields(),
                            Field.TITLE);
                }

                if (Validator.isNotNull(snippet)) {
                    snippets.add(snippet);
                }
            }

        }
    }
    int totalHits = (int) searchHits.getTotalHits();
    _log.debug("Total Hits: " + totalHits);
    _log.debug("Total Documents size: " + documents.size());
    hits.setDocs(documents.toArray(new Document[documents.size()]));
    hits.setLength(totalHits);
    hits.setQueryTerms(queryTerms.toArray(new String[queryTerms.size()]));
    hits.setScores(scores.toArray(new Float[scores.size()]));
    hits.setSnippets(snippets.toArray(new String[snippets.size()]));

    return hits;
}

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 {/*from w w w  . java 2  s.c om*/
        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;//from   w  w w  .j  a v  a2 s . com
    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.vcms.util.SearchIndexer.java

License:Open Source License

public Summary getDocumentSummary(com.liferay.portal.kernel.search.Document doc, PortletURL portletURL) {

    // Title//from  w  w  w.  j ava 2s  . c  om

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

    // Content

    String content = doc.get(Field.CONTENT);

    content = StringUtil.shorten(content, 200);

    // Portlet URL

    String articleId = doc.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/vcmsviewcontent/view");
    portletURL.setParameter("articleId", articleId);
    VcmsCARelation category = null;
    try {
        category = VcmsCARelationServiceUtil.findRelationsByArticle(articleId);
    } catch (Exception e) {
        // TODO: handle exception
    }
    String categoryId = "";
    if (category != null) {
        categoryId = String.valueOf(category.getCategoryId());
    }
    portletURL.setParameter("categoryId", categoryId);
    return new Summary(title, content, portletURL);
}

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 {/* w  ww  .j  a va  2  s .  c  o m*/
        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 {//from ww w .  j a  va2  s  .c  o  m
        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  2 s .c o  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.rsc.liferay.solr.SolrIndexSearcher.java

License:Open Source License

protected Hits subset(SolrQuery solrQuery, Query query, QueryConfig queryConfig, QueryResponse queryResponse,
        boolean allResults) throws Exception {

    long startTime = System.currentTimeMillis();

    Hits hits = new HitsImpl();

    SolrDocumentList solrDocumentList = queryResponse.getResults();

    long total = solrDocumentList.getNumFound();

    if (allResults && (total > 0)) {
        solrQuery.setRows((int) total);

        queryResponse = _solrServer.query(solrQuery);

        return subset(solrQuery, query, queryConfig, queryResponse, false);
    }/*from   w  ww  .ja v a 2s. co m*/

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

    float maxScore = -1;
    Set<String> queryTerms = new HashSet<String>();
    int subsetTotal = 0;

    for (SolrDocument solrDocument : solrDocumentList) {
        Document document = new DocumentImpl();

        Collection<String> names = solrDocument.getFieldNames();

        for (String name : names) {
            Collection<Object> fieldValues = solrDocument.getFieldValues(name);

            Field field = new Field(name,
                    ArrayUtil.toStringArray(fieldValues.toArray(new Object[fieldValues.size()])));

            document.add(field);
        }

        documents.add(document);

        String snippet = StringPool.BLANK;

        if (queryConfig.isHighlightEnabled()) {
            snippet = getSnippet(solrDocument, queryConfig, queryTerms, queryResponse.getHighlighting(),
                    Field.CONTENT);

            if (Validator.isNull(snippet)) {
                snippet = getSnippet(solrDocument, queryConfig, queryTerms, queryResponse.getHighlighting(),
                        Field.TITLE);
            }

            if (Validator.isNotNull(snippet)) {
                snippets.add(snippet);
            }
        }

        if (queryConfig.isScoreEnabled()) {
            float score = GetterUtil.getFloat(String.valueOf(solrDocument.getFieldValue("score")));

            if (score > maxScore) {
                maxScore = score;
            }

            scores.add(score);
        } else {
            scores.add(maxScore);
        }

        subsetTotal++;
    }

    hits.setDocs(documents.toArray(new Document[subsetTotal]));
    hits.setLength((int) total);
    hits.setQuery(query);
    hits.setQueryTerms(queryTerms.toArray(new String[queryTerms.size()]));

    Float[] scoresArray = scores.toArray(new Float[subsetTotal]);

    if (queryConfig.isScoreEnabled() && (subsetTotal > 0) && (maxScore > 0)) {

        for (int i = 0; i < scoresArray.length; i++) {
            scoresArray[i] = scoresArray[i] / maxScore;
        }
    }

    hits.setScores(scoresArray);

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

    hits.setSearchTime(searchTime);
    hits.setSnippets(snippets.toArray(new String[subsetTotal]));
    hits.setStart(startTime);

    return hits;
}