List of usage examples for org.apache.solr.common SolrDocument keySet
@Override
public Set<String> keySet()
From source file:com.cloudera.cdk.morphline.solr.AbstractSolrMorphlineZkTest.java
License:Apache License
private Record toRecord(SolrDocument doc) { Record record = new Record(); for (String key : doc.keySet()) { record.getFields().replaceValues(key, doc.getFieldValues(key)); }//from ww w . ja v a 2s .c om return record; }
From source file:com.googlecode.solrgeonames.server.HtmlDetailResponse.java
License:Open Source License
private String renderRow(SolrDocument doc) { String output = "<p>"; for (String key : doc.keySet()) { Object object = doc.getFieldValue(key); String value = null;/* www . ja v a 2s . co m*/ if (object instanceof String) { value = (String) doc.getFieldValue(key); } if (object instanceof Integer) { value = String.valueOf((Integer) doc.getFieldValue(key)); } if (object instanceof Float) { value = String.valueOf((Float) doc.getFieldValue(key)); } if (object instanceof Long) { value = String.valueOf((Long) doc.getFieldValue(key)); } if (object instanceof Date) { value = ((Date) object).toString(); } if (object instanceof List) { List<String> multiValue = (ArrayList<String>) object; StringBuffer sb = new StringBuffer(); for (Iterator iterator = multiValue.iterator(); iterator.hasNext();) { String string = (String) iterator.next(); sb.append(string); if (iterator.hasNext()) { sb.append(", "); } } value = sb.toString(); } output += "<b>" + StringEscapeUtils.escapeHtml(key) + "</b>: " + StringEscapeUtils.escapeHtml(value) + "<br/>"; } output += "</p>"; return output; }
From source file:com.googlecode.solrgeonames.server.JsonDetailResponse.java
License:Open Source License
/** * Render a single 'row' from the result set * * @param doc: The Solr document to render * @return String: The rendered document in JSON *//*from w w w . j a v a 2 s.com*/ private String renderRow(SolrDocument doc) { String output = ""; for (String key : doc.keySet()) { // Make sure our commas are correct if (!output.equals("")) { output += ",\n"; } Object object = doc.getFieldValue(key); String value = null; if (object instanceof String) { value = (String) doc.getFieldValue(key); } if (object instanceof Integer) { value = String.valueOf((Integer) doc.getFieldValue(key)); } if (object instanceof Float) { value = String.valueOf((Float) doc.getFieldValue(key)); } if (object instanceof Long) { value = String.valueOf((Long) doc.getFieldValue(key)); } if (object instanceof Date) { value = ((Date) object).toString(); } if (object instanceof List) { List<String> multiValue = (ArrayList<String>) object; StringBuffer sb = new StringBuffer(); for (Iterator iterator = multiValue.iterator(); iterator.hasNext();) { String string = (String) iterator.next(); sb.append(string); if (iterator.hasNext()) { sb.append(", "); } } value = sb.toString(); } key = StringEscapeUtils.escapeJavaScript(key); value = StringEscapeUtils.escapeJavaScript(value); output += "\"" + key + "\": \"" + value + "\""; } return "{\n" + output + "\n}"; }
From source file:com.googlecode.solrgeonames.server.JsonSearchResponse.java
License:Open Source License
/** * Render a single 'row' from the result set * * @param doc: The Solr document to render * @return String: The rendered document in JSON */// ww w. ja va2 s. c om private String renderRow(SolrDocument doc) { String output = ""; for (String key : doc.keySet()) { // Make sure our commas are correct if (!output.equals("")) { output += ",\n"; } Object object = doc.getFieldValue(key); String value = null; if (object instanceof String) { value = (String) doc.getFieldValue(key); } if (object instanceof Integer) { value = String.valueOf((Integer) doc.getFieldValue(key)); } if (object instanceof Float) { value = String.valueOf((Float) doc.getFieldValue(key)); } if (object instanceof Long) { value = String.valueOf((Long) doc.getFieldValue(key)); } if (object instanceof Date) { value = ((Date) object).toString(); } if (object instanceof List) { List<String> multiValue = (ArrayList<String>) object; StringBuffer sb = new StringBuffer(); for (Iterator iterator = multiValue.iterator(); iterator.hasNext();) { String string = (String) iterator.next(); sb.append(string); if (iterator.hasNext()) { sb.append(", "); } } value = sb.toString(); } output += escape(key, value); // When we come across the ID, add in a Geonames URI if (key.equals("id")) { output += ",\n" + escape("geonames_uri", "http://sws.geonames.org/" + value + "/"); } } // Display string String name = (String) doc.getFieldValue("basic_name"); String country = (String) doc.getFieldValue("country_code"); String timezone = (String) doc.getFieldValue("timezone"); String display = name + ", " + country + " (" + timezone + ")"; output += ",\n" + escape("display", display); return "{\n" + output + "\n}"; }
From source file:de.dlr.knowledgefinder.webapp.webservice.exporter.BibTeXExporter.java
License:Apache License
private BibTeXEntry convertData(SolrDocument doc) { String type = (String) doc.getFieldValue("resourceType"); type = types.containsKey(type) ? types.get(type) : "misc"; String id = (String) doc.getFieldValue("id"); BibTeXEntry entry = new BibTeXEntry(new Key(type), new Key(id)); Set<String> fields = doc.keySet(); Iterator<String> itr = fields.iterator(); while (itr.hasNext()) { String field = itr.next(); Object value = doc.get(field); String stringValue = ""; if (value.getClass().equals(ArrayList.class)) { for (Object o : (ArrayList<Object>) value) { if (tags.get(field).equals("Author")) { stringValue = formatAuthorText(String.valueOf(o)); } else { stringValue += String.valueOf(o); }/*from w ww . j a va2s.co m*/ } } else if (value.getClass().equals(Date.class)) { DateFormat df; if (tags.get(field).equals("Year")) df = new SimpleDateFormat("yyyy"); else df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); stringValue = df.format((Date) value); } else { stringValue = (String) value; } if (tags.containsKey(field)) { entry.addField(new Key(tags.get(field)), new StringValue(stringValue, StringValue.Style.BRACED)); } } return entry; }