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

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

Introduction

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

Prototype

SearchContext

Source Link

Usage

From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, String keywords) {

    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    searchContext.setEntryClassNames(CLASS_NAMES);

    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

    Hits hits = null;//from  ww w . jav a2 s  .c  o m

    try {
        searchQuery.addTerm(Field.TITLE, keywords);
        hits = SearchEngineUtil.search(searchContext, searchQuery);
    } catch (SearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return hits;

}

From source file:com.liferay.asset.search.test.AssetSearcherStagingTest.java

License:Open Source License

protected SearchContext getSearchContext() {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(_group.getCompanyId());

    return searchContext;
}

From source file:com.liferay.asset.search.test.AssetSearcherTest.java

License:Open Source License

protected SearchContext getSearchContext() {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(_group.getCompanyId());
    searchContext.setGroupIds(new long[] { _group.getGroupId() });

    return searchContext;
}

From source file:com.liferay.asset.search.test.AssetUtilSearchSortTest.java

License:Open Source License

protected SearchContext createSearchContext() {
    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.GROUP_ID, _group.getGroupId());
    searchContext.setCompanyId(_group.getCompanyId());
    searchContext.setGroupIds(new long[] { _group.getGroupId() });
    searchContext.setKeywords(StringPool.BLANK);
    searchContext.setUserId(_group.getCreatorUserId());

    return searchContext;
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long groupId, long userId, long creatorUserId, int status, int start, int end)
        throws PortalException {

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

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

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

    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);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    return indexer.search(searchContext);
}

From source file:com.liferay.bookmarks.util.test.BookmarksTestUtil.java

License:Open Source License

public static SearchContext getSearchContext(long companyId, long groupId, long folderId, String keywords,
        boolean highlight, boolean score) {

    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(highlight);
    queryConfig.setScoreEnabled(score);//from   w ww  .  j a v a  2s .  c  om

    searchContext.setQueryConfig(queryConfig);

    return searchContext;
}

From source file:com.liferay.calendar.search.test.CalendarSearchFixture.java

License:Open Source License

public SearchContext getSearchContext(String keywords, Locale locale) {
    SearchContext searchContext = new SearchContext();

    try {//from   ww  w . j  a  v  a2 s. c  o  m
        searchContext.setCompanyId(TestPropsValues.getCompanyId());
        searchContext.setUserId(getUserId());
    } catch (PortalException pe) {
        throw new RuntimeException(pe);
    }

    searchContext.setGroupIds(new long[] { _group.getGroupId() });
    searchContext.setKeywords(keywords);
    searchContext.setLocale(Objects.requireNonNull(locale));

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setSelectedFieldNames(StringPool.STAR);

    return searchContext;
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected Hits search(ThemeDisplay themeDisplay, String keywords) throws Exception {

    SearchContext searchContext = new SearchContext();

    keywords = StringUtil.toLowerCase(keywords);

    searchContext.setAttribute(Field.NAME, keywords);
    searchContext.setAttribute("resourceName", keywords);

    searchContext.setCompanyId(themeDisplay.getCompanyId());
    searchContext.setEnd(SearchContainer.DEFAULT_DELTA);
    searchContext.setGroupIds(new long[0]);

    Group group = themeDisplay.getScopeGroup();

    searchContext.setIncludeStagingGroups(group.isStagingGroup());

    searchContext.setStart(0);//w  w w  . j av a2 s . c om
    searchContext.setUserId(themeDisplay.getUserId());

    Indexer<?> indexer = CalendarSearcher.getInstance();

    return indexer.search(searchContext);
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.SearchMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    Indexer indexer = _indexerRegistry.nullSafeGetIndexer(ConfigurationModel.class);

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(false);//from www. ja v a  2s .  c  o m
    searchContext.setCompanyId(CompanyConstants.SYSTEM);
    searchContext.setLocale(renderRequest.getLocale());

    String keywords = renderRequest.getParameter("keywords");

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

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(true);
    queryConfig.setLocale(renderRequest.getLocale());
    queryConfig.setScoreEnabled(true);

    try {
        Hits hits = indexer.search(searchContext);

        Document[] documents = hits.getDocs();

        Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
                .getConfigurationModels();

        List<ConfigurationModel> searchResults = new ArrayList<>(documents.length);

        for (Document document : documents) {
            String configurationModelId = document.get(FieldNames.CONFIGURATION_MODEL_ID);

            ConfigurationModel configurationModel = configurationModels.get(configurationModelId);

            if (configurationModel == null) {
                String configurationModelFactoryId = document.get(FieldNames.CONFIGURATION_MODEL_FACTORY_PID);

                configurationModel = configurationModels.get(configurationModelFactoryId);
            }

            if (configurationModel != null) {
                searchResults.add(configurationModel);
            }
        }

        ConfigurationModelIterator configurationModelIterator = new ConfigurationModelIterator(searchResults);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL_ITERATOR,
                configurationModelIterator);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.RESOURCE_BUNDLE_LOADER_PROVIDER,
                _resourceBundleLoaderProvider);
    } catch (Exception e) {
        throw new PortletException(e);
    }

    return "/view.jsp";
}

From source file:com.liferay.content.targeting.service.impl.CampaignLocalServiceImpl.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);/*ww  w  .  ja  v  a  2s . c o  m*/
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);
    searchContext.setStart(start);

    return searchContext;
}