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.message.boards.web.internal.display.context.DefaultMBListDisplayContext.java

License:Open Source License

@Override
public void populateResultsAndTotal(SearchContainer searchContainer) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    if (isShowSearch()) {
        long searchCategoryId = ParamUtil.getLong(_request, "searchCategoryId");

        long[] categoryIdsArray = null;

        List categoryIds = new ArrayList();

        categoryIds.add(Long.valueOf(searchCategoryId));

        MBCategoryServiceUtil.getSubcategoryIds(categoryIds, themeDisplay.getScopeGroupId(), searchCategoryId);

        categoryIdsArray = StringUtil.split(StringUtil.merge(categoryIds), 0L);

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

        SearchContext searchContext = SearchContextFactory.getInstance(_request);

        searchContext.setAttribute("paginationType", "more");
        searchContext.setCategoryIds(categoryIdsArray);
        searchContext.setEnd(searchContainer.getEnd());
        searchContext.setIncludeAttachments(true);

        String keywords = ParamUtil.getString(_request, "keywords");

        searchContext.setKeywords(keywords);

        searchContext.setStart(searchContainer.getStart());

        Hits hits = indexer.search(searchContext);

        searchContainer.setResults(SearchResultUtil.getSearchResults(hits, _request.getLocale()));

        searchContainer.setSearch(true);
        searchContainer.setTotal(hits.getLength());
    } else if (isShowRecentPosts()) {
        searchContainer.setEmptyResultsMessage("there-are-no-recent-posts");

        long groupThreadsUserId = ParamUtil.getLong(_request, "groupThreadsUserId");

        Calendar calendar = Calendar.getInstance();

        MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings
                .getInstance(themeDisplay.getSiteGroupId());

        int offset = GetterUtil.getInteger(mbGroupServiceSettings.getRecentPostsDateOffset());

        calendar.add(Calendar.DATE, -offset);

        searchContainer.setTotal(MBThreadServiceUtil.getGroupThreadsCount(themeDisplay.getScopeGroupId(),
                groupThreadsUserId, calendar.getTime(), WorkflowConstants.STATUS_APPROVED));
        searchContainer.setResults(MBThreadServiceUtil.getGroupThreads(themeDisplay.getScopeGroupId(),
                groupThreadsUserId, calendar.getTime(), WorkflowConstants.STATUS_APPROVED,
                searchContainer.getStart(), searchContainer.getEnd()));
    } else if (isShowMyPosts()) {
        long groupThreadsUserId = ParamUtil.getLong(_request, "groupThreadsUserId");

        if (themeDisplay.isSignedIn()) {
            groupThreadsUserId = themeDisplay.getUserId();
        }//from   w  w w.j  ava  2s  . c  o m

        int status = WorkflowConstants.STATUS_ANY;

        searchContainer.setTotal(MBThreadServiceUtil.getGroupThreadsCount(themeDisplay.getScopeGroupId(),
                groupThreadsUserId, status));
        searchContainer.setResults(MBThreadServiceUtil.getGroupThreads(themeDisplay.getScopeGroupId(),
                groupThreadsUserId, status, searchContainer.getStart(), searchContainer.getEnd()));
        searchContainer.setEmptyResultsMessage("you-do-not-have-any-posts");
    } else {
        int status = WorkflowConstants.STATUS_APPROVED;

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())) {

            status = WorkflowConstants.STATUS_ANY;
        }

        searchContainer.setTotal(MBCategoryLocalServiceUtil
                .getCategoriesAndThreadsCount(themeDisplay.getScopeGroupId(), _categoryId, status));
        searchContainer.setResults(MBCategoryServiceUtil.getCategoriesAndThreads(themeDisplay.getScopeGroupId(),
                _categoryId, status, searchContainer.getStart(), searchContainer.getEnd()));
    }
}

