use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class AddUpdateCommand method getPrintableId.
public String getPrintableId() {
if (req != null) {
IndexSchema schema = req.getSchema();
SchemaField sf = schema.getUniqueKeyField();
if (solrDoc != null && sf != null) {
SolrInputField field = solrDoc.getField(sf.getName());
if (field != null) {
return field.getFirstValue().toString();
}
}
}
return "(null)";
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class FieldMutatingUpdateProcessor method processAdd.
/**
* Calls <code>mutate</code> on any fields identified by the selector
* before forwarding the command down the chain. Any SolrExceptions
* thrown by <code>mutate</code> will be logged with the Field name,
* wrapped and re-thrown.
*/
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
final SolrInputDocument doc = cmd.getSolrInputDocument();
// make a copy we can iterate over while mutating the doc
final Collection<String> fieldNames = new ArrayList<>(doc.getFieldNames());
for (final String fname : fieldNames) {
if (!selector.shouldMutate(fname))
continue;
final SolrInputField src = doc.get(fname);
SolrInputField dest = null;
try {
dest = mutate(src);
} catch (SolrException e) {
String msg = "Unable to mutate field '" + fname + "': " + e.getMessage();
SolrException.log(log, msg, e);
throw new SolrException(BAD_REQUEST, msg, e);
}
if (null == dest) {
doc.remove(fname);
} else {
// for now, don't allow it.
if (!fname.equals(dest.getName())) {
throw new SolrException(SERVER_ERROR, "mutate returned field with different name: " + fname + " => " + dest.getName());
}
doc.put(dest.getName(), dest);
}
}
super.processAdd(cmd);
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class FieldNameMutatingUpdateProcessorFactory method getInstance.
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
return new UpdateRequestProcessor(next) {
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
final SolrInputDocument doc = cmd.getSolrInputDocument();
final Collection<String> fieldNames = new ArrayList<>(doc.getFieldNames());
for (final String fname : fieldNames) {
Matcher matcher = pattern.matcher(fname);
if (matcher.find()) {
String newFieldName = matcher.replaceAll(replacement);
if (!newFieldName.equals(fname)) {
SolrInputField old = doc.remove(fname);
old.setName(newFieldName);
doc.put(newFieldName, old);
}
}
}
super.processAdd(cmd);
}
@Override
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
super.processDelete(cmd);
}
};
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class FieldValueMutatingUpdateProcessor method mutate.
@Override
protected final SolrInputField mutate(final SolrInputField src) {
Collection<Object> values = src.getValues();
//don't mutate
if (values == null)
return src;
SolrInputField result = new SolrInputField(src.getName());
for (final Object srcVal : values) {
final Object destVal = mutateValue(srcVal);
if (DELETE_VALUE_SINGLETON == destVal) {
/* NOOP */
log.debug("removing value from field '{}': {}", src.getName(), srcVal);
} else {
if (destVal != srcVal) {
log.debug("replace value from field '{}': {} with {}", new Object[] { src.getName(), srcVal, destVal });
}
result.addValue(destVal);
}
}
return 0 == result.getValueCount() ? null : result;
}
use of org.apache.solr.common.SolrInputField in project lucene-solr by apache.
the class ConcatFieldUpdateProcessorFactory method getInstance.
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
return mutator(getSelector(), next, src -> {
if (src.getValueCount() <= 1)
return src;
SolrInputField result = new SolrInputField(src.getName());
result.setValue(StringUtils.join(src.getValues(), delimiter));
return result;
});
}
Aggregations