Example usage for com.liferay.portal.kernel.search SearchContext setStart

List of usage examples for com.liferay.portal.kernel.search SearchContext setStart

Introduction

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

Prototype

public void setStart(int start) 

Source Link

Usage

From source file:com.liferay.content.targeting.service.impl.UserSegmentLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long groupId, String keywords, int start, int end)
        throws PortalException, SystemException {

    SearchContext searchContext = new SearchContext();

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);//from  w  w w  . j a va  2  s. c om
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);
    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormViewRecordsDisplayContext.java

License:Open Source License

protected void updateSearchContainerResults() {
    List<DDLRecord> results = null;
    int total = 0;

    DisplayTerms displayTerms = _recordSearchContainer.getDisplayTerms();

    int status = WorkflowConstants.STATUS_ANY;

    if (Validator.isNull(displayTerms.getKeywords())) {
        results = _ddlRecordLocalService.getRecords(_ddlRecordSet.getRecordSetId(), status,
                _recordSearchContainer.getStart(), _recordSearchContainer.getEnd(),
                _recordSearchContainer.getOrderByComparator());
        total = _ddlRecordLocalService.getRecordsCount(_ddlRecordSet.getRecordSetId(), status);
    } else {/* w w w . j  av  a  2s. c o m*/
        SearchContext searchContext = SearchContextFactory
                .getInstance(PortalUtil.getHttpServletRequest(_renderRequest));

        searchContext.setAttribute(Field.STATUS, status);
        searchContext.setAttribute("recordSetId", _ddlRecordSet.getRecordSetId());
        searchContext.setAttribute("recordSetScope", _ddlRecordSet.getScope());
        searchContext.setEnd(_recordSearchContainer.getEnd());
        searchContext.setKeywords(displayTerms.getKeywords());
        searchContext.setStart(_recordSearchContainer.getStart());

        BaseModelSearchResult<DDLRecord> baseModelSearchResult = _ddlRecordLocalService
                .searchDDLRecords(searchContext);

        results = baseModelSearchResult.getBaseModels();
        total = baseModelSearchResult.getLength();
    }

    _recordSearchContainer.setResults(results);
    _recordSearchContainer.setTotal(total);
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.display.context.DDMFormViewFormInstanceRecordsDisplayContext.java

License:Open Source License

protected void updateSearchContainerResults() {
    List<DDMFormInstanceRecord> results = null;
    int total = 0;

    DisplayTerms displayTerms = _ddmFormInstanceRecordSearchContainer.getDisplayTerms();

    int status = WorkflowConstants.STATUS_ANY;

    if (Validator.isNull(displayTerms.getKeywords())) {
        results = _ddmFormInstanceRecordLocalService.getFormInstanceRecords(
                _ddmFormInstance.getFormInstanceId(), status, _ddmFormInstanceRecordSearchContainer.getStart(),
                _ddmFormInstanceRecordSearchContainer.getEnd(),
                _ddmFormInstanceRecordSearchContainer.getOrderByComparator());
        total = _ddmFormInstanceRecordLocalService
                .getFormInstanceRecordsCount(_ddmFormInstance.getFormInstanceId(), status);
    } else {/*from w w  w.j a  va  2 s.c om*/
        SearchContext searchContext = SearchContextFactory
                .getInstance(PortalUtil.getHttpServletRequest(_renderRequest));

        searchContext.setAttribute(Field.STATUS, status);
        searchContext.setAttribute("formInstanceId", _ddmFormInstance.getFormInstanceId());
        searchContext.setEnd(_ddmFormInstanceRecordSearchContainer.getEnd());
        searchContext.setKeywords(displayTerms.getKeywords());
        searchContext.setStart(_ddmFormInstanceRecordSearchContainer.getStart());

        BaseModelSearchResult<DDMFormInstanceRecord> baseModelSearchResult = _ddmFormInstanceRecordLocalService
                .searchFormInstanceRecords(searchContext);

        results = baseModelSearchResult.getBaseModels();
        total = baseModelSearchResult.getLength();
    }

    _ddmFormInstanceRecordSearchContainer.setResults(results);
    _ddmFormInstanceRecordSearchContainer.setTotal(total);
}

From source file:com.liferay.experts.service.impl.QuestionLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, long groupId, String keywords, LinkedHashMap<String, Object> params,
        int start, int end, Sort sort) throws SystemException {

    try {/*from   w  w w  . ja va2 s.  com*/
        SearchContext searchContext = new SearchContext();

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

        if (params != null) {
            if (Validator.isNull(keywords)) {
                keywords = (String) params.get("keywords");
            }

            params.remove("keywords");
        }

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

        QueryConfig queryConfig = new QueryConfig();

        queryConfig.setHighlightEnabled(false);

        searchContext.setQueryConfig(queryConfig);

        if (sort != null) {
            searchContext.setSorts(new Sort[] { sort });
        }

        searchContext.setStart(start);

        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Question.class);

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

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

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<Long> folderIds, long classNameId,
        String articleId, String title, String description, String content, int status, String ddmStructureKey,
        String ddmTemplateKey, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end,
        Sort sort) {/*from   w  w w .  j  ava  2 s. com*/

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andSearch);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    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("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setGroupIds(new long[] { groupId });

    if (params != null) {
        searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions")));

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

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

    QueryConfig queryConfig = new QueryConfig();

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

    searchContext.setQueryConfig(queryConfig);

    if (sort != null) {
        searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    return searchContext;
}

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

License:Open Source License

protected SearchContext buildSearchContext(long groupId, long userId, long creatorUserId, int status, int start,
        int end) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    searchContext.setAttribute("paginationType", "none");

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }//from   www.j a  v a 2s.  co  m

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    return searchContext;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<java.lang.Long> folderIds,
        long classNameId, String ddmStructureKey, String ddmTemplateKey, String keywords,
        LinkedHashMap<String, Object> params, int start, int end, Sort sort, boolean showVersions) {

    String articleId = null;/*from ww w.java  2  s.c  o  m*/
    String title = null;
    String description = null;
    String content = null;
    boolean andOperator = false;

    if (Validator.isNotNull(keywords)) {
        articleId = keywords;
        title = keywords;
        description = keywords;
        content = keywords;
    } else {
        andOperator = true;
    }

    if (params != null) {
        params.put("keywords", keywords);
    }

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andOperator);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    attributes.put(Field.CLASS_NAME_ID, classNameId);
    attributes.put(Field.CONTENT, content);
    attributes.put(Field.DESCRIPTION, description);
    attributes.put(Field.STATUS, getStatus());
    attributes.put(Field.TITLE, title);
    attributes.put("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions"), true));

    if (params != null) {
        keywords = (String) params.remove("keywords");

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

    searchContext.setAttribute("head", !showVersions);
    searchContext.setAttribute("params", params);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setStart(start);

    QueryConfig queryConfig = new QueryConfig();

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

    searchContext.setQueryConfig(queryConfig);

    if (sort != null) {
        searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.mail.util.AccountIndexer.java

License:Open Source License

@Override
protected void doDelete(Account account) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(account.getCompanyId());
    searchContext.setEnd(QueryUtil.ALL_POS);
    searchContext.setSearchEngineId(getSearchEngineId());
    searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
    searchContext.setStart(QueryUtil.ALL_POS);

    BooleanQuery booleanQuery = new BooleanQueryImpl();

    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME);

    booleanQuery.addRequiredTerm("accountId", account.getAccountId());

    Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery);

    List<String> uids = new ArrayList<>(hits.getLength());

    for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        uids.add(document.get(Field.UID));
    }/*from   w w  w  . j  a  v  a 2 s .c om*/

    IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids,
            isCommitImmediately());
}