From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long companyId, long[] groupIds, long userId, String className, String keywords, int status,
        int start, int end) throws SystemException {
    try {/*w  ww  .ja va 2  s . com*/
        SearchContext searchContext = new SearchContext();

        Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);

        assetEntriesFacet.setStatic(true);

        searchContext.addFacet(assetEntriesFacet);

        Facet scopeFacet = new ScopeFacet(searchContext);

        scopeFacet.setStatic(true);

        searchContext.addFacet(scopeFacet);

        searchContext.setAttribute("paginationType", "regular");
        searchContext.setAttribute("status", status);
        searchContext.setCompanyId(companyId);
        searchContext.setEnd(end);
        searchContext.setEntryClassNames(getClassNames(companyId, className));
        searchContext.setGroupIds(groupIds);
        searchContext.setKeywords(keywords);

        QueryConfig queryConfig = new QueryConfig();

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

        searchContext.setQueryConfig(queryConfig);

        searchContext.setStart(start);
        searchContext.setUserId(userId);

        Indexer indexer = FacetedSearcher.getInstance();

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

From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long companyId, long[] groupIds, long userId, String className, String userName,
        String title, String description, String assetCategoryIds, String assetTagNames, int status,
        boolean andSearch, int start, int end) throws SystemException {
    try {//from   w w  w.jav  a 2 s .  c  o  m
        SearchContext searchContext = new SearchContext();

        Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);

        assetEntriesFacet.setStatic(true);

        searchContext.addFacet(assetEntriesFacet);

        Facet scopeFacet = new ScopeFacet(searchContext);

        scopeFacet.setStatic(true);

        searchContext.addFacet(scopeFacet);

        searchContext.setAndSearch(andSearch);
        searchContext.setAssetCategoryIds(StringUtil.split(assetCategoryIds, 0L));
        searchContext.setAssetTagNames(StringUtil.split(assetTagNames));
        searchContext.setAttribute(Field.DESCRIPTION, description);
        searchContext.setAttribute(Field.TITLE, title);
        searchContext.setAttribute(Field.USER_NAME, userName);
        searchContext.setAttribute("paginationType", "regular");
        searchContext.setAttribute("status", status);
        searchContext.setCompanyId(companyId);
        searchContext.setEnd(end);
        searchContext.setEntryClassNames(getClassNames(companyId, className));
        searchContext.setGroupIds(groupIds);

        QueryConfig queryConfig = new QueryConfig();

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

        searchContext.setQueryConfig(queryConfig);

        searchContext.setStart(start);
        searchContext.setUserId(userId);

        Indexer indexer = FacetedSearcher.getInstance();

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

From source file:com.liferay.portlet.bookmarks.service.BookmarksFolderServiceTest.java

License:Open Source License

public void testSearch() throws Exception {
    BookmarksEntry entry = addEntry();//from   w  ww  .  j a  v a 2  s . co  m

    Thread.sleep(1000);

    long companyId = entry.getCompanyId();
    long groupId = entry.getFolder().getGroupId();
    long folderId = entry.getFolderId();
    String keywords = "test";

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setFolderIds(new long[] { folderId });
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

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

    searchContext.setQueryConfig(queryConfig);

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

    Hits hits = indexer.search(searchContext);

    assertEquals(1, hits.getLength());

    List<Document> results = hits.toList();

    for (Document doc : results) {
        assertEquals(companyId, GetterUtil.getLong(doc.get(Field.COMPANY_ID)));

        assertEquals(groupId, GetterUtil.getLong(doc.get(Field.GROUP_ID)));

        assertEqualsIgnoreCase(entry.getName(), doc.get(Field.TITLE));
        assertEquals(entry.getUrl(), doc.get(Field.URL));
        assertEqualsIgnoreCase(entry.getDescription(), doc.get(Field.DESCRIPTION));

        assertEquals(folderId, GetterUtil.getLong(doc.get("folderId")));
        assertEquals(entry.getEntryId(), GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK)));
    }

    BookmarksFolderLocalServiceUtil.deleteFolder(folderId);

    Thread.sleep(1000);

    hits = indexer.search(searchContext);

    Query query = hits.getQuery();

    assertEquals(query.toString(), 0, hits.getLength());

    addEntry();
    addEntry();
    addEntry();
    addEntry();

    Thread.sleep(1000);

    searchContext.setEnd(3);
    searchContext.setFolderIds(null);
    searchContext.setStart(1);

    hits = indexer.search(searchContext);

    assertEquals(4, hits.getLength());
    assertEquals(2, hits.getDocs().length);
}

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public Hits search(long companyId, long userId, String portletId, long groupId, long[] repositoryIds,
        String keywords, int start, int end) throws SystemException {

    try {//from   ww w .  ja v a  2  s  .c  o  m
        SearchContext searchContext = new SearchContext();

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

        Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

        searchContext.setSearchEngineId(indexer.getSearchEngineId());

        searchContext.setStart(start);
        searchContext.setUserId(userId);

        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);

        contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);

        if (groupId > 0) {
            Group group = groupLocalService.getGroup(groupId);

            if (group.isLayout()) {
                contextQuery.addRequiredTerm(Field.SCOPE_GROUP_ID, groupId);

                groupId = group.getParentGroupId();
            }

            contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if ((repositoryIds != null) && (repositoryIds.length > 0)) {
            BooleanQuery repositoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

            for (long repositoryId : repositoryIds) {
                try {
                    if (userId > 0) {
                        PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

                        DLFolderPermission.check(permissionChecker, groupId, repositoryId, ActionKeys.VIEW);
                    }

                    if (repositoryId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

                        repositoryId = groupId;
                    }

                    TermQuery termQuery = TermQueryFactoryUtil.create(searchContext, "repositoryId",
                            repositoryId);

                    repositoryIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
                } catch (Exception e) {
                }
            }

            contextQuery.add(repositoryIdsQuery, BooleanClauseOccur.MUST);
        }

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

        searchQuery.addTerms(_KEYWORDS_FIELDS, keywords);

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

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

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

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 {//w w w  .j a  va  2 s  .c  o m
        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.sample.service.impl.SearchLocalServiceImpl.java

License:Open Source License

/**
 * NOTE FOR DEVELOPERS://ww w.j a  v  a2 s  .com
 *
 * Never reference this interface directly. Always use {@link com.liferay.portlet.sample.service.SearchLocalServiceUtil} to access the search local service.
 */

public List<JournalArticle> searchWC(String structureKey, String fieldName, Serializable fieldValue,
        ThemeDisplay themeDisplay) {

    List<JournalArticle> articles = new ArrayList<JournalArticle>();

    try {
        SearchContext searchContext = new SearchContext();
        int start = QueryUtil.ALL_POS;
        int end = QueryUtil.ALL_POS;

        LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();

        Map<String, Serializable> searchByFields = new LinkedHashMap<String, Serializable>();
        searchByFields.put(fieldName, fieldValue);

        params.put(SampleConstants.STRUCTURE_FIELDS, searchByFields);
        params.put(SampleConstants.STRUCTURE_KEY, structureKey);
        params.put(SampleConstants.STRUCTURE_GROUP_ID, themeDisplay.getScopeGroupId());

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

        attributes.put("params", params);

        searchContext.setAttributes(attributes);

        searchContext.setAndSearch(true);
        searchContext.setCompanyId(themeDisplay.getCompanyId());
        searchContext.setGroupIds(new long[] { PortalUtil.getSiteGroupId(themeDisplay.getScopeGroupId()) });

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

        QueryConfig queryConfig = new QueryConfig();
        queryConfig.setHighlightEnabled(false);
        queryConfig.setScoreEnabled(false);

        searchContext.setQueryConfig(queryConfig);

        searchContext.setStart(start);
        searchContext.setEnd(end);

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

        articles = getJournalArticles(indexer.search(searchContext));
    } catch (Exception e) {
        _log.error(e);
    }

    return articles;
}

From source file:com.liferay.trash.service.impl.TrashEntryLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, long userId, String keywords,
        int start, int end, Sort sort) {

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);//  ww  w. j  av  a2 s  .  c o m
    searchContext.setKeywords(keywords);
    searchContext.setGroupIds(new long[] { groupId });

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

    searchContext.setStart(start);
    searchContext.setUserId(userId);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    return searchContext;
}

