List of usage examples for org.apache.solr.common.util NamedList getVal
@SuppressWarnings("unchecked") public T getVal(int idx)
From source file:alba.solr.core.Loader.java
License:Apache License
@Override public void init() { requestHandlers = new HashMap<String, AlbaRequestHandler>(); searchComponents = new HashMap<String, CallableFunction>(); functions = new HashMap<String, CallableFunction>(); postFilters = new HashMap<String, CallableFunction>(); pseudoFields = new HashMap<String, SolrPseudoField>(); dynamicFunctions = new HashMap<String, DocValuesDynamicValueSource>(); packageScanner = new PackageScanner(); cachedResults = new HashMap<Object, CachedResult>(); docTransformers = new HashMap<String, CallableFunction>(); responseWriters = new HashMap<String, AlbaResponseWriter>(); NamedList l = this.getInitParams(); NamedList<String> packagesToScan = (NamedList<String>) this.getInitParams().get("packagesToScan"); String packageName = ""; for (int i = 0; i < packagesToScan.size(); i++) { packageName = packagesToScan.getVal(i); //loadPlugins(packageName); loadPlugins2(packageName);//ww w . jav a 2s. c o m } }
From source file:co.diji.solr.XMLWriter.java
License:Apache License
public void writeNamedList(String name, NamedList val) throws IOException { int sz = val.size(); startTag("lst", name, sz <= 0); for (int i = 0; i < sz; i++) { writeVal(val.getName(i), val.getVal(i)); }/*from w ww. jav a 2 s . c o m*/ if (sz > 0) { writer.write("</lst>"); } }
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;/*from ww w . j av a 2 s. c om*/ 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.doculibre.constellio.services.AutocompleteServicesImpl.java
License:Open Source License
@SuppressWarnings("unchecked") static private NamedList<Object> suggest(String q, String fieldName, SolrServer server, Boolean isStringField) { NamedList<Object> returnList = new NamedList<Object>(); // escape special characters SolrQuery query = new SolrQuery(); /*/* w w w. ja va2 s . c om*/ * // * Set terms.lower to the input term * query.setParam(TermsParams.TERMS_LOWER, q); // * Set terms.prefix to * the input term query.setParam(TermsParams.TERMS_PREFIX, q); // * Set * terms.lower.incl to false * query.setParam(TermsParams.TERMS_LOWER_INCLUSIVE, "false"); // * Set * terms.fl to the name of the source field * query.setParam(TermsParams.TERMS_FIELD, fieldName); */ query.setParam(TermsParams.TERMS_FIELD, fieldName);// query.addTermsField("spell"); query.setParam(TermsParams.TERMS_LIMIT, TERMS_LIMIT);// query.setTermsLimit(MAX_TERMS); query.setParam(TermsParams.TERMS, "true");// query.setTerms(true); query.setParam(TermsParams.TERMS_LOWER, q);// query.setTermsLower(q); query.setParam(TermsParams.TERMS_PREFIX, q);// query.setTermsPrefix(q); query.setParam(TermsParams.TERMS_MINCOUNT, TERMS_MINCOUNT); query.setRequestHandler(SolrServices.AUTOCOMPLETE_QUERY_NAME); try { QueryResponse qr = server.query(query); NamedList<Object> values = qr.getResponse(); NamedList<Object> terms = (NamedList<Object>) values.get("terms");// TermsResponse // resp // = // qr.getTermsResponse(); NamedList<Object> suggestions = (NamedList<Object>) terms.get(fieldName);// items // = // resp.getTerms("spell"); if (!isStringField) { q = AnalyzerUtils.analyzePhrase(q, false); } for (int i = 0; i < suggestions.size(); i++) { String currentSuggestion = suggestions.getName(i); // System.out.println(currentSuggestion); if (isStringField) { if (currentSuggestion.contains(q)) { // String suffix = // StringUtils.substringAfter(currentSuggestion, q); // if (suffix.isEmpty() && // !currentSuggestion.equals(q)){ // //q n est pas dans currentSuggestion // break; // } if (currentSuggestion.contains(SPECIAL_CHAR)) { // le resultat de recherche retourne des fois une // partie de la valeur existant // dans le champ! currentSuggestion = StringUtils.substringAfter(currentSuggestion, SPECIAL_CHAR); } returnList.add(currentSuggestion, suggestions.getVal(i)); } } else { currentSuggestion = AnalyzerUtils.analyzePhrase(currentSuggestion, false); if (currentSuggestion.contains(q)) { returnList.add(currentSuggestion, suggestions.getVal(i)); } } } } catch (SolrServerException e) { throw new RuntimeException(e); } return returnList; }
From source file:com.doculibre.constellio.services.AutocompleteServicesImpl.java
License:Open Source License
private static void print(String q, NamedList<Object> suggestions) { System.out.println("########### " + q + " ##############"); for (int i = 0; i < suggestions.size(); i++) { System.out.println(suggestions.getName(i) + "\t" + suggestions.getVal(i)); }// w w w .ja v a2 s. com }
From source file:com.github.fengtan.sophie.tables.CoresTable.java
License:Open Source License
/** * Recursively convert a hierarchical NamedList into a linear Map. * //from w w w. j a v a 2 s . c o m * @param namedList * Hierarchical NamedList. * @param map * Map to be populated. * @return Linear Map populated with values in the NamedList. */ private Map<String, String> linearizeNamedList(NamedList<?> namedList, Map<String, String> map) { // Inspect all elements in the NamedList. for (int idx = 0; idx < namedList.size(); idx++) { Object object = namedList.getVal(idx); if (object instanceof NamedList) { // Element is a NamedList: populate the map recursively. linearizeNamedList((NamedList<?>) object, map); } else { // Element is not a NamedList: add it to the map. String name = namedList.getName(idx); map.put(name, object.toString()); // Create column if it does not exist yet. if (!hasColumn(name)) { addColumn(name); } } } // Return populated map. return map; }
From source file:com.ifactory.press.db.solr.processor.FieldMergingProcessorFactory.java
License:Apache License
private void doInit() { Object o = initArgs.get("destinationField"); if (o == null || !(o instanceof String)) { log.error("destinationField must be present as a string, got " + o); return;/*from www .j a va2 s .c om*/ } destinationField = (String) o; FieldType destinationFieldType = schema.getFieldType(destinationField); if (destinationFieldType == null) { log.error("deistinationField is not defined in the schema: it has no schema type"); return; } o = initArgs.get("sourceField"); if (o == null || !(o instanceof NamedList)) { log.error("sourceField must be present as a list, got " + o); return; } NamedList<?> sourceFields = (NamedList<?>) o; if (sourceFields.size() == 0) { log.error("destinationField must not be empty"); } sourceAnalyzers = new HashMap<String, Analyzer>(); for (int i = 0; i < sourceFields.size(); i++) { String sourceFieldName = sourceFields.getName(i); o = sourceFields.getVal(i); FieldType fieldType; if (o instanceof String && !((String) o).isEmpty()) { String analysisFieldName = (String) o; fieldType = schema.getFieldTypeByName(analysisFieldName); if (fieldType == null) { log.error("No such field type: " + analysisFieldName); } } else { fieldType = schema.getFieldType(sourceFieldName); if (fieldType == null) { log.error("No field type for field: " + sourceFieldName); } } if (fieldType != null) { sourceAnalyzers.put(sourceFieldName, fieldType.getIndexAnalyzer()); } } }
From source file:com.nridge.ds.solr.SolrResponseBuilder.java
License:Open Source License
private void populateMoreLikeThis(QueryResponse aQueryResponse) { String docName;//www . j a v a2 s. c o m Document mltDocument; DataField docNameField; SolrDocumentList solrDocumentList; Logger appLogger = mAppMgr.getLogger(this, "populateMoreLikeThis"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); NamedList<SolrDocumentList> mltDocuments = aQueryResponse.getMoreLikeThis(); if (mltDocuments != null) { mDocument.addRelationship(Solr.RESPONSE_MORE_LIKE_THIS, createMLTBag()); Relationship mltRelationship = mDocument.getFirstRelationship(Solr.RESPONSE_MORE_LIKE_THIS); if (mltRelationship != null) { int mltCount = mltDocuments.size(); DataBag mltBag = mltRelationship.getBag(); docNameField = mltBag.getFieldByName("mlt_name"); mltBag.setValueByName("mlt_total", mltCount); for (int i = 0; i < mltCount; i++) { docName = mltDocuments.getName(i); docNameField.addValue(docName); solrDocumentList = mltDocuments.getVal(i); if (solrDocumentList.getNumFound() > 0L) { mltDocument = new Document(Solr.RESPONSE_MLT_DOCUMENT, createDocumentTable()); populateDocument(mltDocument, solrDocumentList); mltRelationship.add(mltDocument); } } } } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.pjaol.ESB.formatters.JSONFormatter.java
License:Apache License
private String iterateNamedList(NamedList output) { JSONObject jo = new JSONObject(); int sz = output.size(); for (int i = 0; i < sz; i++) { String k = output.getName(i); Object v = output.getVal(i); if (v instanceof NamedList) { jo.put(k, recurseNamedList((NamedList) v)); } else {// ww w .ja v a 2 s .c o m jo.put(k, v); } } return jo.toJSONString(); }
From source file:com.pjaol.ESB.formatters.JSONFormatter.java
License:Apache License
private JSONArray recurseNamedList(NamedList output) { int sz = output.size(); JSONArray jarr = new JSONArray(); for (int i = 0; i < sz; i++) { JSONObject jo = new JSONObject(); String k = output.getName(i); Object v = output.getVal(i); if (v instanceof NamedList) { jo.put(k, recurseNamedList((NamedList) v)); } else if (v instanceof Map) { jo.put(k, recurseMap((Map) v)); } else {// w ww . j av a2s. co m jo.put(k, v); } jarr.add(jo); } return jarr; }