Example usage for com.liferay.portal.kernel.search QueryConfig setLocale

List of usage examples for com.liferay.portal.kernel.search QueryConfig setLocale

Introduction

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

Prototype

public void setLocale(Locale locale) 

Source Link

Usage

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  2 s.  co 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";
}