From source file:com.liferay.wiki.web.internal.display.context.DefaultWikiListPagesDisplayContext.java

License:Open Source License

@Override
public void populateResultsAndTotal(SearchContainer searchContainer) throws PortalException {

    WikiPage page = (WikiPage) _request.getAttribute(WikiWebKeys.WIKI_PAGE);

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String navigation = ParamUtil.getString(_request, "navigation", "all-pages");

    String keywords = ParamUtil.getString(_request, "keywords");

    int total = 0;
    List<WikiPage> results = new ArrayList<>();

    if (Validator.isNotNull(keywords)) {
        Indexer<WikiPage> indexer = IndexerRegistryUtil.getIndexer(WikiPage.class);

        SearchContext searchContext = SearchContextFactory.getInstance(_request);

        searchContext.setAttribute("paginationType", "more");
        searchContext.setEnd(searchContainer.getEnd());
        searchContext.setIncludeAttachments(true);
        searchContext.setIncludeDiscussions(true);
        searchContext.setKeywords(keywords);
        searchContext.setNodeIds(new long[] { _wikiNode.getNodeId() });
        searchContext.setStart(searchContainer.getStart());

        Hits hits = indexer.search(searchContext);

        searchContainer.setTotal(hits.getLength());

        List<SearchResult> searchResults = SearchResultUtil.getSearchResults(hits, themeDisplay.getLocale());

        for (SearchResult searchResult : searchResults) {
            WikiPage wikiPage = WikiPageLocalServiceUtil.getPage(searchResult.getClassPK());

            results.add(wikiPage);/*from w ww .  j  av a 2s. c om*/
        }
    } else if (navigation.equals("all-pages")) {
        total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true,
                themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED);

        searchContainer.setTotal(total);

        OrderByComparator<WikiPage> obc = WikiPortletUtil
                .getPageOrderByComparator(searchContainer.getOrderByCol(), searchContainer.getOrderByType());

        results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true,
                themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED, searchContainer.getStart(),
                searchContainer.getEnd(), obc);
    } else if (navigation.equals("categorized-pages") || navigation.equals("tagged-pages")) {

        AssetEntryQuery assetEntryQuery = new AssetEntryQuery(WikiPage.class.getName(), searchContainer);

        assetEntryQuery.setEnablePermissions(true);

        total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

        searchContainer.setTotal(total);

        assetEntryQuery.setEnd(searchContainer.getEnd());
        assetEntryQuery.setStart(searchContainer.getStart());

        List<AssetEntry> assetEntries = AssetEntryServiceUtil.getEntries(assetEntryQuery);

        for (AssetEntry assetEntry : assetEntries) {
            WikiPageResource pageResource = WikiPageResourceLocalServiceUtil
                    .getPageResource(assetEntry.getClassPK());

            WikiPage assetPage = WikiPageLocalServiceUtil.getPage(pageResource.getNodeId(),
                    pageResource.getTitle());

            results.add(assetPage);
        }
    } else if (navigation.equals("draft-pages") || navigation.equals("pending-pages")) {

        long draftUserId = themeDisplay.getUserId();

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())) {

            draftUserId = 0;
        }

        int status = WorkflowConstants.STATUS_DRAFT;

        if (navigation.equals("pending-pages")) {
            status = WorkflowConstants.STATUS_PENDING;
        }

        total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), draftUserId,
                _wikiNode.getNodeId(), status);

        searchContainer.setTotal(total);

        results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), draftUserId,
                _wikiNode.getNodeId(), status, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("frontpage")) {
        WikiWebComponentProvider wikiWebComponentProvider = WikiWebComponentProvider
                .getWikiWebComponentProvider();

        WikiGroupServiceConfiguration wikiGroupServiceConfiguration = wikiWebComponentProvider
                .getWikiGroupServiceConfiguration();

        WikiPage wikiPage = WikiPageServiceUtil.getPage(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(),
                wikiGroupServiceConfiguration.frontPageName());

        searchContainer.setTotal(1);

        results.add(wikiPage);
    } else if (navigation.equals("history")) {
        total = WikiPageLocalServiceUtil.getPagesCount(page.getNodeId(), page.getTitle());

        searchContainer.setTotal(total);

        results = WikiPageLocalServiceUtil.getPages(page.getNodeId(), page.getTitle(), QueryUtil.ALL_POS,
                QueryUtil.ALL_POS, new PageVersionComparator());
    } else if (navigation.equals("incoming-links")) {
        List<WikiPage> links = WikiPageLocalServiceUtil.getIncomingLinks(page.getNodeId(), page.getTitle());

        total = links.size();

        searchContainer.setTotal(total);

        results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("orphan-pages")) {
        List<WikiPage> orphans = WikiPageServiceUtil.getOrphans(themeDisplay.getScopeGroupId(),
                _wikiNode.getNodeId());

        total = orphans.size();

        searchContainer.setTotal(total);

        results = ListUtil.subList(orphans, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("outgoing-links")) {
        List<WikiPage> links = WikiPageLocalServiceUtil.getOutgoingLinks(page.getNodeId(), page.getTitle());

        total = links.size();

        searchContainer.setTotal(total);

        results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("recent-changes")) {
        total = WikiPageServiceUtil.getRecentChangesCount(themeDisplay.getScopeGroupId(),
                _wikiNode.getNodeId());

        searchContainer.setTotal(total);

        results = WikiPageServiceUtil.getRecentChanges(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(),
                searchContainer.getStart(), searchContainer.getEnd());
    }

    searchContainer.setResults(results);
}

From source file:com.liferay.wiki.web.internal.portlet.action.AutocompletePageTitleMVCResourceCommand.java

License:Open Source License

protected JSONArray getJSONArray(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws PortalException {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    HttpServletRequest request = PortalUtil.getHttpServletRequest(resourceRequest);

    SearchContext searchContext = SearchContextFactory.getInstance(request);

    searchContext.setEnd(20);/* w  w  w. java  2 s  .  c o  m*/

    String query = ParamUtil.getString(request, "query");

    searchContext.setKeywords(StringUtil.toLowerCase(query));

    long nodeId = ParamUtil.getLong(resourceRequest, "nodeId");

    searchContext.setNodeIds(new long[] { nodeId });

    searchContext.setStart(0);

    Hits hits = _wikiPageTitleSearcher.search(searchContext);

    for (Document document : hits.getDocs()) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("title", document.get(Field.TITLE));

        jsonArray.put(jsonObject);
    }

    return jsonArray;
}