/** * Merge a {@code SolrInputDocument} into the master document, adding a prefix to every field name as it is added. * * @param inputDocument document to be added * @param prefix prefix to be added to field names */ public void add(SolrInputDocument inputDocument, String prefix) { for (Entry<String, SolrInputField> entry : inputDocument.entrySet()) { SolrInputField inputField = entry.getValue(); document.addField(prefix + entry.getKey(), inputField.getValues(), inputField.getBoost()); } }
public void add(SolrInputField field) { if (field != null) { // Overwrite the 'id' field if (field.getName().equals(IdFieldMapper.INPUT_FIELD)) { doc.setField(field.getName(), field.getValue(), field.getBoost()); } // Append other fields else { doc.addField(field.getName(), field.getValue(), field.getBoost()); } } }
public static void writeXML( SolrInputDocument doc, Writer writer ) throws IOException { writer.write("<doc boost=\""+doc.getDocumentBoost()+"\">"); for( SolrInputField field : doc ) { float boost = field.getBoost(); String name = field.getName(); for( Object v : field ) { if (v instanceof Date) { v = DateUtil.getThreadLocalDateFormat().format( (Date)v ); }else if (v instanceof byte[]) { byte[] bytes = (byte[]) v; v = Base64.byteArrayToBase64(bytes, 0,bytes.length); } else if (v instanceof ByteBuffer) { ByteBuffer bytes = (ByteBuffer) v; v = Base64.byteArrayToBase64(bytes.array(), bytes.position(),bytes.limit() - bytes.position()); } if( boost != 1.0f ) { XML.writeXML(writer, "field", v.toString(), "name", name, "boost", boost ); } else if (v != null) { XML.writeXML(writer, "field", v.toString(), "name", name ); } // only write the boost for the first multi-valued field // otherwise, the used boost is the product of all the boost values boost = 1.0f; } } writer.write("</doc>"); }
private List<NamedList> solrInputDocumentToList(SolrInputDocument doc) { List<NamedList> l = new ArrayList<NamedList>(); NamedList nl = new NamedList(); nl.add("boost", doc.getDocumentBoost() == 1.0f ? null : doc.getDocumentBoost()); l.add(nl); Iterator<SolrInputField> it = doc.iterator(); while (it.hasNext()) { nl = new NamedList(); SolrInputField field = it.next(); nl.add("name", field.getName()); nl.add("val", field.getValue()); nl.add("boost", field.getBoost() == 1.0f ? null : field.getBoost()); l.add(nl); } return l; }
float boost = field.getBoost(); String name = field.getName();
outputField.setBoost(inputField.getBoost());
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException { List<SolrInputDocument> children = sdoc.getChildDocuments(); int sz = sdoc.size() + (children==null ? 0 : children.size()); writeTag(SOLRINPUTDOC, sz); writeFloat(sdoc.getDocumentBoost()); for (SolrInputField inputField : sdoc.values()) { if (inputField.getBoost() != 1.0f) { writeFloat(inputField.getBoost()); } writeExternString(inputField.getName()); writeVal(inputField.getValue()); } if (children != null) { for (SolrInputDocument child : children) { writeSolrInputDocument(child); } } }
SchemaField sfield = schema.getFieldOrNull(name); boolean used = false; float boost = field.getBoost();