throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "meaningless command: " + cmd); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "operation not supported" + cmd); Term term = idTerm.createTerm(idFieldType.toInternal(cmd.id));
} catch (SolrException e) { if (e.code() != 400) { throw new IOException(e);
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception IndexSchema schema = req.getSchema(); SolrIndexSearcher searcher = req.getSearcher(); IndexReader reader = searcher.getReader(); SolrParams params = req.getParams(); int numTerms = params.getInt( NUMTERMS, DEFAULT_COUNT ); Integer docId = params.getInt( DOC_ID ); if( docId == null && params.get( ID ) != null ) { SchemaField uniqueKey = schema.getUniqueKeyField(); String v = uniqueKey.getType().toInternal( params.get(ID) ); Term t = new Term( uniqueKey.getName(), v ); docId = searcher.getFirstMatch( t ); if( docId < 0 ) { throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+params.get( ID ) ); throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+docId ); info.add( "key", getFieldFlagsKey() ); info.add( "NOTE", "Document Frequency (df) is not updated when a document is marked for deletion. df values include deleted documents." ); rsp.add( "info", info ); rsp.setHttpCaching(false);
@Override public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false)) { return; throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Illegal query type. The incoming query must be a Lucene SpanNearQuery and it was a " + origQuery.getClass().getName()); SolrIndexSearcher searcher = rb.req.getSearcher(); IndexReader reader = searcher.getIndexReader(); Spans spans = sQuery.getSpans(reader); createWeights(params.get(CommonParams.Q), sQuery, termWeights, bigramWeights, reader); float adjWeight = params.getFloat(ADJACENT_WEIGHT, DEFAULT_ADJACENT_WEIGHT); addPassage(tvm.passage, rankedPassages, termWeights, bigramWeights, adjWeight, secondAdjWeight, bigramWeight); } catch (CloneNotSupportedException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Internal error cloning Passage", e); NamedList qaResp = new NamedList(); rb.rsp.add("qaResponse", qaResp); SchemaField uniqField = rb.req.getSchema().getUniqueKeyField(); if (rankedPassages.size() > 0) { int size = Math.min(rows, rankedPassages.size());
@Override @SuppressWarnings("unchecked") public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false) || spellCheckers.isEmpty()) { return; boolean shardRequest = "true".equals(params.get(ShardParams.IS_SHARD)); String q = params.get(SPELLCHECK_Q); SolrSpellChecker spellChecker = getSpellChecker(params); Collection<Token> tokens = null; throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "The spellcheck.q parameter is required."); } else { Integer hitsInteger = (Integer) rb.rsp.getToLog().get("hits"); long hits = 0; if (hitsInteger == null) { IndexReader reader = rb.req.getSearcher().getIndexReader(); SpellingOptions options = new SpellingOptions(tokens, reader, count, alternativeTermCount, suggestMode, extendedResults, accuracy, response.add("suggestions", suggestions); rb.rsp.add("spellcheck", response); throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Specified dictionaries do not exist: " + getDictionaryNameAsSingleString(getDictionaryNames(params)));
@Override public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException { String xsl = request.getParams().get("lux.xml-xsl-stylesheet"); @SuppressWarnings("unchecked") List<String> errors = response.getValues().getAll("xpath-error"); String contentType = getContentType (request, response); NamedList<?> values = (NamedList<?>) response.getValues().get("xpath-results"); if (values == null && !errors.isEmpty()) { StringBuilder buf = new StringBuilder(); buf.append(e).append("\n"); throw new SolrException(ErrorCode.BAD_REQUEST, buf.toString()); } else if (response.getException() != null) { String error = (String) ((NamedList<?>) response.getValues().get("error")).get("msg"); if (error == null) { error = response.getException().toString();
private void addDebugInfo(SolrQueryRequest req, SolrQueryResponse rsp, String q, List<Query> mltFqFilters, MLTResult mltResult) { DocListAndSet mltDocs = mltResult.getResults(); boolean dbg = req.getParams().getBool(CommonParams.DEBUG_QUERY, false); boolean dbgQuery = false, dbgResults = false; if (dbg == false){//if it's true, we are doing everything anyway. String[] dbgParams = req.getParams().getParams(CommonParams.DEBUG); if (dbgParams != null) { for (int i = 0; i < dbgParams.length; i++) { NamedList<Object> dbgInfo = new NamedList<Object>(); NamedList<Object> stdDbg = SolrPluginUtils.doStandardDebug(req, q, mltResult.getQuery(), mltDocs.docList, dbgQuery, dbgResults); if (null != dbgInfo) { rsp.add("debug", dbgInfo); dbgInfo.add( "mltTerms", it ); dbgInfo.addAll(stdDbg); dbgInfo.add("filter_queries",req.getParams().getParams(CommonParams.FQ)); List<String> fqs = new ArrayList<String>(mltFqFilters.size()); for (Query fq : mltFqFilters) { SolrException.log(log, "Exception during debug", e); rsp.add("exception_during_debug", SolrException.toStr(e));
public void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) { if (handler==null) { log.warn(logid+"Null Request Handler '" + req.getParams().get(CommonParams.QT) +"' :" + req); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,"Null Request Handler '" + req.getParams().get(CommonParams.QT) + "'", true); } // setup response header and handle request final NamedList<Object> responseHeader = new SimpleOrderedMap<Object>(); rsp.add("responseHeader", responseHeader); NamedList toLog = rsp.getToLog(); //toLog.add("core", getName()); toLog.add("webapp", req.getContext().get("webapp")); toLog.add("path", req.getContext().get("path")); toLog.add("params", "{" + req.getParamString() + "}"); handler.handleRequest(req,rsp); setResponseHeaderValues(handler,req,rsp); StringBuilder sb = new StringBuilder(); for (int i=0; i<toLog.size(); i++) { String name = toLog.getName(i); Object val = toLog.getVal(i); sb.append(name).append("=").append(val).append(" "); } log.info(logid + sb.toString()); /*log.info(logid+"" + req.getContext().get("path") + " " + req.getParamString()+ " 0 "+ (int)(rsp.getEndTime() - req.getStartTime()));*/ }
/** * Handle Custom Action. * <p/> * This method could be overridden by derived classes to handle custom actions. <br> By default - this method throws a * solr exception. Derived classes are free to write their derivation if necessary. */ protected boolean handleCustomAction(SolrQueryRequest req, SolrQueryResponse rsp) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unsupported operation: " + req.getParams().get(CoreAdminParams.ACTION)); }
@Override public NamedList<Object> processResponse(InputStream body, String encoding) { try { StringWriter writer = new StringWriter(); IOUtils.copy(body, writer, encoding); String output = writer.toString(); NamedList<Object> list = new NamedList<>(); list.add("response", output); return list; } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "parsing error", e); } }
String alternate = cores.getManagementPath(); if (alternate != null && path.startsWith(alternate)) { path = path.substring(0, alternate.length()); if( path.equals( cores.getAdminPath() ) ) { handler = cores.getMultiCoreHandler(); solrReq = adminRequestParser.parse(null,path, req); handleAdminRequest(req, response, handler, solrReq); final SolrConfig config = core.getSolrConfig(); handler = core.getRequestHandler( path ); String qt = solrReq.getParams().get( CommonParams.QT ); handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); solrReq.close();
String mt = atm.get(type); String field = params.get(QUERY_FIELD); SchemaField sp = req.getSchema().getFieldOrNull(field); if (sp == null) { throw new SolrException(ErrorCode.SERVER_ERROR,"Undefined field: "+field); Analyzer analyzer = sp.getType().getQueryAnalyzer(); TokenStream ts = analyzer.tokenStream(field, new StringReader(qstr)); throw new ParseException(e.getLocalizedMessage()); return new SpanNearQuery(sql.toArray(new SpanQuery[sql.size()]), params.getInt(QAParams.SLOP, 10), true);//<co id="qqp.spanNear"/>
private MLTResult getMoreLikeTheseFromQuery(SolrQueryResponse rsp, SolrParams params, int flags, String q, Query query, SortSpec sortSpec, List<Query> targetFqFilters, List<Query> mltFqFilters, SolrIndexSearcher searcher, MoreLikeThisHelper mlt, int start, int rows) throws IOException, SyntaxError { boolean includeMatch = params.getBool(MoreLikeThisParams.MATCH_INCLUDE, true); int matchOffset = params.getInt(MoreLikeThisParams.MATCH_OFFSET, 0); // Find the base match DocList match = searcher.getDocList(query, targetFqFilters, null, matchOffset, 10000, flags); // only get the first one... if(match.matches() == 0){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format("MoreLikeThis was unable to find any documents matching the query: '%s'.", q)); } if (includeMatch) { rsp.add("match", match); } // This is an iterator, but we only handle the first match DocIterator iterator = match.iterator(); if (iterator.hasNext()) { // do a MoreLikeThis query for each document in results return mlt.getMoreLikeTheseFromDocs(iterator, start, rows, mltFqFilters, flags, sortSpec.getSort()); } return null; }
public Long getExpirationTime() { try { return (Long)getResponse().get("long"); } catch (ClassCastException e) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "parsing error", e); } } }
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { SolrParams params = req.getParams(); UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessingChain(params.get(UpdateParams.UPDATE_PROCESSOR)); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); try { ContentStreamLoader documentLoader = newLoader(req, processor); Iterable<ContentStream> streams = req.getContentStreams(); if (streams == null) { if (!RequestHandlerUtils.handleCommit(processor, params, false) && !RequestHandlerUtils.handleRollback(processor, params, false)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing content stream"); } } else { for (ContentStream stream : streams) { documentLoader.load(req, rsp, stream); } // Perhaps commit from the parameters RequestHandlerUtils.handleCommit(processor, params, false); RequestHandlerUtils.handleRollback(processor, params, false); } } finally { // finish the request processor.finish(); } }
SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.NAME); CoreDescriptor dcore = new CoreDescriptor(coreContainer, name, params.get(CoreAdminParams.INSTANCE_DIR)); String opts = params.get(CoreAdminParams.CONFIG); if (opts != null) dcore.setConfigName(opts); SolrCore core = coreContainer.create(dcore); coreContainer.register(name, core, false); rsp.add("core", core.getName()); return coreContainer.isPersistent(); } catch (Exception ex) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error executing default implementation of CREATE", ex);
SolrCore core = coreContainer.getCore( coreName ); if( core == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "No such core: " + coreName ); SolrRequestHandler handler = core.getRequestHandler( path ); if( handler == null ) { if( "/select".equals( path ) || "/select/".equalsIgnoreCase( path) ) { String qt = params.get( CommonParams.QT ); handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); path.equals( coreContainer.getAdminPath() ) ) { handler = coreContainer.getMultiCoreHandler(); core.close(); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+path ); req.getContext().put( "path", path ); SolrQueryResponse rsp = new SolrQueryResponse(); core.execute( handler, req, rsp ); req.close(); return normalized;
/** get the param from params, fail if not found **/ @Override public String get(String param) { String val = params.get(param); if( val == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Missing required parameter: "+param ); } return val; }
@Override public SortField getSortField(final SchemaField field, final boolean reverse) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unsupported operation. Can not sort on SIREn field: " + field.getName()); }