Search in sources :

Example 1 with SearchForm

use of org.codelibs.fess.app.web.base.SearchForm in project fess by codelibs.

the class SearchAction method doSearch.

protected HtmlResponse doSearch(final SearchForm form) {
    validate(form, messages -> {
    }, () -> asHtml(virtualHost(path_SearchJsp)));
    if (isLoginRequired()) {
        return redirectToLogin();
    }
    if (viewHelper.isUseSession()) {
        final HttpSession session = request.getSession(false);
        if (session != null) {
            final Object resultsPerPage = session.getAttribute(Constants.RESULTS_PER_PAGE);
            if (resultsPerPage instanceof Integer) {
                form.num = (Integer) resultsPerPage;
            }
        }
    }
    if (StringUtil.isBlank(form.q) && form.fields.isEmpty()) {
        // redirect to index page
        form.q = null;
        return redirectToRoot();
    }
    try {
        buildFormParams(form);
        form.lang = searchService.getLanguages(request, form);
        request.setAttribute(Constants.REQUEST_LANGUAGES, form.lang);
        request.setAttribute(Constants.REQUEST_QUERIES, form.q);
        final WebRenderData renderData = new WebRenderData();
        searchService.search(form, renderData, getUserBean());
        return asHtml(virtualHost(path_SearchJsp)).renderWith(data -> {
            renderData.register(data);
            if (favoriteSupport || thumbnailSupport) {
                final String queryId = renderData.getQueryId();
                final List<Map<String, Object>> documentItems = renderData.getDocumentItems();
                userInfoHelper.storeQueryId(queryId, documentItems);
                if (thumbnailSupport) {
                    thumbnailManager.storeRequest(queryId, documentItems);
                }
            }
            RenderDataUtil.register(data, "displayQuery", getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH)));
            createPagingQuery(form);
        });
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        saveError(e.getMessageCode());
        return redirectToRoot();
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        saveError(messages -> {
            messages.addErrorsResultSizeExceeded(GLOBAL);
        });
        return redirectToRoot();
    }
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) Constants(org.codelibs.fess.Constants) LoggerFactory(org.slf4j.LoggerFactory) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) Map(java.util.Map) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LaFunctions(org.lastaflute.taglib.function.LaFunctions) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) HttpSession(javax.servlet.http.HttpSession) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) SearchService(org.codelibs.fess.app.service.SearchService) SearchForm(org.codelibs.fess.app.web.base.SearchForm) List(java.util.List) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) HttpSession(javax.servlet.http.HttpSession) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) Map(java.util.Map) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Resource (javax.annotation.Resource)1 HttpSession (javax.servlet.http.HttpSession)1 StringUtil (org.codelibs.core.lang.StringUtil)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 Constants (org.codelibs.fess.Constants)1 SearchService (org.codelibs.fess.app.service.SearchService)1 FessSearchAction (org.codelibs.fess.app.web.base.FessSearchAction)1 SearchForm (org.codelibs.fess.app.web.base.SearchForm)1 SearchRenderData (org.codelibs.fess.entity.SearchRenderData)1 SearchRequestType (org.codelibs.fess.entity.SearchRequestParams.SearchRequestType)1 InvalidQueryException (org.codelibs.fess.exception.InvalidQueryException)1 ResultOffsetExceededException (org.codelibs.fess.exception.ResultOffsetExceededException)1 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)1 LaFunctions (org.lastaflute.taglib.function.LaFunctions)1 Execute (org.lastaflute.web.Execute)1