List of usage examples for org.apache.solr.common.params CommonParams FQ
String FQ
To view the source code for org.apache.solr.common.params CommonParams FQ.
Click Source Link
From source file:de.qaware.chronix.solr.query.ChronixQueryHandler.java
License:Apache License
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { ModifiableSolrParams modifiableSolrParams = new ModifiableSolrParams(req.getParams()); String originQuery = modifiableSolrParams.get(CommonParams.Q); long[] startAndEnd = dateRangeParser.getNumericQueryTerms(originQuery); long queryStart = or(startAndEnd[0], -1, 0); long queryEnd = or(startAndEnd[1], -1, Long.MAX_VALUE); modifiableSolrParams.set(ChronixQueryParams.QUERY_START_LONG, String.valueOf(queryStart)); modifiableSolrParams.set(ChronixQueryParams.QUERY_END_LONG, String.valueOf(queryEnd)); String query = dateRangeParser.replaceRangeQueryTerms(originQuery); modifiableSolrParams.set(CommonParams.Q, query); //Set the min required fields if the user define a sub set of fields modifiableSolrParams.set(CommonParams.FL, minRequiredFields(modifiableSolrParams.get(CommonParams.FL))); //Set the updated query req.setParams(modifiableSolrParams); //check the filter queries String[] filterQueries = modifiableSolrParams.getParams(CommonParams.FQ); //if we have an isAggregation if (contains(filterQueries, ChronixQueryParams.AGGREGATION_PARAM) || contains(filterQueries, ChronixQueryParams.ANALYSIS_PARAM)) { analysisHandler.handleRequestBody(req, rsp); } else {/*from w ww . j a v a 2 s . co m*/ //let the default search handler do its work searchHandler.handleRequestBody(req, rsp); } //add the converted start and end to the response rsp.getResponseHeader().add(ChronixQueryParams.QUERY_START_LONG, queryStart); rsp.getResponseHeader().add(ChronixQueryParams.QUERY_END_LONG, queryEnd); }
From source file:net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector.java
License:Open Source License
public SolrQueryResponse query(SolrQueryRequest req) throws SolrException { final long startTime = System.currentTimeMillis(); // during the solr query we set the thread name to the query string to get more debugging info in thread dumps String q = req.getParams().get(CommonParams.Q); String fq = req.getParams().get(CommonParams.FQ); String sort = req.getParams().get(CommonParams.SORT); String threadname = Thread.currentThread().getName(); if (q != null) Thread.currentThread().setName("solr query: q = " + q + (fq == null ? "" : ", fq = " + fq) + (sort == null ? "" : ", sort = " + sort)); // for debugging in Threaddump SolrQueryResponse rsp = new SolrQueryResponse(); NamedList<Object> responseHeader = new SimpleOrderedMap<Object>(); responseHeader.add("params", req.getOriginalParams().toNamedList()); rsp.add("responseHeader", responseHeader); //SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); // send request to solr and create a result this.requestHandler.handleRequest(req, rsp); // get statistics and add a header with that Exception exception = rsp.getException(); int status = exception == null ? 0 : exception instanceof SolrException ? ((SolrException) exception).code() : 500; responseHeader.add("status", status); responseHeader.add("QTime", (int) (System.currentTimeMillis() - startTime)); if (q != null) Thread.currentThread().setName(threadname); // return result return rsp;/* ww w . ja v a 2s . c o m*/ }
From source file:net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector.java
License:Open Source License
/** * the usage of getResponseByParams is disencouraged for the embedded Solr connector. Please use request(SolrParams) instead. * Reason: Solr makes a very complex folding/unfolding including data compression for SolrQueryResponses. *//*ww w .j ava2s . co m*/ @Override public QueryResponse getResponseByParams(ModifiableSolrParams params) throws IOException { if (this.server == null) throw new IOException("server disconnected"); // during the solr query we set the thread name to the query string to get more debugging info in thread dumps String q = params.get(CommonParams.Q); String fl = params.get(CommonParams.FL); String[] fq = params.getParams(CommonParams.FQ); String threadname = Thread.currentThread().getName(); if (q != null) { StringBuilder fqa = new StringBuilder(); if (fq != null) for (String f : fq) fqa.append("fq=").append(f).append(' '); Thread.currentThread().setName("solr query: q = " + q + (fq == null ? "" : ", " + fqa.toString()) + (fl == null ? "" : ", fl=" + fl)); //System.out.println("solr query: q = " + q + (fq == null ? "" : ", " + fqa.toString()) + (fl == null ? "" : ", fl=" + fl)); } QueryResponse rsp; try { rsp = this.server.query(params); if (q != null) Thread.currentThread().setName(threadname); if (rsp != null) if (log.isFine()) log.fine(rsp.getResults().getNumFound() + " results for q=" + q); return rsp; } catch (final SolrServerException e) { throw new IOException(e); } catch (final Throwable e) { throw new IOException("Error executing query", e); } }
From source file:net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector.java
License:Open Source License
/** * get the solr document list from a query response * This differs from getResponseByParams in such a way that it does only create the fields of the response but * never search snippets and there are also no facets generated. * @param params//from ww w .ja v a 2 s .c om * @return * @throws IOException * @throws SolrException */ @Override public SolrDocumentList getDocumentListByParams(ModifiableSolrParams params) throws IOException, SolrException { SolrQueryRequest req = this.request(params); SolrQueryResponse response = null; String q = params.get(CommonParams.Q); String fq = params.get(CommonParams.FQ); String sort = params.get(CommonParams.SORT); String threadname = Thread.currentThread().getName(); try { if (q != null) Thread.currentThread().setName("solr query: q = " + q + (fq == null ? "" : ", fq = " + fq) + (sort == null ? "" : ", sort = " + sort)); // for debugging in Threaddump response = this.query(req); if (q != null) Thread.currentThread().setName(threadname); if (response == null) throw new IOException("response == null"); return SolrQueryResponse2SolrDocumentList(req, response); } finally { req.close(); SolrRequestInfo.clearRequestInfo(); } }
From source file:net.yacy.cora.federate.solr.connector.RemoteSolrConnector.java
License:Open Source License
@Override public QueryResponse getResponseByParams(ModifiableSolrParams params) throws IOException { // during the solr query we set the thread name to the query string to get more debugging info in thread dumps String q = params.get(CommonParams.Q); String fq = params.get(CommonParams.FQ); String threadname = Thread.currentThread().getName(); if (q != null) Thread.currentThread().setName("solr query: q = " + q + (fq == null ? "" : ", fq = " + fq)); QueryRequest request = new QueryRequest(params); ResponseParser responseParser = useBinaryResponseWriter ? new BinaryResponseParser() : new XMLResponseParser(); request.setResponseParser(responseParser); long t = System.currentTimeMillis(); NamedList<Object> result = null; try {//from w ww. j a v a 2 s . c o m result = this.server.request(request); } catch (final Throwable e) { //ConcurrentLog.logException(e); throw new IOException(e.getMessage()); /* Log.logException(e); server = instance.getServer(this.corename); super.init(server); try { result = server.request(request); } catch (final Throwable e1) { throw new IOException(e1.getMessage()); } */ } QueryResponse response = new QueryResponse(result, this.server); response.setElapsedTime(System.currentTimeMillis() - t); if (q != null) Thread.currentThread().setName(threadname); return response; }
From source file:net.yacy.cora.federate.solr.connector.SolrServerConnector.java
License:Open Source License
/** * get the solr document list from a query response * This differs from getResponseByParams in such a way that it does only create the fields of the response but * never search snippets and there are also no facets generated. * @param params//from w w w . j ava2s .c o m * @return * @throws IOException * @throws SolrException */ @Override public SolrDocumentList getDocumentListByParams(ModifiableSolrParams params) throws IOException { if (this.server == null) throw new IOException("server disconnected"); // during the solr query we set the thread name to the query string to get more debugging info in thread dumps String q = params.get(CommonParams.Q); String fq = params.get(CommonParams.FQ); String sort = params.get(CommonParams.SORT); String fl = params.get(CommonParams.FL); String threadname = Thread.currentThread().getName(); QueryResponse rsp; int retry = 0; Throwable error = null; while (retry++ < 10) { try { if (q != null) Thread.currentThread().setName("solr query: q = " + q + (fq == null ? "" : ", fq = " + fq) + (sort == null ? "" : ", sort = " + sort) + "; retry = " + retry + "; fl = " + fl); // for debugging in Threaddump rsp = this.server.query(params); if (q != null) Thread.currentThread().setName(threadname); if (rsp != null) if (log.isFine()) log.fine(rsp.getResults().getNumFound() + " results for q=" + q); return rsp.getResults(); } catch (final SolrServerException e) { error = e; } catch (final Throwable e) { error = e; clearCaches(); // prevent further OOM if this was caused by OOM } ConcurrentLog.severe("SolrServerConnector", "Failed to query remote Solr: " + error.getMessage() + ", query:" + q + (fq == null ? "" : ", fq = " + fq)); try { Thread.sleep(1000); } catch (InterruptedException e) { } } throw new IOException("Error executing query", error); }
From source file:net.yacy.http.servlets.GSAsearchServlet.java
License:Open Source License
/** * from here copy of htroot/gsa/gsasearchresult.java * with modification to use HttpServletRequest instead of (yacy) RequestHeader *///from w w w . j a v a 2 s. c o m public static void respond(final HttpServletRequest header, final Switchboard sb, final OutputStream out) { // remember the peer contact for peer statistics String clientip = header.getHeader(HeaderFramework.CONNECTION_PROP_CLIENTIP); if (clientip == null) clientip = "<unknown>"; // read an artificial header addendum String userAgent = header.getHeader(HeaderFramework.USER_AGENT); if (userAgent == null) userAgent = "<unknown>"; sb.peers.peerActions.setUserAgent(clientip, userAgent); // --- handled by Servlet securityHandler // check if user is allowed to search (can be switched in /ConfigPortal.html) boolean authenticated = header.isUserInRole(UserDB.AccessRight.ADMIN_RIGHT.toString()); //sb.adminAuthenticated(header) >= 2; // final boolean searchAllowed = authenticated || sb.getConfigBool(SwitchboardConstants.PUBLIC_SEARCHPAGE, true); // if (!searchAllowed) return null; // create post serverObjects post = new serverObjects(); post.put(CommonParams.Q, ""); post.put("num", "0"); // convert servletrequest parameter to old style serverObjects map Map<String, String[]> map = header.getParameterMap(); Iterator<Map.Entry<String, String[]>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String[]> param = it.next(); post.put(param.getKey(), param.getValue()); // hint: post.put uses String[] for String value anyways } ConcurrentLog.info("GSA Query", post.toString()); sb.intermissionAllThreads(3000); // tell all threads to do nothing for a specific time // rename post fields according to result style //post.put(CommonParams.Q, post.remove("q")); // same as solr //post.put(CommonParams.START, post.remove("start")); // same as solr //post.put(, post.remove("client"));//required, example: myfrontend //post.put(, post.remove("output"));//required, example: xml,xml_no_dtd String originalQuery = post.get(CommonParams.Q, ""); post.put("originalQuery", originalQuery); // get a solr query string QueryGoal qg = new QueryGoal(originalQuery); List<String> solrFQ = qg.collectionTextFilterQuery(false); StringBuilder solrQ = qg.collectionTextQuery(); post.put("defType", "edismax"); for (String fq : solrFQ) post.add(CommonParams.FQ, fq); post.put(CommonParams.Q, solrQ.toString()); post.put(CommonParams.ROWS, post.remove("num")); post.put(CommonParams.ROWS, Math.min(post.getInt(CommonParams.ROWS, 10), (authenticated) ? 100000000 : 100)); // set ranking final Ranking ranking = sb.index.fulltext().getDefaultConfiguration().getRanking(0); final String qf = ranking.getQueryFields(); if (!qf.isEmpty()) post.put(DisMaxParams.QF, qf); if (post.containsKey(CommonParams.SORT)) { // if a gsa-style sort attribute is given, use this to set the solr sort attribute GSAResponseWriter.Sort sort = new GSAResponseWriter.Sort(post.get(CommonParams.SORT, "")); String sorts = sort.toSolr(); if (sorts == null) { post.remove(CommonParams.SORT); } else { post.put(CommonParams.SORT, sorts); } } else { // if no such sort attribute is given, use the ranking as configured for YaCy String fq = ranking.getFilterQuery(); String bq = ranking.getBoostQuery(); String bf = ranking.getBoostFunction(); if (fq.length() > 0) post.put(CommonParams.FQ, fq); if (bq.length() > 0) post.put(DisMaxParams.BQ, bq); if (bf.length() > 0) post.put("boost", bf); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29 } String daterange[] = post.remove("daterange"); if (daterange != null) { String origfq = post.get(CommonParams.FQ); String datefq = ""; for (String dr : daterange) { String from_to[] = dr.endsWith("..") ? new String[] { dr.substring(0, dr.length() - 2), "" } : dr.startsWith("..") ? new String[] { "", dr.substring(2) } : dr.split("\\.\\."); if (from_to.length != 2) continue; Date from = HeaderFramework.parseGSAFS(from_to[0]); if (from == null) from = new Date(0); Date to = HeaderFramework.parseGSAFS(from_to[1]); if (to == null) to = new Date(); to.setTime(to.getTime() + 24L * 60L * 60L * 1000L); // we add a day because the day is inclusive String z = CollectionSchema.last_modified.getSolrFieldName() + ":[" + ISO8601Formatter.FORMATTER.format(from) + " TO " + ISO8601Formatter.FORMATTER.format(to) + "]"; datefq = datefq.length() == 0 ? z : " OR " + z; } if (datefq.length() > 0) post.put(CommonParams.FQ, origfq == null || origfq.length() == 0 ? datefq : "(" + origfq + ") AND (" + datefq + ")"); } post.put(CommonParams.FL, CollectionSchema.content_type.getSolrFieldName() + ',' + CollectionSchema.id.getSolrFieldName() + ',' + CollectionSchema.sku.getSolrFieldName() + ',' + CollectionSchema.title.getSolrFieldName() + ',' + CollectionSchema.description_txt.getSolrFieldName() + ',' + CollectionSchema.load_date_dt.getSolrFieldName() + ',' + CollectionSchema.last_modified.getSolrFieldName() + ',' + CollectionSchema.size_i.getSolrFieldName()); post.put("hl", "true"); post.put("hl.q", originalQuery); post.put("hl.fl", CollectionSchema.description_txt + "," + CollectionSchema.h4_txt.getSolrFieldName() + "," + CollectionSchema.h3_txt.getSolrFieldName() + "," + CollectionSchema.h2_txt.getSolrFieldName() + "," + CollectionSchema.h1_txt.getSolrFieldName() + "," + CollectionSchema.text_t.getSolrFieldName()); post.put("hl.alternateField", CollectionSchema.description_txt.getSolrFieldName()); post.put("hl.simple.pre", "<b>"); post.put("hl.simple.post", "</b>"); post.put("hl.fragsize", Integer.toString(SearchEvent.SNIPPET_MAX_LENGTH)); //String[] access = post.remove("access"); //String[] entqr = post.remove("entqr"); // add sites operator String[] site = post.remove("site"); // example: col1|col2 if (site != null && site[0].length() > 0) { String origfq = post.get(CommonParams.FQ); String sitefq = QueryModifier.parseCollectionExpression(site[0]); post.put(CommonParams.FQ, origfq == null || origfq.length() == 0 ? sitefq : "(" + origfq + ") AND (" + sitefq + ")"); } // get the embedded connector EmbeddedSolrConnector connector = sb.index.fulltext().getDefaultEmbeddedConnector(); if (connector == null) return; // do the solr request SolrQueryRequest req = connector.request(post.toSolrParams(null)); SolrQueryResponse response = null; Exception e = null; try { response = connector.query(req); } catch (final SolrException ee) { e = ee; } if (response != null) e = response.getException(); if (e != null) { ConcurrentLog.logException(e); if (req != null) req.close(); SolrRequestInfo.clearRequestInfo(); return; } // set some context for the writer /* Map<Object,Object> context = req.getContext(); context.put("ip", header.get("CLIENTIP", "")); context.put("client", "vsm_frontent"); context.put("sort", sort.sort); context.put("site", site == null ? "" : site); context.put("access", access == null ? "p" : access[0]); context.put("entqr", entqr == null ? "3" : entqr[0]); */ // write the result directly to the output stream Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); try { responseWriter.write(ow, req, response); ow.flush(); } catch (final IOException e1) { } finally { req.close(); SolrRequestInfo.clearRequestInfo(); try { ow.close(); } catch (final IOException e1) { } } // log result Object rv = response.getValues().get("response"); int matches = 0; if (rv != null && rv instanceof ResultContext) { matches = ((ResultContext) rv).docs.matches(); } else if (rv != null && rv instanceof SolrDocumentList) { matches = (int) ((SolrDocumentList) rv).getNumFound(); } AccessTracker.addToDump(originalQuery, Integer.toString(matches)); ConcurrentLog.info("GSA Query", "results: " + matches + ", for query:" + post.toString()); }
From source file:net.yacy.http.servlets.SolrSelectServlet.java
License:Open Source License
@Override public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { HttpServletRequest hrequest = (HttpServletRequest) request; HttpServletResponse hresponse = (HttpServletResponse) response; SolrQueryRequest req = null;//from ww w . jav a 2 s.c o m final Method reqMethod = Method.getMethod(hrequest.getMethod()); Writer out = null; try { // prepare request to solr MultiMapSolrParams mmsp = SolrRequestParsers.parseQueryString(hrequest.getQueryString()); Switchboard sb = Switchboard.getSwitchboard(); boolean authenticated = true; // count remote searches if this was part of a p2p search if (mmsp.getMap().containsKey("partitions")) { final int partitions = mmsp.getInt("partitions", 30); sb.searchQueriesGlobal += 1.0f / partitions; // increase query counter } // get the ranking profile id int profileNr = mmsp.getInt("profileNr", 0); // rename post fields according to result style String querystring = ""; if (!mmsp.getMap().containsKey(CommonParams.Q) && mmsp.getMap().containsKey(CommonParams.QUERY)) { querystring = mmsp.get(CommonParams.QUERY, ""); mmsp.getMap().remove(CommonParams.QUERY); QueryModifier modifier = new QueryModifier(0); querystring = modifier.parse(querystring); modifier.apply(mmsp); QueryGoal qg = new QueryGoal(querystring); StringBuilder solrQ = qg.collectionTextQuery(); mmsp.getMap().put(CommonParams.Q, new String[] { solrQ.toString() }); // sru patch } String q = mmsp.get(CommonParams.Q, ""); if (querystring.length() == 0) querystring = q; if (!mmsp.getMap().containsKey(CommonParams.START)) { int startRecord = mmsp.getFieldInt("startRecord", null, 0); mmsp.getMap().remove("startRecord"); mmsp.getMap().put(CommonParams.START, new String[] { Integer.toString(startRecord) }); // sru patch } if (!mmsp.getMap().containsKey(CommonParams.ROWS)) { int maximumRecords = mmsp.getFieldInt("maximumRecords", null, 10); mmsp.getMap().remove("maximumRecords"); mmsp.getMap().put(CommonParams.ROWS, new String[] { Integer.toString(maximumRecords) }); // sru patch } mmsp.getMap().put(CommonParams.ROWS, new String[] { Integer .toString(Math.min(mmsp.getInt(CommonParams.ROWS, 10), (authenticated) ? 100000000 : 100)) }); // set ranking according to profile number if ranking attributes are not given in the request Ranking ranking = sb.index.fulltext().getDefaultConfiguration().getRanking(profileNr); if (!mmsp.getMap().containsKey(CommonParams.SORT) && !mmsp.getMap().containsKey(DisMaxParams.BQ) && !mmsp.getMap().containsKey(DisMaxParams.BF) && !mmsp.getMap().containsKey("boost")) { if (!mmsp.getMap().containsKey("defType")) mmsp.getMap().put("defType", new String[] { "edismax" }); String fq = ranking.getFilterQuery(); String bq = ranking.getBoostQuery(); String bf = ranking.getBoostFunction(); if (fq.length() > 0) mmsp.getMap().put(CommonParams.FQ, new String[] { fq }); if (bq.length() > 0) mmsp.getMap().put(DisMaxParams.BQ, new String[] { bq }); if (bf.length() > 0) mmsp.getMap().put("boost", new String[] { bf }); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29 } // get a response writer for the result String wt = mmsp.get(CommonParams.WT, "xml"); // maybe use /solr/select?q=*:*&start=0&rows=10&wt=exml QueryResponseWriter responseWriter = RESPONSE_WRITER.get(wt); if (responseWriter == null) throw new ServletException("no response writer"); if (responseWriter instanceof OpensearchResponseWriter) { // set the title every time, it is possible that it has changed final String promoteSearchPageGreeting = (sb .getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ? sb.getConfig("network.unit.description", "") : sb.getConfig(SwitchboardConstants.GREETING, ""); ((OpensearchResponseWriter) responseWriter).setTitle(promoteSearchPageGreeting); } // if this is a call to YaCys special search formats, enhance the query with field assignments if ((responseWriter instanceof YJsonResponseWriter || responseWriter instanceof OpensearchResponseWriter) && "true".equals(mmsp.get("hl", "true"))) { // add options for snippet generation if (!mmsp.getMap().containsKey("hl.q")) mmsp.getMap().put("hl.q", new String[] { q }); if (!mmsp.getMap().containsKey("hl.fl")) mmsp.getMap().put("hl.fl", new String[] { CollectionSchema.description_txt + "," + CollectionSchema.h4_txt.getSolrFieldName() + "," + CollectionSchema.h3_txt.getSolrFieldName() + "," + CollectionSchema.h2_txt.getSolrFieldName() + "," + CollectionSchema.h1_txt.getSolrFieldName() + "," + CollectionSchema.text_t.getSolrFieldName() }); if (!mmsp.getMap().containsKey("hl.alternateField")) mmsp.getMap().put("hl.alternateField", new String[] { CollectionSchema.description_txt.getSolrFieldName() }); if (!mmsp.getMap().containsKey("hl.simple.pre")) mmsp.getMap().put("hl.simple.pre", new String[] { "<b>" }); if (!mmsp.getMap().containsKey("hl.simple.post")) mmsp.getMap().put("hl.simple.post", new String[] { "</b>" }); if (!mmsp.getMap().containsKey("hl.fragsize")) mmsp.getMap().put("hl.fragsize", new String[] { Integer.toString(SearchEvent.SNIPPET_MAX_LENGTH) }); } // get the embedded connector String requestURI = hrequest.getRequestURI(); boolean defaultConnector = (requestURI.startsWith("/solr/" + WebgraphSchema.CORE_NAME)) ? false : requestURI.startsWith("/solr/" + CollectionSchema.CORE_NAME) || mmsp.get("core", CollectionSchema.CORE_NAME).equals(CollectionSchema.CORE_NAME); mmsp.getMap().remove("core"); SolrConnector connector = defaultConnector ? sb.index.fulltext().getDefaultEmbeddedConnector() : sb.index.fulltext().getEmbeddedConnector(WebgraphSchema.CORE_NAME); if (connector == null) { connector = defaultConnector ? sb.index.fulltext().getDefaultConnector() : sb.index.fulltext().getConnectorForRead(WebgraphSchema.CORE_NAME); } if (connector == null) throw new ServletException("no core"); // add default queryfield parameter according to local ranking config (or defaultfield) if (ranking != null) { // ranking normally never null final String qf = ranking.getQueryFields(); if (qf.length() > 4) { // make sure qf has content (else use df) addParam(DisMaxParams.QF, qf, mmsp.getMap()); // add QF that we set to be best suited for our index // TODO: if every peer applies a decent QF itself, this can be reverted to getMap().put() } else { mmsp.getMap().put(CommonParams.DF, new String[] { CollectionSchema.text_t.getSolrFieldName() }); } } else { mmsp.getMap().put(CommonParams.DF, new String[] { CollectionSchema.text_t.getSolrFieldName() }); } // do the solr request, generate facets if we use a special YaCy format final SolrQueryResponse rsp; if (connector instanceof EmbeddedSolrConnector) { req = ((EmbeddedSolrConnector) connector).request(mmsp); rsp = ((EmbeddedSolrConnector) connector).query(req); // prepare response hresponse.setHeader("Cache-Control", "no-cache, no-store"); HttpCacheHeaderUtil.checkHttpCachingVeto(rsp, hresponse, reqMethod); // check error if (rsp.getException() != null) { AccessTracker.addToDump(querystring, "0", new Date()); sendError(hresponse, rsp.getException()); return; } NamedList<?> values = rsp.getValues(); DocList r = ((ResultContext) values.get("response")).docs; int numFound = r.matches(); AccessTracker.addToDump(querystring, Integer.toString(numFound), new Date()); // write response header final String contentType = responseWriter.getContentType(req, rsp); if (null != contentType) response.setContentType(contentType); if (Method.HEAD == reqMethod) { return; } // write response body if (responseWriter instanceof BinaryResponseWriter) { ((BinaryResponseWriter) responseWriter).write(response.getOutputStream(), req, rsp); } else { out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); responseWriter.write(out, req, rsp); out.flush(); } } else { // write a 'faked' response using a call to the backend SolrDocumentList sdl = connector.getDocumentListByQuery(mmsp.getMap().get(CommonParams.Q)[0], mmsp.getMap().get(CommonParams.SORT) == null ? null : mmsp.getMap().get(CommonParams.SORT)[0], Integer.parseInt(mmsp.getMap().get(CommonParams.START)[0]), Integer.parseInt(mmsp.getMap().get(CommonParams.ROWS)[0]), mmsp.getMap().get(CommonParams.FL)); OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream()); EnhancedXMLResponseWriter.write(osw, req, sdl); osw.close(); } } catch (final Throwable ex) { sendError(hresponse, ex); } finally { if (req != null) { req.close(); } SolrRequestInfo.clearRequestInfo(); if (out != null) try { out.close(); } catch (final IOException e1) { } } }
From source file:net.yacy.search.query.QueryModifier.java
License:Open Source License
public void apply(serverObjects post) { final StringBuilder fq = apply(post.get(CommonParams.FQ, "")); if (fq.length() > 0) { String fqs = fq.toString(); if (fqs.startsWith(" AND ")) fqs = fqs.substring(5);//from w w w .j a v a 2 s.c o m post.remove(CommonParams.FQ); post.put(CommonParams.FQ, fqs); } }
From source file:net.yacy.search.query.QueryModifier.java
License:Open Source License
public void apply(MultiMapSolrParams mmsp) { final StringBuilder fq = apply(mmsp.get(CommonParams.FQ, "")); if (fq.length() > 0) { String fqs = fq.toString(); if (fqs.startsWith(" AND ")) fqs = fqs.substring(5);//from w w w.j a v a2 s. c om mmsp.getMap().remove(CommonParams.FQ); mmsp.getMap().put(CommonParams.FQ, new String[] { fqs }); } }