Search in sources :

Example 1 with SearchRequest

use of org.jasig.portal.search.SearchRequest in project SimpleContentPortlet by Jasig.

the class SearchContentController method searchContent.

@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING)
public void searchContent(EventRequest request, EventResponse response) {
    final Event event = request.getEvent();
    final SearchRequest searchQuery = (SearchRequest) event.getValue();
    final String textContent = getTextContent(request);
    final String[] searchTerms = searchQuery.getSearchTerms().split(" ");
    for (final String term : searchTerms) {
        if (StringUtils.containsIgnoreCase(textContent, term)) {
            // matched, create results object and copy over the query id
            final SearchResults searchResults = new SearchResults();
            searchResults.setQueryId(searchQuery.getQueryId());
            searchResults.setWindowId(request.getWindowID());
            // Build the result object for the match
            final SearchResult searchResult = new SearchResult();
            String title = request.getPreferences().getValue("searchResultsTitle", "${portlet.title}");
            searchResult.setTitle(title);
            searchResult.setSummary(getContentSummary(textContent));
            searchResult.getType().add("Portlet Content");
            // Add the result to the results and send the event
            searchResults.getSearchResult().add(searchResult);
            response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, searchResults);
            // Stop processing
            return;
        }
    }
}
Also used : SearchRequest(org.jasig.portal.search.SearchRequest) Event(javax.portlet.Event) SearchResult(org.jasig.portal.search.SearchResult) SearchResults(org.jasig.portal.search.SearchResults) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Aggregations

Event (javax.portlet.Event)1 SearchRequest (org.jasig.portal.search.SearchRequest)1 SearchResult (org.jasig.portal.search.SearchResult)1 SearchResults (org.jasig.portal.search.SearchResults)1 EventMapping (org.springframework.web.portlet.bind.annotation.EventMapping)1