/** * 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)); }
if (!(((SolrIndexReader) rb.req.getSearcher().getIndexReader()).getWrappedReader() instanceof lucandra.IndexReader)) return false; if (rb.req.getParams().getBool(ShardParams.IS_SHARD, false)) String indexName = (String) rb.req.getContext().get("solandra-index");
@Override public String[] getParams(String param) { String[] vals = params.getParams(param); if( vals == null || vals.length == 0 ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Missing required parameter: "+param ); } return vals; }
@Override public void init( final NamedList args ) { if( args != null ) { SolrParams params = SolrParams.toSolrParams( args ); maxNumToLog = params.getInt( "maxNumToLog", maxNumToLog ); } }
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 ); rsp.add( "doc", docinfo ); else if ( "schema".equals( params.get( "show" ) ) ) { rsp.add( "schema", getSchemaInfo( req.getSchema() ) ); if( params.get( CommonParams.FL ) != null ) { fields = new HashSet<String>(); for( String f : params.getParams( CommonParams.FL ) ) { fields.add( f );
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()));*/ }
@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 { int count = params.getInt(SPELLCHECK_COUNT, 1); boolean onlyMorePopular = params.getBool(SPELLCHECK_ONLY_MORE_POPULAR, DEFAULT_ONLY_MORE_POPULAR); boolean extendedResults = params.getBool(SPELLCHECK_EXTENDED_RESULTS, false); boolean collate = params.getBool(SPELLCHECK_COLLATE, false); float accuracy = params.getFloat(SPELLCHECK_ACCURACY, Float.MIN_VALUE); Integer alternativeTermCount = params.getInt(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT); Integer maxResultsForSuggest = params.getInt(SpellingParams.SPELLCHECK_MAX_RESULTS_FOR_SUGGEST); ModifiableSolrParams customParams = new ModifiableSolrParams(); for (String checkerName : getDictionaryNames(params)) { response.add("suggestions", suggestions); rb.rsp.add("spellcheck", response);
@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); float secondAdjWeight = params.getFloat(SECOND_ADJ_WEIGHT, DEFAULT_SECOND_ADJACENT_WEIGHT); float bigramWeight = params.getFloat(BIGRAM_WEIGHT, DEFAULT_BIGRAM_WEIGHT); int primaryWindowSize = params.getInt(QAParams.PRIMARY_WINDOW_SIZE, DEFAULT_PRIMARY_WINDOW_SIZE); int adjacentWindowSize = params.getInt(QAParams.ADJACENT_WINDOW_SIZE, DEFAULT_ADJACENT_WINDOW_SIZE); int secondaryWindowSize = params.getInt(QAParams.SECONDARY_WINDOW_SIZE, DEFAULT_SECONDARY_WINDOW_SIZE); WindowBuildingTVM tvm = new WindowBuildingTVM(primaryWindowSize, adjacentWindowSize, secondaryWindowSize); PassagePriorityQueue rankedPassages = new PassagePriorityQueue(); NamedList qaResp = new NamedList(); rb.rsp.add("qaResponse", qaResp); int rows = params.getInt(QA_ROWS, 5);
@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));
ContentStream stream, UpdateRequestProcessor processor) throws Exception { Parser parser = null; String streamType = req.getParams().get(ExtractingParams.STREAM_TYPE, null); if (streamType != null) { String resourceName = req.getParams().get(ExtractingParams.RESOURCE_NAME, null); if (resourceName != null) { metadata.add(TikaMetadataKeys.RESOURCE_NAME_KEY, resourceName); String xpathExpr = params.get(ExtractingParams.XPATH_EXPRESSION); boolean extractOnly = params.getBool(ExtractingParams.EXTRACT_ONLY, false); SolrContentHandler handler = factory.createSolrContentHandler(metadata, params, req.getSchema()); ContentHandler parsingHandler = handler; BaseMarkupSerializer serializer = null; if (extractOnly == true) { String extractFormat = params.get(ExtractingParams.EXTRACT_FORMAT, "xml"); writer = new StringWriter(); if (extractFormat.equals(TEXT_FORMAT)) { String pwMapFile = params.get(ExtractingParams.PASSWORD_MAP_FILE); if(pwMapFile != null && pwMapFile.length() > 0) { InputStream is = req.getCore().getResourceLoader().openResource(pwMapFile); if(is != null) { log.debug("Password file supplied: "+pwMapFile); String resourcePassword = params.get(ExtractingParams.RESOURCE_PASSWORD); if(resourcePassword != null) { epp.setExplicitPassword(resourcePassword);
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.setHttpCaching(false); final SolrParams solrParams = req.getParams(); String dicPath = solrParams.get("dicPath"); Dictionary dict = Utils.getDict(dicPath, loader); NamedList<Object> result = new NamedList<Object>(); result.add("dicPath", dict.getDicPath().toURI()); boolean check = solrParams.getBool("check", false); //仅仅用于检测词库是否有变化 //用于尝试加载词库,有此参数, check 参数可以省略。 boolean reload = solrParams.getBool("reload", false); check |= reload; boolean changed = false; boolean reloaded = false; if(check) { changed = dict.wordsFileIsChange(); result.add("changed", changed); } if(changed && reload) { reloaded = dict.reload(); result.add("reloaded", reloaded); } rsp.add("result", result); }
@Override public void process(ResponseBuilder rb) throws IOException { // Handle the initial facets super.process(rb); // And do the facet tree, if required if (rb.doFacets && rb.req.getParams().getBool(FACET_TREE, false)) { HierarchicalFacets ftp = new HierarchicalFacets(rb.req, rb.getResults().docSet, rb.req.getParams(), rb, parameters); @SuppressWarnings("rawtypes") SimpleOrderedMap<NamedList> ftpResponse = ftp.process(rb.req.getParams().getParams(FACET_TREE_FIELD)); @SuppressWarnings("unchecked") NamedList<Object> facetCounts = (NamedList<Object>) rb.rsp.getValues().get("facet_counts"); if (facetCounts != null) { facetCounts.add("facet_trees", ftpResponse); } else { facetCounts = new NamedList<>(); facetCounts.add("facet_trees", ftpResponse); rb.rsp.add("facet_counts", facetCounts); } } }
SolrParams params = req.getParams(); String q = params.get(CommonParams.Q); String[] fqs = params.getParams(CommonParams.FQ); int start = 0; try { start = Integer.parseInt(params.get(CommonParams.START)); } catch (Exception e) { /* default */ } int rows = 0; try { rows = Integer.parseInt(params.get(CommonParams.ROWS)); } catch (Exception e) { /* default */ } SolrIndexSearcher searcher = req.getSearcher(); Map<String,SchemaField> fields = req.getSchema().getFields(); int ndocs = start + rows; Filter filter = buildFilter(fqs, req); results.setMaxScore(maxScore); results.setStart(start); rsp.add("response", results);
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void writeResponse() throws IOException { writer.write(XML_PROCESSING_INSTR); final String stylesheet = req.getParams().get("stylesheet"); if (isNotNullOrEmptyString(stylesheet)) { writer.write(XML_STYLESHEET); escapeAttributeValue(stylesheet, writer); writer.write(XML_STYLESHEET_END); } writer.write(RESPONSE_ROOT_ELEMENT_START); final NamedList<?> responseValues = rsp.getValues(); if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) { responseValues.remove(RESPONSE_HEADER); } else { ((NamedList)responseValues.get(RESPONSE_HEADER)).add(Names.QUERY, responseValues.remove(Names.QUERY).toString()); } for (final Entry<String, ?> entry : responseValues) { writeValue(entry.getKey(), entry.getValue(), responseValues); } writer.write(RESPONSE_ROOT_ELEMENT_END); }
/** 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; }
public static SolrQueryRequest substituteField(SolrQueryRequest req){ SolrParams params = req.getParams(); String query = params.get("q"); System.out.println("query before ="+query); query = query.replace(' ', '_'); System.out.println("query after ="+query); NamedList values = params.toNamedList(); values.remove("q"); values.add("q", query); params = SolrParams.toSolrParams(values); req.setParams(params); return req; } }
@SuppressWarnings("unchecked") protected void performHighlighting(ReSearcherRequestContext ctx, ResponseBuilder rb) { // check if highlighting is needed SolrParams params = rb.req.getParams(); String highlightRemoved = params.get(RES_HIGHLIGHT_REMOVED_TAG_PARAM_NAME); String highlightReplaced = params.get(RES_HIGHLIGHT_REPLACED_TAG_PARAM_NAME); boolean ignoreQuotes = params.get(RES_HIGHLIGHT_IGNORE_QUOTES_PARAM_NAME, "true").equals("true") ? true : false; if (highlightRemoved == null && highlightReplaced == null) { // nothing to do, so just return; return; } // else, fetch suggestions produced by the component and perform highlighting List<String> sugs = (List<String>) rb.rsp.getValues().get(getSuggestionsTagName()); if (sugs == null) { // if component didn't generate suggestions, there is nothing to highlight return; } List<String> sugsHighlighted = new ArrayList<String>(); for (String sug : sugs) { sugsHighlighted.add(CorrectionHighlighter.highlightCorrections(ctx.getOriginalQueryString(), sug, highlightRemoved, highlightReplaced, ignoreQuotes)); } rb.rsp.getValues().add(getSuggestionsTagName() + "_highlighted", sugsHighlighted); }