List of usage examples for org.apache.solr.common.params SolrParams wrapDefaults
public static SolrParams wrapDefaults(SolrParams params, SolrParams defaults)
From source file:com.adr.bigdata.search.product.fe.BaseSuggestionHandler.java
@Override public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) { String cacheKey = SolrParamUtils.transform(req.getParams()); try {//from www. j a v a 2s .com String cacheResponse = this.rdModel.get(cacheKey); if (cacheResponse == null) { //cacheMiss try { final Object[] terms = new Object[1]; suggestionLogic.execute(req, rsp, new Callable() { @Override public void call(Object... args) { terms[0] = args[0]; } }); SolrQueryResponse _rsp = new SolrQueryResponse(); super.handleRequest(req, _rsp); suggestionLogic.writeRsp(req, _rsp, terms[0]); String result = outerString(req, _rsp); if (!zeroResult(_rsp)) { this.rdModel.put(cacheKey, result); } ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); params.set("vincache", true); SolrParams _params = SolrParams.wrapDefaults(params, defaults); _params = SolrParams.wrapAppended(_params, appends); req.setParams(_params); rsp.add("vincache", result); } catch (Exception e) { error(req, rsp); getLogger().error("", e); } } else { //cache hit ModifiableSolrParams solrParam = new ModifiableSolrParams(req.getParams()); solrParam.set("vincache", true); SolrParams params = SolrParams.wrapAppended(solrParam, appends); params = SolrParams.wrapDefaults(params, defaults); req.setParams(params); rsp.add("vincache", cacheResponse); } } catch (Exception cacheEx) { getLogger().error("fail to get from redis cache.....{}", cacheEx.getMessage()); try { final Object[] terms = new Object[1]; suggestionLogic.execute(req, rsp, new Callable() { @Override public void call(Object... args) { terms[0] = args[0]; } }); super.handleRequest(req, rsp); suggestionLogic.writeRsp(req, rsp, terms[0]); } catch (Exception e) { error(req, rsp); getLogger().error("", e); } } }
From source file:com.github.healthonnet.search.SynonymExpandingExtendedDismaxQParserPlugin.java
License:Apache License
@Override public Query parse() throws SyntaxError { SolrParams localParams = getLocalParams(); SolrParams params = getParams();/* w ww . ja va2 s.com*/ SolrParams solrParams = localParams == null ? params : SolrParams.wrapDefaults(localParams, params); String defmainAnalyser = solrParams.get(Params.MAIN_DEFAULT_ANALYZER, null); String defSynonymsAnalyser = solrParams.get(Params.SYNONYMS_DEFAULT_ANALYZER, null); Boolean preanalyzis = solrParams.getBool(Params.MAIN_PREANALYZIS, false); // check to make sure the analyzer exists if (preanalyzis) { String preAnalyzerName = solrParams.get(Params.MAIN_ANALYZER, null); if (preAnalyzerName == null) { // no query analyzer specified if (defmainAnalyser != null && defmainAnalyser.length() > 0) { preAnalyzerName = defmainAnalyser; } else { if (mainAnalyzers.size() >= 1) { // only one analyzer defined; just use that one preAnalyzerName = mainAnalyzers.keySet().iterator().next(); } } } if (preAnalyzerName != null) { mainAnalyzer = mainAnalyzers.get(preAnalyzerName); analyzeMainQuery(mainAnalyzer); } else mainAnalyzer = null; } else { mainAnalyzer = null; } Query query = mainQueryParser.parse(); // disable/enable synonym handling altogether if (!solrParams.getBool(Params.SYNONYMS, false)) { reasonForNotExpandingSynonyms = ReasonForNotExpandingSynonyms.PluginDisabled; return query; } // check to make sure the analyzer exists String analyzerName = solrParams.get(Params.SYNONYMS_ANALYZER, null); if (analyzerName == null) { // no synonym analyzer specified if (defSynonymsAnalyser != null && defSynonymsAnalyser.length() > 0) { analyzerName = defSynonymsAnalyser; } else { if (synonymAnalyzers.size() >= 1) { // only one analyzer defined; just use that one analyzerName = synonymAnalyzers.keySet().iterator().next(); } else { reasonForNotExpandingSynonyms = ReasonForNotExpandingSynonyms.NoAnalyzerSpecified; return query; } } } Analyzer synonymAnalyzer = synonymAnalyzers.get(analyzerName); if (synonymAnalyzer == null) { // couldn't find analyzer reasonForNotExpandingSynonyms = ReasonForNotExpandingSynonyms.AnalyzerNotFound; return query; } if (solrParams.getBool(Params.SYNONYMS_DISABLE_PHRASE_QUERIES, false) && getQueryStringFromParser().indexOf('"') != -1) { // disable if a phrase query is detected, i.e. there's a '"' reasonForNotExpandingSynonyms = ReasonForNotExpandingSynonyms.IgnoringPhrases; return query; } try { query = attemptToApplySynonymsToQuery(query, solrParams, synonymAnalyzer); } catch (IOException e) { // TODO: better error handling - for now just bail out reasonForNotExpandingSynonyms = ReasonForNotExpandingSynonyms.UnhandledException; e.printStackTrace(System.err); } return query; }
From source file:com.kmwllc.search.solr.parser.GraphQueryParser.java
License:Open Source License
@Override public Query parse() throws SyntaxError { SolrParams localParams = getLocalParams(); SolrParams params = getParams();/*from ww w. ja v a2 s . com*/ SolrParams solrParams = SolrParams.wrapDefaults(localParams, params); QParser baseParser = subQuery(solrParams.get(QueryParsing.V), null); Query startNodesQuery = baseParser.getQuery(); String fromField = localParams.get("from", "node_id"); String toField = localParams.get("to", "edge_ids"); QParser traversalBaseParser = subQuery(localParams.get("traversalFilter"), null); Query traversalFilter = traversalBaseParser.getQuery(); // TODO: un-invert this logic boolean onlyLeafNodes = Boolean.valueOf(localParams.get("returnOnlyLeaf", "false")); boolean returnStartNodes = Boolean.valueOf(localParams.get("returnRoot", "true")); int maxDepth = Integer.valueOf(localParams.get("maxDepth", "-1")); GraphQuery gq = new GraphQuery(startNodesQuery, fromField, toField, traversalFilter); gq.setMaxDepth(maxDepth); gq.setOnlyLeafNodes(onlyLeafNodes); gq.setReturnStartNodes(returnStartNodes); return gq; }
From source file:com.sindicetech.siren.solr.qparser.SirenQParser.java
License:Open Source License
@Override public Query parse() throws SyntaxError { final SolrParams solrParams = SolrParams.wrapDefaults(localParams, params); final Map<String, Float> boosts = parseQueryFields(req.getSchema(), solrParams); // We disable the coord because this query is an artificial construct final BooleanQuery query = new BooleanQuery(true); // if empty main query, ignore and try to parse the nested queries if (qstr != null && !qstr.isEmpty()) { this.processMainQuery(query, boosts, qstr); }/*from w w w. j a v a 2 s . c o m*/ this.processNestedQuery(query, solrParams); return query; }
From source file:fr.gael.dhus.search.plugins.DocAccessControl.java
License:Open Source License
@Override public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { SolrParams solrParams = SolrParams.wrapDefaults(localParams, params); final Long userId = Long.valueOf(solrParams.get(SolrUtils.CURRENT_USER_ID, "-1")); return new QParser(qstr, localParams, params, req) { @Override// w w w.j a va 2 s. com public Query parse() throws SyntaxError { return new DocAccess(userId); } }; }
From source file:org.opensextant.solrtexttagger.AbstractTaggerTest.java
License:Open Source License
/** REMEMBER to close() the result req object. */ protected SolrQueryRequest reqDoc(String doc, SolrParams moreParams) { log.debug("Test doc: " + doc); SolrParams params = SolrParams.wrapDefaults(moreParams, baseParams); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), params) { };/*from ww w.ja va2 s . c o m*/ Iterable<ContentStream> stream = Collections .singleton((ContentStream) new ContentStreamBase.StringStream(doc)); req.setContentStreams(stream); return req; }
From source file:org.opensextant.solrtexttagger.TaggerRequestHandler.java
License:Open Source License
/** * This request handler supports configuration options defined at the top level as well as * those in typical Solr 'defaults', 'appends', and 'invariants'. The top level ones are treated * as invariants.//from w w w . j av a2 s.c om */ private void setTopInitArgsAsInvariants(SolrQueryRequest req) { // First convert top level initArgs to SolrParams HashMap<String, String> map = new HashMap<>(initArgs.size()); for (int i = 0; i < initArgs.size(); i++) { Object val = initArgs.getVal(i); if (val != null && !(val instanceof NamedList)) map.put(initArgs.getName(i), val.toString()); } if (map.isEmpty()) return;//short circuit; nothing to do SolrParams topInvariants = new MapSolrParams(map); // By putting putting the top level into the 1st arg, it overrides request params in 2nd arg. req.setParams(SolrParams.wrapDefaults(topInvariants, req.getParams())); }
From source file:org.sindice.siren.solr.qparser.SirenQParser.java
License:Apache License
@Override public Query parse() throws ParseException { if (qstr == null || qstr.length() == 0) return null; final SolrParams solrParams = SolrParams.wrapDefaults(localParams, params); final Map<String, Float> boosts = parseQueryFields(req.getSchema(), solrParams); final BooleanQuery main = this.getMainQuery(boosts, qstr); this.addNestedQuery(main, solrParams); return main;/* w ww .ja v a 2 s. c o m*/ }
From source file:org.tallison.solr.search.SpanQParser.java
License:Apache License
public SpanQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { super(qstr, localParams, params, req); IndexSchema schema = req.getSchema(); //now set the params SolrParams comboParams = SolrParams.wrapDefaults(localParams, params); //preamble to initializing the parser Analyzer analyzer = schema.getQueryAnalyzer(); //default analyzer? defaultFieldName = getParam(CommonParams.DF); if (defaultFieldName != null) { SchemaField sf = schema.getField(defaultFieldName); if (sf != null && sf.getType() != null) { analyzer = sf.getType().getQueryAnalyzer(); }//from www .java2 s.c om } //initialize the parser parser = new SolrSpanQueryParser(defaultFieldName, analyzer, schema, this); parser.setAllowLeadingWildcard(comboParams.getBool(ALLOW_LEADING_WILDCARD, true)); parser.setAutoGeneratePhraseQueries(comboParams.getBool(AUTO_GENERATE_PHRASE, false)); org.apache.lucene.queryparser.classic.QueryParser.Operator defaultOp = DEFAULT_OPERATOR; String defaultOpString = comboParams.get(QueryParsing.OP); if (defaultOpString != null) { if (defaultOpString.equalsIgnoreCase("and")) { defaultOp = org.apache.lucene.queryparser.classic.QueryParser.Operator.AND; } } parser.setDefaultOperator(defaultOp); parser.setFuzzyMaxEdits(comboParams.getInt(MAX_FUZZY_EDITS, 2)); parser.setFuzzyPrefixLength(comboParams.getInt(PREFIX_LENGTH, 0)); parser.setPhraseSlop(comboParams.getInt(PHRASE_SLOP, 0)); parser.setSpanNearMaxDistance(comboParams.getInt(NEAR_MAX, -1)); parser.setSpanNotNearMaxDistance(comboParams.getInt(NOT_NEAR_MAX, -1)); }
From source file:org.xwiki.search.solr.internal.XWikiDismaxQParserPlugin.java
License:Open Source License
/** * Extends the given search parameters with aliases for the fields that appear in the given search query. * /*from w w w . ja v a 2 s . co m*/ * @param query the search query where to look for field names * @param parameters the search parameters to extend * @return the extended search parameters */ public SolrParams withFieldAliases(String query, SolrParams parameters) { Set<String> fieldNames = extractFieldNames(query); // Add default query fields (these fields are used to search for free text that appears in the query). String defaultQueryFields = parameters.get("qf"); if (defaultQueryFields != null) { fieldNames.addAll(SolrPluginUtils.parseFieldBoosts(defaultQueryFields).keySet()); } if (fieldNames.isEmpty()) { return parameters; } Map<String, String> aliasParameters = new HashMap<String, String>(); addMultilingualFieldAliases(fieldNames, aliasParameters, parameters); addTypedDynamicFieldAliases(fieldNames, aliasParameters, parameters); return aliasParameters.isEmpty() ? parameters : SolrParams.wrapDefaults(new MapSolrParams(aliasParameters), parameters); }