Search in sources :

Example 1 with QueryRequestContext

use of com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext in project tis by qlangtech.

the class IndexQueryAction method doQuery.

@Func(value = PermissionConstant.PERMISSION_INDEX_QUERY, sideEffect = false)
public void doQuery(Context context) throws Exception {
    List<String> sfields = Lists.newArrayList(this.getRequest().getParameterValues("sfields"));
    final String query = StringUtils.defaultIfEmpty((this.getString("q")).replaceAll("\r|\n", StringUtils.EMPTY), "*:*");
    Integer shownum = null;
    shownum = this.getInt("shownum", 3);
    QueryRequestWrapper request = new QueryRequestWrapper(this.getRequest(), context);
    QueryRequestContext requestContext = new QueryRequestContext(request);
    final String sort = getString("sort");
    final String[] fqs = this.getStringArray("fq");
    final QueryResutStrategy queryResutStrategy = QueryIndexServlet.createQueryResutStrategy(this.getAppDomain(), request, getResponse(), getDaoContext());
    final List<ServerJoinGroup> serverlist = queryResutStrategy.queryProcess();
    QueryIndexServlet.execuetQuery(this, this.getAppDomain(), requestContext, this.getDaoContext(), queryResutStrategy, serverlist, query, sort, fqs, shownum, sfields);
}
Also used : QueryRequestContext(com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext) QueryRequestWrapper(com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestWrapper) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 2 with QueryRequestContext

use of com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext in project tis by qlangtech.

the class QueryIndexServlet method doQuery.

public void doQuery(final HttpServletRequest request, final HttpServletResponse resp, AppDomainInfo domain, List<String> sfields) throws ServletException, IOException {
    request.setAttribute("selectedFields", sfields);
    request.setCharacterEncoding(TisUTF8.getName());
    final String query = StringUtils.defaultIfEmpty((request.getParameter("q")).replaceAll("\r|\n", StringUtils.EMPTY), "*:*");
    Integer shownum = null;
    try {
        shownum = Integer.parseInt(request.getParameter("shownum"));
    } catch (Throwable e2) {
    }
    QueryRequestContext requestContext = new QueryRequestContext(request);
    final String sort = request.getParameter("sort");
    final String[] fqs = request.getParameterValues("fq");
    if (domain instanceof com.qlangtech.tis.pubhook.common.Nullable) {
        throw new IllegalStateException("domain can not be nullable ");
    }
    final QueryResutStrategy queryResutStrategy = createQueryResutStrategy(domain, request, resp, this.getContext());
    final List<ServerJoinGroup> serverlist = queryResutStrategy.queryProcess();
    execuetQuery(null, domain, requestContext, this.getContext(), queryResutStrategy, serverlist, query, sort, fqs, shownum, sfields);
// }
}
Also used : QueryRequestContext(com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext)

Example 3 with QueryRequestContext

use of com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext in project tis by qlangtech.

the class QueryIndexServlet method createQueryResutStrategy.

public static // , boolean queryResultAware
QueryResutStrategy createQueryResutStrategy(// , boolean queryResultAware
AppDomainInfo domain, // , boolean queryResultAware
final HttpServletRequest request, final HttpServletResponse resp, RunContext runContext) {
    final SolrQueryModuleCreatorAdapter creatorAdapter = new SolrQueryModuleCreatorAdapter() {

        @Override
        public boolean schemaAware() {
            return false;
        }

        @Override
        public SolrParams build(IParamGetter params, final String querystr, final String sort, final String[] fqs, final Integer shownumf, final List<String> showFields) {
            SolrQuery query = new SolrQuery();
            // 增加排序字段
            if (StringUtils.isNotBlank(sort)) {
                query.add(CommonParams.SORT, sort);
            }
            // query.add(CommonParams.Q, querystr);
            query.setQuery(querystr);
            if (fqs != null) {
                for (String fq : fqs) {
                    query.add(CommonParams.FQ, fq);
                }
            }
            boolean facet = params.getBoolean(FacetParams.FACET);
            if (facet) {
                String facetField = params.getString(FacetParams.FACET_FIELD);
                if (StringUtils.isNotEmpty(facetField)) {
                    query.addFacetField(facetField);
                }
                String facetQuery = params.getString(FacetParams.FACET_QUERY);
                if (StringUtils.isNotEmpty(facetQuery)) {
                    query.addFacetQuery(facetQuery);
                }
                String facetPrefix = params.getString(FacetParams.FACET_PREFIX);
                if (StringUtils.isNotEmpty(facetPrefix)) {
                    query.setFacetPrefix(facetPrefix);
                }
            }
            query.add(CommonParams.START, params.getString(CommonParams.START, "0"));
            // 默认显示前三行
            query.setRows(shownumf);
            // query.add(CommonParams.ROWS, String.valueOf(shownumf));
            query.add(CommonParams.VERSION, "2.2");
            query.add(CommonParams.WT, "xml");
            boolean distrib = params.getBoolean(CommonParams.DISTRIB);
            query.add(CommonParams.DISTRIB, String.valueOf(distrib));
            if (showFields.isEmpty()) {
                if (distrib) {
                    query.setFields("*", FIELD_SHARD);
                }
            } else {
                for (String field : showFields) {
                    query.addField(field);
                }
                if (distrib) {
                    query.addField(FIELD_SHARD);
                }
            }
            query.setShowDebugInfo(params.getBoolean(CommonParams.DEBUG));
            return query;
        }

        @Override
        public ParseResult processSchema(InputStream schemaStream) {
            try {
                // SolrFieldsParser schemaParser = new SolrFieldsParser();
                ParseResult parseResult = SolrFieldsParser.parse(() -> IOUtils.toByteArray(schemaStream)).getSchemaParseResult();
                return parseResult;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String[] getParameterValues(String keyname) {
            return request.getParameterValues(keyname);
        }

        @Override
        public void handleError(String url, ServerJoinGroup server, long allcount, Exception e) {
            synchronized (resp) {
                try {
                    String serverInfo = "[" + server.getGroupIndex() + "]" + server.getIp();
                    flushResult(resp, request, Arrays.asList(convert2Html("url:" + url + "<br/>" + getErrorContent(e), serverInfo)), allcount);
                } catch (IOException e1) {
                }
            }
        }

        @Override
        public void processResult(QueryRequestContext qrequest, QueryResponse result, ServerJoinGroup server) throws Exception {
            flushResult(resp, qrequest.request, convert2Html(qrequest, result, server, false), qrequest.resultCount.get());
        }

        @Override
        public void processResult(QueryRequestContext qrequest, List<Row> rows) throws Exception {
            flushResult(resp, qrequest.request, rows, qrequest.resultCount.get());
        }

        @Override
        public void setQuerySelectServerCandiate(Map<String, List<ServerJoinGroup>> servers) {
            request.setAttribute("querySelectServerCandiate", servers);
        }
    };
    final QueryResutStrategy queryResutStrategy = SolrCloudQueryResutStrategy.create(domain, creatorAdapter, runContext);
    return queryResutStrategy;
}
Also used : ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) InputStream(java.io.InputStream) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) QueryRequestContext(com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IParamGetter(com.qlangtech.tis.runtime.module.action.IParamGetter) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Aggregations

QueryRequestContext (com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestContext)3 Func (com.qlangtech.tis.manage.spring.aop.Func)1 IParamGetter (com.qlangtech.tis.runtime.module.action.IParamGetter)1 QueryRequestWrapper (com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestWrapper)1 ParseResult (com.qlangtech.tis.solrdao.impl.ParseResult)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ServletException (javax.servlet.ServletException)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1