List of usage examples for org.apache.solr.common SolrInputDocument entrySet
@Override
public Set<Entry<String, SolrInputField>> entrySet()
From source file:com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapperTest.java
License:Apache License
private Record toRecord(SolrInputDocument doc) { Record record = new Record(); for (Entry<String, SolrInputField> entry : doc.entrySet()) { record.getFields().putAll(entry.getKey(), entry.getValue().getValues()); }//from w ww . jav a2 s .c om return record; }
From source file:com.ngdata.hbaseindexer.parse.SolrInputDocumentBuilder.java
License:Apache License
/** * Merge a {@code SolrInputDocument} into the master document, adding a prefix to every field name as it is added. * //from w w w . j a va 2 s. co m * @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()); } }
From source file:net.yacy.cora.federate.solr.connector.AbstractSolrConnector.java
License:Open Source License
private SolrInputDocument partialUpdatePatch(final SolrInputDocument docIn) { SolrInputDocument docOut = new SolrInputDocument(); docOut.setField(CollectionSchema.id.name(), docIn.getFieldValue(CollectionSchema.id.name())); for (Entry<String, SolrInputField> entry : docIn.entrySet()) { if (entry.getKey().equals(CollectionSchema.id.name())) continue; SolrInputField sif = entry.getValue(); Map<String, Object> partialUpdate = new HashMap<>(1); Object value = sif.getValue(); docOut.removeField(entry.getKey()); partialUpdate.put("set", value); docOut.setField(entry.getKey(), partialUpdate); }//from w w w . j a v a 2s . c o m return docOut; }
From source file:nl.minbzk.dwr.zoeken.enricher.uploader.SolrResultUploader.java
License:Open Source License
/** * Determine the database name, based on the composite key, or null if any of the composite key replacements could not be resolved. * * XXX: We only consider the replacement values from the first document given. * * @param name/* w ww .jav a 2 s. c om*/ * @param nameComposition * @param namePrerequisitesExpression * @param documents * @return String */ private String determineAlternateDatabaseName(final String name, final String nameComposition, final String namePrerequisitesExpression, final List<SolrInputDocument> documents) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); String result; result = nameComposition.replace("{name}", name).trim(); result = result.replace("{year}", String.format("%04d", calendar.get(calendar.YEAR))); result = result.replace("{month}", String.format("%02d", calendar.get(calendar.MONTH))); if (documents.size() > 0) { final SolrInputDocument document = documents.get(0); while (result.contains("{") && result.indexOf("}") > result.indexOf("{")) { String fieldName = result.substring(result.indexOf("{") + 1, result.indexOf("}")); if (document.containsKey(fieldName)) result = result.replace("{" + fieldName + "}", document.getFieldValue(fieldName).toString()); else { if (logger.isDebugEnabled()) logger.debug(String.format( "Field '%s' was missing from document with ID '%s' - will revert back to default collection '%s'", fieldName, document.getFieldValue(REFERENCE_FIELD), name)); return null; } } // Also check the pre-requisite expression - only return a composite database name if it's met if (StringUtils.hasText(namePrerequisitesExpression)) { final ExpressionParser parser = new SpelExpressionParser(); final Map<String, Object> values = new HashMap<String, Object>(); for (Map.Entry<String, SolrInputField> entry : document.entrySet()) { // XXX: Always get just the first value /* if (entry.getValue().getValueCount() > 1) values.put(entry.getKey(), entry.getValue().getValues()); else */ values.put(entry.getKey(), entry.getValue().getFirstValue()); } StandardEvaluationContext context = new StandardEvaluationContext(new Object() { public Map<String, Object> getValues() { return values; } }); if (!parser.parseExpression(namePrerequisitesExpression).getValue(context, Boolean.class)) { if (logger.isDebugEnabled()) logger.debug(String.format( "Pre-requisite expression '%s' failed to match against document with ID '%s' - will revert back to default collection '%s'", namePrerequisitesExpression, document.get(REFERENCE_FIELD).toString(), name)); return null; } } } return result; }