Search in sources :

Example 6 with SearchResult

use of org.apereo.portal.search.SearchResult in project uPortal by Jasig.

the class SearchPortletController method addSearchResults.

/**
 * @param portletSearchResults Results from a portlet
 * @param results Results collating object
 * @param httpServletRequest current request
 * @param portletWindowId Id of the portlet window that provided the results
 */
private void addSearchResults(SearchResults portletSearchResults, PortalSearchResults results, final HttpServletRequest httpServletRequest, final IPortletWindowId portletWindowId) {
    for (SearchResult result : portletSearchResults.getSearchResult()) {
        final String resultUrl = this.getResultUrl(httpServletRequest, result, portletWindowId);
        this.logger.debug("Created {} with from {}", resultUrl, result.getTitle());
        modifySearchResultLinkTitle(result, httpServletRequest, portletWindowId);
        results.addPortletSearchResults(resultUrl, result);
    }
}
Also used : SearchResult(org.apereo.portal.search.SearchResult)

Example 7 with SearchResult

use of org.apereo.portal.search.SearchResult in project uPortal by Jasig.

the class SearchPortletController method showJSONSearchResults.

/**
 * Display AJAX autocomplete search results for the last query
 */
@ResourceMapping(value = "retrieveSearchJSONResults")
public ModelAndView showJSONSearchResults(PortletRequest request) {
    PortletPreferences prefs = request.getPreferences();
    int maxTextLength = Integer.parseInt(prefs.getValue(AUTOCOMPLETE_MAX_TEXT_LENGTH_PREF_NAME, "180"));
    final Map<String, Object> model = new HashMap<>();
    List<AutocompleteResultsModel> results = new ArrayList<>();
    final PortletSession session = request.getPortletSession();
    String queryId = (String) session.getAttribute(SEARCH_LAST_QUERY_ID);
    if (queryId != null) {
        final PortalSearchResults portalSearchResults = this.getPortalSearchResults(request, queryId);
        if (portalSearchResults != null) {
            final ConcurrentMap<String, List<Tuple<SearchResult, String>>> resultsMap = portalSearchResults.getResults();
            results = collateResultsForAutoCompleteResponse(resultsMap, maxTextLength);
        }
    }
    model.put("results", results);
    model.put("count", results.size());
    return new ModelAndView("json", model);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.portlet.ModelAndView) SearchResult(org.apereo.portal.search.SearchResult) PortletSession(javax.portlet.PortletSession) PortletPreferences(javax.portlet.PortletPreferences) List(java.util.List) ArrayList(java.util.ArrayList) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Example 8 with SearchResult

use of org.apereo.portal.search.SearchResult in project uPortal by Jasig.

the class PortletRegistrySearchService method getSearchResults.

@Override
public SearchResults getSearchResults(PortletRequest request, SearchRequest query) {
    final String queryString = query.getSearchTerms().toLowerCase();
    final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final SearchResults results = new SearchResults();
    for (IPortletDefinition portlet : portlets) {
        if (portletRegistryUtil.matches(queryString, portlet)) {
            final SearchResult result = new SearchResult();
            result.setTitle(portlet.getTitle());
            result.setSummary(portlet.getDescription());
            result.getType().add(searchResultType);
            String url = portletRegistryUtil.buildPortletUrl(httpServletRequest, portlet);
            if (url != null) {
                result.setExternalUrl(url);
                results.getSearchResult().add(result);
            }
        }
    }
    return results;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 9 with SearchResult

use of org.apereo.portal.search.SearchResult in project uPortal by Jasig.

the class MarketplaceSearchService method getSearchResults.

/**
 * Returns a list of search results that pertain to the marketplace query is the query to search
 * will search name, title, description, fname, and captions
 */
@Override
public SearchResults getSearchResults(PortletRequest request, SearchRequest query) {
    final String queryString = query.getSearchTerms().toLowerCase();
    final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final SearchResults results = new SearchResults();
    for (IPortletDefinition portlet : portlets) {
        if (this.matches(queryString, new MarketplacePortletDefinition(portlet, this.marketplaceService, this.portletCategoryRegistry))) {
            final SearchResult result = new SearchResult();
            result.setTitle(portlet.getTitle());
            result.setSummary(portlet.getDescription());
            result.getType().add("marketplace");
            final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(httpServletRequest, portlet.getFName());
            // If user does not have browse permission, exclude the portlet.
            if (portletWindow != null && authorizationService.canPrincipalBrowse(authorizationService.newPrincipal(request.getRemoteUser(), EntityEnum.PERSON.getClazz()), portlet)) {
                final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletFName(httpServletRequest, portlet.getFName(), UrlType.RENDER);
                final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
                portletUrlBuilder.setWindowState(PortletUtils.getWindowState("maximized"));
                result.setExternalUrl(portalUrlBuilder.getUrlString());
                PortletUrl url = new PortletUrl();
                url.setType(PortletUrlType.RENDER);
                url.setPortletMode("VIEW");
                url.setWindowState("maximized");
                PortletUrlParameter actionParam = new PortletUrlParameter();
                actionParam.setName("action");
                actionParam.getValue().add("view");
                url.getParam().add(actionParam);
                PortletUrlParameter fNameParam = new PortletUrlParameter();
                fNameParam.setName("fName");
                fNameParam.getValue().add(portlet.getFName());
                url.getParam().add(fNameParam);
                result.setPortletUrl(url);
                // Add the result to list to return
                results.getSearchResult().add(result);
            }
        }
    }
    return results;
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrl(org.apereo.portal.search.PortletUrl) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

SearchResult (org.apereo.portal.search.SearchResult)9 SearchResults (org.apereo.portal.search.SearchResults)6 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Event (javax.portlet.Event)2 PortletSession (javax.portlet.PortletSession)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 PortletUrl (org.apereo.portal.search.PortletUrl)2 PortletUrlParameter (org.apereo.portal.search.PortletUrlParameter)2 SearchRequest (org.apereo.portal.search.SearchRequest)2 EventMapping (org.springframework.web.portlet.bind.annotation.EventMapping)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1