public Status insert(String table, String key, Map<String, ByteIterator> values) { try { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", key); for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { doc.addField(entry.getKey(), entry.getValue()); response = client.add(table, doc, commitTime); } else { response = client.add(table, doc); client.commit(table);
int ttl = mutation.determineTTL(); SolrInputDocument doc = new SolrInputDocument(); doc.setField(keyIdField, docId); doc.setField(e.field, isNewDoc ? fieldValue : new HashMap<String, Object>(1) {{ put("set", fieldValue); doc.setField(ttlField, String.format("+%dSECONDS", ttl));
private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException { if (documents.size() == 0) return; try { solrClient.request(newUpdateRequest().add(documents), collectionName); } catch (HttpSolrClient.RemoteSolrException rse) { logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse); logger.error("Details in failed document batch: "); for (SolrInputDocument d : documents) { Collection<String> fieldNames = d.getFieldNames(); for (String name : fieldNames) { logger.error(name + ":" + d.getFieldValue(name).toString()); } } throw rse; } }
private void deleteIndividualFieldsFromIndex(String collectionName, String keyIdField, String docId, HashSet<IndexEntry> fieldDeletions) throws SolrServerException, IOException { if (fieldDeletions.isEmpty()) return; Map<String, String> fieldDeletes = new HashMap<String, String>(1) {{ put("set", null); }}; SolrInputDocument doc = new SolrInputDocument(); doc.addField(keyIdField, docId); StringBuilder sb = new StringBuilder(); for (IndexEntry fieldToDelete : fieldDeletions) { doc.addField(fieldToDelete.field, fieldDeletes); sb.append(fieldToDelete).append(","); } if (logger.isTraceEnabled()) logger.trace("Deleting individual fields [{}] for document {}", sb.toString(), docId); UpdateRequest singleDocument = newUpdateRequest(); singleDocument.add(doc); solrClient.request(singleDocument, collectionName); }
public SolrInputDocument toSolrInputDocument(SolrDocument d) { final SolrInputDocument doc = new SolrInputDocument(); for (String name : d.getFieldNames()) { doc.addField(name, d.getFieldValue(name)); } return doc; } }
protected void index_specific(int serverNumber, Object... fields) throws Exception { SolrInputDocument doc = new SolrInputDocument(); for (int i = 0; i < fields.length; i += 2) { doc.addField((String) (fields[i]), fields[i + 1]); } controlClient.add(doc); SolrClient client = clients.get(serverNumber); client.add(doc); }
SolrInputDocument doc = new SolrInputDocument(); String uniqueKeyField = schema.getUniqueKeyField().getName(); if (!hasId) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "All documents must contain a unique key value: '" + doc.toString() + "'"); doc.addField(fieldName, text.toString(), DEFAULT_BOOST); if (uniqueKeyField.equals(fieldName)) { hasId = true;
stateSerializer.serialize( entityState, false, graph ); SolrInputDocument input = new SolrInputDocument(); input.addField( "id", entityState.entityReference().identity() ); input.addField( "type", entityState.entityDescriptor().types().findFirst().get().getName() ); input.addField( "lastModified", java.util.Date.from( entityState.lastModified() ) ); if( field.getType().getTypeName().equals( "json" ) ) input.addField( field.getName(), value ); else if( statement.getObject() instanceof URI && !"type".equals( field.getName() ) ) String name = field.getName(); input.addField( name, value ); value = value.substring( value.lastIndexOf( ':' ) + 1, value.length() ); input.addField( field.getName(), value );
public static SolrInputDocument toSolrInputDocument(Document document) { SolrInputDocument solrInputDocument = new SolrInputDocument(); for (Map.Entry<String, Object> field : document.getDocument().entrySet()) { if (field.getKey().equals(MetaAlertConstants.ALERT_FIELD)) { // We have a children, that needs to be translated as a child doc, not a field. List<Map<String, Object>> alerts = (List<Map<String, Object>>) field.getValue(); for (Map<String, Object> alert : alerts) { SolrInputDocument childDocument = new SolrInputDocument(); for (Map.Entry<String, Object> alertField : alert.entrySet()) { childDocument.addField(alertField.getKey(), alertField.getValue()); } solrInputDocument.addChildDocument(childDocument); } } else { solrInputDocument.addField(field.getKey(), field.getValue()); } } return solrInputDocument; }
public Collection<SolrInputDocument> toDocs(Iterable<JSONObject> messages) { Collection<SolrInputDocument> ret = new ArrayList<>(); for(JSONObject message: messages) { SolrInputDocument document = new SolrInputDocument(); for (Object key : message.keySet()) { Object value = message.get(key); if (value instanceof Iterable) { for (Object v : (Iterable) value) { document.addField("" + key, v); } } else { document.addField("" + key, value); } } if (!document.containsKey(Constants.GUID)) { document.addField(Constants.GUID, UUID.randomUUID().toString()); } ret.add(document); } return ret; }
@Override public void store(String url, Status status, Metadata metadata, Date nextFetch) throws Exception { SolrInputDocument doc = new SolrInputDocument(); doc.setField("url", url); doc.setField("host", URLUtil.getHost(url)); doc.setField("status", status.name()); Iterator<String> keyIterator = metadata.keySet().iterator(); while (keyIterator.hasNext()) { String key = keyIterator.next(); String[] values = metadata.getValues(key); doc.setField(String.format("%s.%s", mdPrefix, key), values); } doc.setField("nextFetchDate", nextFetch); connection.getClient().add(doc); }
private SolrInputDocument buildDocument(ITuple tuple) { SolrInputDocument doc = new SolrInputDocument(); for (String tupleField : tuple.getFields()) { FieldTypeWrapper fieldTypeWrapper = typeFinder.getFieldTypeWrapper(tupleField); if (fieldTypeWrapper != null) { FieldType fieldType = fieldTypeWrapper.getType(); if (fieldType.isMultiValued()) { addMultivalueFieldToDoc(doc, tupleField, tuple); } else { addFieldToDoc(doc, tupleField, tuple); } } else { log.debug("Field [{}] does NOT match static or dynamic field declared in schema. Not added to document", tupleField); } } return doc; }
@Override public void processAdd(AddUpdateCommand cmd) throws IOException { SolrInputDocument doc = cmd.getSolrInputDocument(); String appid = (String)doc.getFieldValue( "appid" ); String docid = (String)doc.getFieldValue( "docid" ); doc.addField("uniqueid", appid + "-" + docid); // pass it up the chain super.processAdd(cmd); }
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()); } } }
/** * Convenience method for building up SolrInputDocuments */ final SolrInputDocument doc(SolrInputField... fields) { SolrInputDocument d = new SolrInputDocument(); for (SolrInputField f : fields) { d.put(f.getName(), f); } return d; }
SchemaField sf = schema.getFieldOrNull(name); if (sf==null && unknownFieldPrefix.length() > 0) { name = unknownFieldPrefix + name; sf = schema.getFieldOrNull(name); } else if (sf == null && defaultField.length() > 0 && name.equals(TikaMetadataKeys.RESOURCE_NAME_KEY) == false /*let the fall through below handle this*/){ name = defaultField; sf = schema.getFieldOrNull(name); if (sf != null && !sf.multiValued() && vals != null) { StringBuilder builder = new StringBuilder(); boolean first=true; document.addField(name, transformValue(fval, sf)); document.addField(name, transformValue(val, sf));
private void addMultivalueFieldToDoc(SolrInputDocument doc, String tupleField, ITuple tuple) { String[] values = getValues(tupleField, tuple); for (String value : values) { log.debug("Adding {} to multivalue field document {}", value, tupleField); doc.addField(tupleField, value); } }