/** Get all the values for a field. * * @param name name of the field to fetch * @return value of the field or null if not set */ @Override public Collection<Object> getFieldValues(String name) { SolrInputField field = getField(name); if (field!=null) { return field.getValues(); } return null; }
/** Get all the values for a field. * * @param name name of the field to fetch * @return value of the field or null if not set */ public Collection<Object> getFieldValues(String name) { SolrInputField field = getField(name); if (field!=null) { return field.getValues(); } return null; }
/** Get all the values for a field. * * @param name name of the field to fetch * @return value of the field or null if not set */ public Collection<Object> getFieldValues(String name) { SolrInputField field = getField(name); if (field!=null) { return field.getValues(); } return null; }
/** * Generates a simple <add><doc>... XML String with no options */ public String adoc(SolrInputDocument sdoc) { List<String> fields = new ArrayList<String>(); for (SolrInputField sf : sdoc) { for (Object o : sf.getValues()) { fields.add(sf.getName()); fields.add(o.toString()); } } return adoc(fields.toArray(new String[fields.size()])); }
/** * 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()); } }
private void addCopyAsIsFields(SolrInputDocument doc, SolrInputField[] copyAsIsFieldsValues) { if (copyAsIsFieldsValues != null) { for (SolrInputField f : copyAsIsFieldsValues) { if (f != null) { Collection<Object> values = f.getValues(); if (values != null && values.size() > 0) { addField(doc, f.getName(), values); } } } } } }
/** * 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()); } }
/** * Get the list of faces and the item identifier: */ public List<String> getFaces() { SolrInputField faces = getField(SolrFields.IMAGE_FACES); if (faces == null || faces.getValueCount() == 0) return null; // Otherwise, list 'em: List<String> hl = new ArrayList<String>(); this.gatherMatches(faces.getValues(), "cat", hl); this.gatherMatches(faces.getValues(), "human", hl); return hl; }
/** * Get the host->host links: */ public List<String> getHostLinks() { SolrInputField links = getField(SolrFields.SOLR_LINKS_HOSTS); if (links == null || links.getValueCount() == 0) return null; // Otherwise, build a list: List<String> hl = new ArrayList<String>(); for (Object v : links.getValues()) { hl.add(getHost() + "\t" + (String) v); } return hl; } }
private Record toRecord(SolrInputDocument doc) { Record record = new Record(); for (Entry<String, SolrInputField> entry : doc.entrySet()) { record.getFields().putAll(entry.getKey(), entry.getValue().getValues()); } return record; }
private Record toRecord(SolrInputDocument doc) { Record record = new Record(); for (Entry<String, SolrInputField> entry : doc.entrySet()) { record.getFields().putAll(entry.getKey(), entry.getValue().getValues()); } return record; }
private static void setUpdateField(SolrInputDocument doc, String field, String value) { if (doc.getField(field) == null || !doc.getField(field).getValues().contains(value)) { doc.addField(field, value); } }
private static void setUpdateField(SolrInputDocument doc, String field, String value) { if (doc.getField(field) == null || !doc.getField(field).getValues().contains(value)) { doc.addField(field, value); } }
private Record toRecord(SolrInputDocument doc) { Record record = new Record(); for (Entry<String, SolrInputField> entry : doc.entrySet()) { record.getFields().putAll(entry.getKey(), entry.getValue().getValues()); } return record; }
private Record toRecord(SolrInputDocument doc) { Record record = new Record(); for (Entry<String, SolrInputField> entry : doc.entrySet()) { record.getFields().putAll(entry.getKey(), entry.getValue().getValues()); } return record; }
private static void addField(SolrInputDocument doc, String name, String value) { // find if such field already exists if (doc.get(name) == null) { // System.out.println("Adding field " + name + " without previous values"); doc.addField(name, value); } else { // for some fields we can't allow multiple values, like ID field phrase, so we have to perform this check SolrInputField f = doc.get(name); for (Object val : f.getValues()) { // fix for boolean values if ((value.equalsIgnoreCase("t") && val.toString().equalsIgnoreCase("true")) || (value.equalsIgnoreCase("f") && val.toString().equalsIgnoreCase("false"))) { return; } if (value.equals(val.toString())) { // if we find such value in the doc, we will not add it again // System.out.println("Field " + name + " already contains value " + value); return; } } // System.out.println("Adding field " + name + " without new value " + value); f.addValue(value); } }
private static void addField(SolrInputDocument doc, String name, String [] values) { // find if such field already exists if (doc.get(name) == null) { doc.addField(name, values); } else { // for some fields we can't allow multiple values, like ID field phrase, so we have to perform this check SolrInputField f = doc.get(name); for (String v : values) { boolean valueAlreadyIn = false; for (Object val : f.getValues()) { if (v.equals(val.toString())) { // if we find such value in the doc, we will not add it again valueAlreadyIn = true; break; } // fix for boolean values if ((v.equalsIgnoreCase("t") && val.toString().equalsIgnoreCase("true")) || (v.equalsIgnoreCase("f") && val.toString().equalsIgnoreCase("false"))) { valueAlreadyIn = true; break; } } if (!valueAlreadyIn) { f.addValue(v); } } } }
private void addField(SolrInputDocument doc, String name, String value) { // find if such field already exists if (doc.get(name) == null) { doc.addField(name, value); } else { // for some fields we can't allow multiple values, like ID field phrase, so we have to perform this check SolrInputField f = doc.get(name); boolean valueExists = false; for (Object existingValue : f.getValues()) { if (existingValue == null && value == null) { valueExists = true; break; } if (existingValue != null && value != null && existingValue.equals(value)) { valueExists = true; break; } } if (!valueExists) { f.addValue(value); } } }
boolean valueExists = false; for (Object existingValue : f.getValues()) { if (existingValue == null && value == null) { valueExists = true;
SolrInputField v = solr.getSolrDocument().get(f); if (v.getValueCount() > 1) { Iterator<Object> i = v.getValues().iterator(); List<String> vals = new ArrayList<String>(); while (i.hasNext()) {