List of usage examples for org.apache.solr.common.util NamedList getAll
public List<T> getAll(String name)
From source file:at.newmedialab.lmf.util.solr.SuggestionRequestHandler.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" })
public void inform(SolrCore core) {
super.inform(core);
suggestionService = new SuggestionService(core, this.getInitArgs());
//set default args
NamedList args = (NamedList) this.getInitArgs().get("defaults");
SUGGESTION = args.get(SuggestionRequestParams.SUGGESTION) != null
? Boolean.parseBoolean((String) args.get(SuggestionRequestParams.SUGGESTION))
: SUGGESTION;/* w w w . j ava2 s .c om*/
MULTIVALUE = args.get(SuggestionRequestParams.SUGGESTION_MULTIVALUE) != null
? Boolean.parseBoolean((String) args.get(SuggestionRequestParams.SUGGESTION_MULTIVALUE))
: MULTIVALUE;
LIMIT = args.get(SuggestionRequestParams.SUGGESTION_LIMIT) != null
? Integer.parseInt((String) args.get(SuggestionRequestParams.SUGGESTION_LIMIT))
: LIMIT;
DF = args.get(SuggestionRequestParams.SUGGESTION_DF) != null
? (String) args.get(SuggestionRequestParams.SUGGESTION_DF)
: DF;
List<String> fields = args.getAll(SuggestionRequestParams.SUGGESTION_FIELD) != null
? args.getAll(SuggestionRequestParams.SUGGESTION_FIELD)
: Collections.emptyList();
if (!fields.isEmpty()) {
FIELDS = fields.toArray(new String[fields.size()]);
}
List<String> fqs = args.getAll(CommonParams.FQ) != null ? args.getAll(CommonParams.FQ)
: Collections.emptyList();
if (!fqs.isEmpty()) {
FQS = fqs.toArray(new String[fields.size()]);
}
}
From source file:com.constellio.data.dao.services.bigVault.CustomizedSpellCheckResponse.java
License:Apache License
public CustomizedSpellCheckResponse(NamedList<Object> spellInfo) { Object sugg = spellInfo.get("suggestions"); if (sugg == null) { correctlySpelled = true;// ww w.j a v a 2 s .com return; } for (int i = 0; i < spellInfo.size(); i++) { String n = spellInfo.getName(i); if ("correctlySpelled".equals(n)) { correctlySpelled = (Boolean) spellInfo.getVal(i); } else if ("collationInternalRank".equals(n)) { //continue; } else if ("collations".equals(n)) { List<Object> collationInfo = spellInfo.getAll(n); collations = new ArrayList<>(collationInfo.size()); for (Object o : collationInfo) { if (o instanceof String) { collations.add(new Collation().setCollationQueryString((String) o)); } else if (o instanceof NamedList) { @SuppressWarnings("unchecked") NamedList<Object> expandedCollation = (NamedList<Object>) o; String collationQuery = (String) expandedCollation.get("collationQuery"); int hits = (Integer) expandedCollation.get("hits"); @SuppressWarnings("unchecked") NamedList<String> misspellingsAndCorrections = (NamedList<String>) expandedCollation .get("misspellingsAndCorrections"); Collation collation = new Collation(); collation.setCollationQueryString(collationQuery); collation.setNumberOfHits(hits); for (int ii = 0; ii < misspellingsAndCorrections.size(); ii++) { String misspelling = misspellingsAndCorrections.getName(ii); String correction = misspellingsAndCorrections.getVal(ii); collation.addMisspellingsAndCorrection(new Correction(misspelling, correction)); } collations.add(collation); } else { throw new AssertionError("Should get Lists of Strings or List of NamedLists here."); } } } else { @SuppressWarnings("unchecked") Suggestion s = new Suggestion(n, (NamedList<Object>) spellInfo.getVal(i)); suggestionMap.put(n, s); suggestions.add(s); } } }
From source file:com.searchbox.SuggesterComponent.java
License:Apache License
@Override // standard loading of options from config file, discussed in documentation public void init(NamedList args) { LOGGER.debug(("Hit init")); super.init(args); this.initParams = args; buildOnOptimize = Boolean.parseBoolean((String) args.get(SuggesterComponentParams.BUILD_ON_OPTIMIZE)); if (buildOnOptimize == null) { buildOnOptimize = Boolean.parseBoolean(SuggesterComponentParams.BUILD_ON_OPTIMIZE_DEFAULT); }// ww w. jav a 2 s. c o m buildOnCommit = Boolean.parseBoolean((String) args.get(SuggesterComponentParams.BUILD_ON_COMMIT)); if (buildOnCommit == null) { buildOnCommit = Boolean.parseBoolean(SuggesterComponentParams.BUILD_ON_COMMIT_DEFAULT); } storeDirname = (String) args.get(SuggesterComponentParams.STOREDIR); if (storeDirname == null) { storeDirname = SuggesterComponentParams.STOREDIR_DEFAULT; } stopWordFile = (String) args.get(SuggesterComponentParams.STOP_WORD_LOCATION); if (stopWordFile == null) { stopWordFile = SuggesterComponentParams.STOP_WORD_LOCATION_DEFAULT; } nonpruneFileName = (String) args.get(SuggesterComponentParams.NONPRUNEFILE); ngrams = (Integer) args.get(SuggesterComponentParams.NGRAMS); if (ngrams == null) { ngrams = Integer.parseInt(SuggesterComponentParams.NGRAMS_DEFAULT); } minDocFreq = (Integer) args.get(SuggesterComponentParams.MINDOCFREQ); if (minDocFreq == null) { minDocFreq = SuggesterComponentParams.MINDOCFREQ_DEFAULT; } minTermFreq = (Integer) args.get(SuggesterComponentParams.MINTERMFREQ); if (minTermFreq == null) { minTermFreq = SuggesterComponentParams.MINTERMFREQ_DEFAULT; } maxNumDocs = (Integer) args.get(SuggesterComponentParams.MAXNUMDOCS); if (maxNumDocs == null) { maxNumDocs = SuggesterComponentParams.MAXNUMDOCS_DEFAULT; } NamedList fields = ((NamedList) args.get(SuggesterComponentParams.FIELDS)); if (fields == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Need to specify at least one field"); } gfields = (String[]) fields.getAll(SuggesterComponentParams.FIELD).toArray(new String[0]); if (gfields == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Need to specify at least one field"); } LOGGER.debug("maxNumDocs is " + maxNumDocs); LOGGER.debug("minDocFreq is " + minDocFreq); LOGGER.debug("minTermFreq is " + minTermFreq); LOGGER.debug("buildOnCommit is " + buildOnCommit); LOGGER.debug("buildOnOptimize is " + buildOnOptimize); LOGGER.debug("storeDirname is " + storeDirname); LOGGER.debug("Ngrams is " + ngrams); LOGGER.debug("Fields is " + gfields); LOGGER.debug("Nonprune file is " + nonpruneFileName); }
From source file:com.searchbox.TaggerComponent.java
License:Apache License
@Override public void init(NamedList args) { LOGGER.debug(("Hit init")); super.init(args); this.initParams = args; buildOnOptimize = Boolean.parseBoolean((String) args.get(TaggerComponentParams.BUILD_ON_OPTIMIZE)); if (buildOnOptimize == null) { buildOnOptimize = Boolean.parseBoolean(TaggerComponentParams.BUILD_ON_OPTIMIZE_DEFAULT); }// www .ja v a2s .c om buildOnCommit = Boolean.parseBoolean((String) args.get(TaggerComponentParams.BUILD_ON_COMMIT)); if (buildOnCommit == null) { buildOnCommit = Boolean.parseBoolean(TaggerComponentParams.BUILD_ON_COMMIT_DEFAULT); } storeDirname = (String) args.get(TaggerComponentParams.STOREDIR); if (storeDirname == null) { storeDirname = TaggerComponentParams.STOREDIR_DEFAULT; } minDocFreq = (Integer) args.get(TaggerComponentParams.MINDOCFREQ); if (minDocFreq == null) { minDocFreq = TaggerComponentParams.MINDOCFREQ_DEFAULT; } minTermFreq = (Integer) args.get(TaggerComponentParams.MINTERMFREQ); if (minTermFreq == null) { minTermFreq = TaggerComponentParams.MINTERMFREQ_DEFAULT; } maxNumDocs = (Integer) args.get(TaggerComponentParams.MAXNUMDOCS); if (maxNumDocs == null) { maxNumDocs = TaggerComponentParams.MAXNUMDOCS_DEFAULT; } NamedList fields = ((NamedList) args.get(TaggerComponentParams.QUERY_FIELDS)); if (fields == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Need to specify at least one field"); } gfields = (String[]) fields.getAll(TaggerComponentParams.QUERY_FIELD).toArray(new String[0]); if (gfields == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Need to specify at least one field"); } boostsFileName = (String) args.get(TaggerComponentParams.BOOSTS_FILENAME); LOGGER.debug("maxNumDocs is " + maxNumDocs); LOGGER.debug("minDocFreq is " + minDocFreq); LOGGER.debug("buildOnCommit is " + buildOnCommit); LOGGER.debug("buildOnOptimize is " + buildOnOptimize); LOGGER.debug("storeDirname is " + storeDirname); LOGGER.debug("Fields is " + gfields); LOGGER.debug("Boosts file is " + boostsFileName); }
From source file:com.sindicetech.siren.solr.facet.SirenFacetProcessorFactory.java
License:Open Source License
/** * //from w ww .j a v a 2 s. c o m * Taken from {@link AddSchemaFieldsUpdateProcessorFactory}'s parseTypeMappings(). * * @param args * @return */ @SuppressWarnings("rawtypes") private List<TypeMapping> parseTypeMappings(NamedList args) { List<TypeMapping> typeMappings = new ArrayList<TypeMapping>(); List typeMappingsParams = args.getAll(TYPE_MAPPING_PARAM); for (Object typeMappingObj : typeMappingsParams) { if (null == typeMappingObj) { throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param cannot be null"); } if (!(typeMappingObj instanceof NamedList)) { throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param must be a <lst>"); } NamedList typeMappingNamedList = (NamedList) typeMappingObj; Object fieldTypeObj = typeMappingNamedList.remove(FIELD_TYPE_PARAM); if (null == fieldTypeObj) { throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain a '" + FIELD_TYPE_PARAM + "' <str>"); } if (!(fieldTypeObj instanceof CharSequence)) { throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' init param must be a <str>"); } if (null != typeMappingNamedList.get(FIELD_TYPE_PARAM)) { throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM + "' <lst/> may contain only one '" + FIELD_TYPE_PARAM + "' <str>"); } String fieldType = fieldTypeObj.toString(); Object maxFieldSizeObj = typeMappingNamedList.remove(MAX_FIELD_SIZE_PARAM); if (maxFieldSizeObj != null) { if (!(maxFieldSizeObj instanceof Integer)) { throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' init param must be an <int>"); } } Collection<String> valueClasses = typeMappingNamedList.removeConfigArgs(VALUE_CLASS_PARAM); if (valueClasses.isEmpty()) { throw new SolrException(SERVER_ERROR, "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain at least one '" + VALUE_CLASS_PARAM + "' <str>"); } typeMappings.add(new TypeMapping(fieldType, (Integer) maxFieldSizeObj, valueClasses)); if (0 != typeMappingNamedList.size()) { throw new SolrException(SERVER_ERROR, "Unexpected '" + TYPE_MAPPING_PARAM + "' init sub-param(s): '" + typeMappingNamedList.toString() + "'"); } args.remove(TYPE_MAPPING_PARAM); } checkMappingExists(typeMappings, FacetDatatype.BOOLEAN.xsdDatatype); checkMappingExists(typeMappings, FacetDatatype.DOUBLE.xsdDatatype); checkMappingExists(typeMappings, FacetDatatype.LONG.xsdDatatype); checkMappingExists(typeMappings, FacetDatatype.STRING.xsdDatatype); return typeMappings; }
From source file:com.sindicetech.siren.solr.handler.SirenUpdateRequestHandler.java
License:Open Source License
private List<FieldMapper> parseMappings(NamedList args, String paramName) { List<FieldMapper> mappers = new ArrayList<>(); List params = args.getAll(paramName); if (!params.isEmpty()) { for (Object mapping : params) { NamedList mappingNamedList = this.validateParameter(paramName, mapping); String fieldType = this.parseFieldTypeParameter(mappingNamedList); String path = this.parseStringParameter(mappingNamedList, PATH_PARAM); String type = this.parseStringParameter(mappingNamedList, TYPE_PARAM); if ((path == null && type == null) || (path != null && type != null)) { throw new SolrException(SERVER_ERROR, "Each mapping must contain either a '" + PATH_PARAM + "' or a '" + TYPE_PARAM + "' sub-parameter"); }/*from ww w . j a va 2s .co m*/ if (mappingNamedList.size() != 0) { throw new SolrException(SERVER_ERROR, "Unexpected '" + paramName + "' sub-parameter(s): '" + mappingNamedList.toString() + "'"); } if (path == null) { mappers.add(new TypeFieldMapper(type, fieldType)); } else { mappers.add(new PathFieldMapper(path, fieldType)); } } args.remove(paramName); } return mappers; }
From source file:com.sindicetech.siren.solr.handler.SirenUpdateRequestHandler.java
License:Open Source License
private FieldMapper parseDefaultMapping(NamedList args) { List defaultParams = args.getAll(DEFAULT_PARAM); if (defaultParams.size() > 1) { throw new SolrException(SERVER_ERROR, "Only one '" + DEFAULT_PARAM + "' mapping is allowed"); }//ww w.ja va 2 s. c o m FieldMapper mapper = null; if (!defaultParams.isEmpty()) { NamedList defaultMappingNamedList = this.validateParameter(DEFAULT_PARAM, defaultParams.get(0)); String fieldType = this.parseFieldTypeParameter(defaultMappingNamedList); mapper = new DefaultFieldMapper(fieldType); args.remove(DEFAULT_PARAM); } return mapper; }
From source file:com.sindicetech.siren.solr.handler.SirenUpdateRequestHandler.java
License:Open Source License
private FieldMapper parseJsonMapping(NamedList args) { List jsonParams = args.getAll(JSON_PARAM); if (jsonParams.size() > 1) { throw new SolrException(SERVER_ERROR, "Only one '" + JSON_PARAM + "' mapping is allowed"); }//w ww . j ava 2 s . co m FieldMapper mapper = null; if (!jsonParams.isEmpty()) { NamedList jsonMappingNamedList = this.validateParameter(JSON_PARAM, jsonParams.get(0)); String fieldType = this.parseFieldTypeParameter(jsonMappingNamedList); mapper = new JsonFieldMapper(fieldType); args.remove(JSON_PARAM); } return mapper; }
From source file:org.alfresco.solr.AlfrescoSolrUtils.java
License:Open Source License
/** * Creates a core using the specified template * @param coreContainer//from ww w . java 2s .c om * @param coreAdminHandler * @param coreName * @param templateName * @param shards * @param nodes * @param extraParams Any number of additional parameters in name value pairs. * @return * @throws InterruptedException */ public static SolrCore createCoreUsingTemplate(CoreContainer coreContainer, AlfrescoCoreAdminHandler coreAdminHandler, String coreName, String templateName, int shards, int nodes, String... extraParams) throws InterruptedException { SolrCore testingCore = null; ModifiableSolrParams coreParams = params(CoreAdminParams.ACTION, "newcore", "storeRef", "workspace://SpacesStore", "coreName", coreName, "numShards", String.valueOf(shards), "nodeInstance", String.valueOf(nodes), "template", templateName); coreParams.add(params(extraParams)); SolrQueryRequest request = new LocalSolrQueryRequest(null, coreParams); SolrQueryResponse response = new SolrQueryResponse(); coreAdminHandler.handleCustomAction(request, response); TimeUnit.SECONDS.sleep(1); if (shards > 1) { NamedList vals = response.getValues(); List<String> coreNames = vals.getAll("core"); assertEquals(shards, coreNames.size()); testingCore = getCore(coreContainer, coreNames.get(0)); } else { assertEquals(coreName, response.getValues().get("core")); //Get a reference to the new core testingCore = getCore(coreContainer, coreName); } TimeUnit.SECONDS.sleep(4); //Wait a little for background threads to catchup assertNotNull(testingCore); return testingCore; }
From source file:org.apache.lucene.queryparser.classic.PreAnalyzedQueryParser.java
License:Apache License
/*** * Main entry that parses the "q" parameter value from every query, * overwrites the parse method from the Solr Query Class. * //from ww w.ja v a 2s . co m */ @Override public Query parse() throws SyntaxError { // Get list of params from request NamedList<Object> requestParams = this.params.toNamedList(); // Getting q param value from request String qryJO = requestParams.get("q").toString(); String finalQry = ""; if (requestParams.get("queryProcessing") == null) { // Get debug parameter from request Boolean debugQuery = Boolean.valueOf(params.get("debugQuery")); if (debugQuery == null) { debugQuery = false; } // Get lemma exp global param Boolean lemmaExp = Boolean.valueOf(params.get("lemma")); if (lemmaExp == null) { lemmaExp = false; } // Get synonym exp global param Boolean synExp = Boolean.valueOf(params.get("syn")); if (synExp == null) { synExp = false; } // Get accent removal global param Boolean accRem = Boolean.valueOf(params.get("accRem")); if (accRem == null) { accRem = false; } // Get language for the query terms, default to english String lang = params.get("language"); if (lang == null) { lang = "en"; } // Special param for lemmatizer testing Boolean showLemmas = params.getBool("showLemmas"); // Store debug messages String debugMessage = "<![CDATA["; String[] transOut = new String[2]; if (!qryJO.equals("*:*")) { // validates all docs wildcard query transOut = transformParamValue(qryJO, debugQuery, lang, synExp, lemmaExp, accRem); finalQry = transOut[0]; } else { // all docs wildcard query scenario finalQry = "*:*"; } // Print final transformed query if (debugQuery) { debugMessage += transOut[1]; debugMessage += "After PreAnalyzed transformation->" + finalQry + "]]>"; System.out.println(debugMessage); } // Get fq params from request List<Object> allFQs = requestParams.getAll("fq"); requestParams.removeAll("fq"); // Iterate over all fq params and apply transformations (tokenization, lemmatization, JSON format) for (Object fqValue : allFQs) { if (fqValue instanceof String[]) { for (String val : (String[]) fqValue) { String newFQ = transformParamValue(val, false, lang, synExp, lemmaExp, accRem)[0]; requestParams.add("fq", newFQ); } } else { String newFQ = transformParamValue(fqValue.toString(), false, lang, synExp, lemmaExp, accRem)[0]; requestParams.add("fq", newFQ); } } if (debugQuery) { requestParams.add("queryParserDebugProcess", debugMessage); } requestParams.add("queryProcessing", "True"); requestParams.remove("q"); requestParams.add("q", finalQry); this.req.setParams(SolrParams.toSolrParams(requestParams)); } else { finalQry = requestParams.get("q").toString(); } // Redirect the transform query to Solr Query Class QueryParser qp = new QueryParser(schema.getDefaultLuceneMatchVersion(), params.get("df"), this); Query qry = qp.parse(finalQry); return qry; }