Search in sources :

Example 1 with ResultOffsetExceededException

use of org.codelibs.fess.exception.ResultOffsetExceededException in project fess by codelibs.

the class ApiAdminSearchlistAction method docs.

// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/searchlist/docs
// POST /api/admin/searchlist/docs
@Execute
public JsonResponse<ApiResult> docs(final SearchBody body) {
    validateApi(body, messages -> {
    });
    if (StringUtil.isBlank(body.q)) {
        // query matches on all documents.
        body.q = Constants.MATCHES_ALL_QUERY;
    }
    final SearchRenderData renderData = new SearchRenderData();
    body.initialize();
    try {
        searchHelper.search(body, renderData, getUserBean());
        return asJson(new ApiDocsResponse().renderData(renderData).status(Status.OK).result());
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throwValidationErrorApi(e.getMessageCode());
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throwValidationErrorApi(messages -> messages.addErrorsResultSizeExceeded(GLOBAL));
    }
    throwValidationErrorApi(messages -> messages.addErrorsInvalidQueryUnknown(GLOBAL));
    // ignore
    return null;
}
Also used : Constants(org.codelibs.fess.Constants) AdminSearchlistAction.getDoc(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.getDoc) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) ApiDeleteResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDeleteResponse) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) AdminSearchlistAction.validateFields(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.validateFields) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Status(org.codelibs.fess.app.web.api.ApiResult.Status) CrudMode(org.codelibs.fess.app.web.CrudMode) Map(java.util.Map) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) SearchHelper(org.codelibs.fess.helper.SearchHelper) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilders(org.opensearch.index.query.QueryBuilders) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) ApiDocResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocResponse) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) JsonResponse(org.lastaflute.web.response.JsonResponse) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Logger(org.apache.logging.log4j.Logger) QueryBuilder(org.opensearch.index.query.QueryBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ApiDocsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocsResponse) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) LogManager(org.apache.logging.log4j.LogManager) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) ApiDocsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocsResponse) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Execute(org.lastaflute.web.Execute)

Example 2 with ResultOffsetExceededException

use of org.codelibs.fess.exception.ResultOffsetExceededException 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() && !form.hasConditionQuery()) {
        // redirect to index page
        form.q = null;
        return redirectToRoot();
    }
    try {
        buildFormParams(form);
        form.lang = searchHelper.getLanguages(request, form);
        final WebRenderData renderData = new WebRenderData();
        searchHelper.search(form, renderData, getUserBean());
        return asHtml(virtualHost(path_SearchJsp)).renderWith(data -> {
            if (form.hasConditionQuery()) {
                form.q = renderData.getSearchQuery();
            }
            renderData.register(data);
            RenderDataUtil.register(data, "displayQuery", getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH, request.getLocale() == null ? Locale.ROOT : request.getLocale())));
            createPagingQuery(form);
            final String[] relatedContents = relatedContentHelper.getRelatedContents(form.getQuery());
            RenderDataUtil.register(data, "relatedContents", relatedContents);
            final String[] relatedQueries = relatedQueryHelper.getRelatedQueries(form.getQuery());
            if (relatedQueries.length > 0) {
                RenderDataUtil.register(data, "relatedQueries", relatedQueries);
            }
        });
    } 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) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) RelatedQueryHelper(org.codelibs.fess.helper.RelatedQueryHelper) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) Locale(java.util.Locale) 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) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) RelatedContentHelper(org.codelibs.fess.helper.RelatedContentHelper) SearchForm(org.codelibs.fess.app.web.base.SearchForm) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) HttpSession(javax.servlet.http.HttpSession) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException)

Aggregations

Map (java.util.Map)2 Resource (javax.annotation.Resource)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 StringUtil (org.codelibs.core.lang.StringUtil)2 Constants (org.codelibs.fess.Constants)2 SearchRenderData (org.codelibs.fess.entity.SearchRenderData)2 InvalidQueryException (org.codelibs.fess.exception.InvalidQueryException)2 ResultOffsetExceededException (org.codelibs.fess.exception.ResultOffsetExceededException)2 Execute (org.lastaflute.web.Execute)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 HttpSession (javax.servlet.http.HttpSession)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 CrudMode (org.codelibs.fess.app.web.CrudMode)1 AdminSearchlistAction.getDoc (org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.getDoc)1