public Map<String,Object> toObject(IndexSchema schema) { Map<String,Object> result = new HashMap<>(); for (Fld fld : fields) { SchemaField sf = schema.getField(fld.ftype.fname); if (!sf.multiValued()) { result.put(fld.ftype.fname, fld.vals.get(0)); } else { result.put(fld.ftype.fname, fld.vals); } } return result; }
public static Map<String,Object> toObject(Doc doc, IndexSchema schema, Collection<String> fieldNames) { Map<String,Object> result = new HashMap<>(); for (Fld fld : doc.fields) { if (fieldNames != null && !fieldNames.contains(fld.ftype.fname)) continue; SchemaField sf = schema.getField(fld.ftype.fname); if (!sf.multiValued()) { result.put(fld.ftype.fname, fld.vals.get(0)); } else { result.put(fld.ftype.fname, fld.vals); } } return result; }
/** * Method that checks if proper field collapsing is actually possible with the current collapse field. * If the collapse field does not meet the proper requirements a runtime exception is thrown. * A runtime exception is thrown under the following circumstances: * <ul> * <li> When the collapse field does not exists in the schema * <li> When the collapse field is multivalued in the schema * <li> When the collapse field is tokenized in the schema * </ul> * * For example when a field is tokenized, only the last token of the field can be retrieved from the fieldcache. This * results in field collapsing only on the last token of a field value instead of the complete field value. * * When the field values from a multivalued field are returned from the <code>FieldCache</code> then an exception may * be thrown. This happens when there are more terms in a field than documents. * * @param schema The index schema */ protected void checkCollapseField(IndexSchema schema) { SchemaField schemaField = schema.getFieldOrNull(collapseField); if (schemaField == null) { throw new RuntimeException("Could not collapse, because collapse field does not exist in the schema."); } if (schemaField.multiValued()) { throw new RuntimeException("Could not collapse, because collapse field is multivalued"); } if (schemaField.getType().isTokenized()) { throw new RuntimeException("Could not collapse, because collapse field is tokenized"); } }
if ((xlField.sf != null && xlField.sf.multiValued()) || nVals > 1) { Collection values;
protected void addSingleField(SchemaField sfield, String val, float boost) { //System.out.println("###################ADDING FIELD "+sfield+"="+val); // we don't check for a null val ourselves because a solr.FieldType // might actually want to map it to something. If createField() // returns null, then we don't store the field. Field field = sfield.createField(val, boost); if (field != null) { if (!sfield.multiValued()) { String oldValue = map.put(sfield.getName(), val); if (oldValue != null) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR: multiple values encountered for non multiValued field " + sfield.getName() + ": first='" + oldValue + "' second='" + val + "'"); } } // field.setBoost(boost); doc.add(field); } }
if (sf != null && !sf.multiValued() && vals != null) { StringBuilder builder = new StringBuilder(); boolean first=true;
if (sf != null && !sf.multiValued() && vals != null) { StringBuilder builder = new StringBuilder(); boolean first=true;
/** * @return a string representing a SchemaField's flags. */ private static String getFieldFlags( SchemaField f ) { FieldType t = (f==null) ? null : f.getType(); // see: http://www.nabble.com/schema-field-properties-tf3437753.html#a9585549 boolean lazy = false; // "lazy" is purely a property of reading fields boolean binary = false; // Currently not possible StringBuilder flags = new StringBuilder(); flags.append( (f != null && f.indexed()) ? FieldFlag.INDEXED.getAbbreviation() : '-' ); flags.append( (t != null && t.isTokenized()) ? FieldFlag.TOKENIZED.getAbbreviation() : '-' ); flags.append( (f != null && f.stored()) ? FieldFlag.STORED.getAbbreviation() : '-' ); flags.append( (f != null && f.multiValued()) ? FieldFlag.MULTI_VALUED.getAbbreviation() : '-' ); flags.append( (f != null && f.storeTermVector() ) ? FieldFlag.TERM_VECTOR_STORED.getAbbreviation() : '-' ); flags.append( (f != null && f.storeTermOffsets() ) ? FieldFlag.TERM_VECTOR_OFFSET.getAbbreviation() : '-' ); flags.append( (f != null && f.storeTermPositions() ) ? FieldFlag.TERM_VECTOR_POSITION.getAbbreviation() : '-' ); flags.append( (f != null && f.omitNorms()) ? FieldFlag.OMIT_NORMS.getAbbreviation() : '-' ); flags.append( (f != null && f.omitTf()) ? FieldFlag.OMIT_TF.getAbbreviation() : '-' ); flags.append( (lazy) ? FieldFlag.LAZY.getAbbreviation() : '-' ); flags.append( (binary) ? FieldFlag.BINARY.getAbbreviation() : '-' ); flags.append( (f != null && f.isCompressed()) ? FieldFlag.COMPRESSED.getAbbreviation() : '-' ); flags.append( (f != null && f.sortMissingFirst() ) ? FieldFlag.SORT_MISSING_FIRST.getAbbreviation() : '-' ); flags.append( (f != null && f.sortMissingLast() ) ? FieldFlag.SORT_MISSING_LAST.getAbbreviation() : '-' ); return flags.toString(); }
if (sf.multiValued()) { MultiValueField mf = multi.get(fname); if (mf==null) {
addFieldToDoc(entry.getValue(), sf.getName(), sf.multiValued(), doc); toWrite = false; } else { multiValued = schemaField.multiValued(); toWrite = true;
SchemaField f = schema.getField(fieldName); if ((f != null) && (!field.getName().startsWith(CmsSearchField.FIELD_CONTENT))) { multi = f.multiValued();
if (version>=2100 && sf!=null && sf.multiValued()) { startTag("arr",fname,false); doIndent=false;
if (version>=2100 && sf.multiValued()) { startTag("arr",fname,false); doIndent=false;
private static SolrDocument toSolrDoc(Document doc, IndexSchema schema) { SolrDocument out = new SolrDocument(); for ( IndexableField f : doc.getFields() ) { // Make sure multivalued fields are represented as lists Object existing = out.get(f.name()); if (existing == null) { SchemaField sf = schema.getFieldOrNull(f.name()); // don't return copyField targets if (sf != null && schema.isCopyFieldTarget(sf)) continue; if (sf != null && sf.multiValued()) { List<Object> vals = new ArrayList<>(); vals.add( f ); out.setField( f.name(), vals ); } else{ out.setField( f.name(), f ); } } else { out.addField( f.name(), f ); } } return out; }
if (sf.multiValued()) { MultiValueField mf = multi.get(fname); if (mf==null) {
if (sf != null && sf.multiValued()) { writeArrayOpener(-1); // no trivial way to determine array size writeVal(fname, val);
boolean multiToken = sf.multiValued() || ft.multiValuedFieldCache();
if (sf.multiValued() || ft.multiValuedFieldCache() || prefix!=null) {
field.getName()); if (field.multiValued()) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "SirenField instances can not be multivalued: " +
field.getName()); if (field.multiValued()) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ExtendedJsonField instances can not be multivalued: " +