From source file:com.liferay.mail.util.FolderIndexer.java

License:Open Source License

@Override
protected void doDelete(Folder folder) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(folder.getCompanyId());
    searchContext.setEnd(QueryUtil.ALL_POS);
    searchContext.setSearchEngineId(getSearchEngineId());
    searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
    searchContext.setStart(QueryUtil.ALL_POS);

    BooleanQuery booleanQuery = new BooleanQueryImpl();

    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME);

    booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

    Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery);

    List<String> uids = new ArrayList<>(hits.getLength());

    for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        uids.add(document.get(Field.UID));
    }/*from w  ww. j  av a  2  s  .  co  m*/

    IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids,
            isCommitImmediately());
}

From source file:com.liferay.mail.util.MessageIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(getSearchEngineId());

    if (obj instanceof Account) {
        Account account = (Account) obj;

        searchContext.setCompanyId(account.getCompanyId());
        searchContext.setEnd(QueryUtil.ALL_POS);
        searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
        searchContext.setStart(QueryUtil.ALL_POS);

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("accountId", account.getAccountId());

        Hits hits = SearchEngineUtil.search(searchContext, booleanQuery);

        List<String> uids = new ArrayList<String>(hits.getLength());

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            uids.add(document.get(Field.UID));
        }//from   w  w w .  ja  v  a 2  s. c o m

        SearchEngineUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids,
                isCommitImmediately());
    } else if (obj instanceof Folder) {
        Folder folder = (Folder) obj;

        searchContext.setCompanyId(folder.getCompanyId());
        searchContext.setEnd(QueryUtil.ALL_POS);
        searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
        searchContext.setStart(QueryUtil.ALL_POS);

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

        Hits hits = SearchEngineUtil.search(searchContext, booleanQuery);

        List<String> uids = new ArrayList<String>(hits.getLength());

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            uids.add(document.get(Field.UID));
        }

        SearchEngineUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids,
                isCommitImmediately());
    } else if (obj instanceof Message) {
        Message message = (Message) obj;

        Document document = new DocumentImpl();

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

        SearchEngineUtil.deleteDocument(getSearchEngineId(), message.getCompanyId(), document.get(Field.UID),
                isCommitImmediately());
    }
}