本文整理汇总了Java中org.apache.solr.common.SolrInputField.getName方法的典型用法代码示例。如果您正苦于以下问题:Java SolrInputField.getName方法的具体用法?Java SolrInputField.getName怎么用?Java SolrInputField.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.SolrInputField
的用法示例。
在下文中一共展示了SolrInputField.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstance
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
public final UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
if (src.getValueCount() <= 1) return src;
SolrInputField result = new SolrInputField(src.getName());
result.setValue(pickSubset(src.getValues()),
src.getBoost());
return result;
}
};
}
示例2: getInstance
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
if (src.getValueCount() <= 1) return src;
SolrInputField result = new SolrInputField(src.getName());
result.setValue(StringUtils.join(src.getValues(), delimiter),
src.getBoost());
return result;
}
};
}
示例3: mutate
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
protected final SolrInputField mutate(final SolrInputField src) {
SolrInputField result = new SolrInputField(src.getName());
for (final Object srcVal : src.getValues()) {
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, 1.0F);
}
}
result.setBoost(src.getBoost());
return 0 == result.getValueCount() ? null : result;
}
示例4: mutate
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
protected SolrInputField mutate(SolrInputField src) {
SchemaField sf = schema.getFieldOrNull(src.getName());
if (sf == null) { // remove this field
return null;
}
FieldType type = PreAnalyzedField.createFieldType(sf);
if (type == null) { // neither indexed nor stored - skip
return null;
}
SolrInputField res = new SolrInputField(src.getName());
res.setBoost(src.getBoost());
for (Object o : src) {
if (o == null) {
continue;
}
Field pre = (Field)parser.createField(sf, o, 1.0f);
if (pre != null) {
res.addValue(pre, 1.0f);
} else { // restore the original value
log.warn("Could not parse field {} - using original value as is: {}", src.getName(), o);
res.addValue(o, 1.0f);
}
}
return res;
}
示例5: toPigValue
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
protected Object toPigValue(SolrInputField field) {
if (field == null)
return null;
String name = field.getName();
Object val = field.getValue();
if (val == null)
return val;
String suffix = name.substring(name.lastIndexOf("_")+1);
if (val instanceof Collection) {
Collection vals = (Collection)val;
// TODO: support multi-valued fields
return null;
} else {
if ("tdt".equals(suffix))
return sdf.get().format((Date)val);
else if ("b".equals(suffix))
return String.valueOf(val);
else
return val;
}
}
示例6: getSolrParams
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
private ModifiableSolrParams getSolrParams(Path file, BasicFileAttributes attrs) throws IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
SolrInputDocument doc = MCRSolrPathDocumentFactory.getInstance().getDocument(file, attrs);
for (SolrInputField field : doc) {
String name = "literal." + field.getName();
if (field.getValueCount() > 1) {
String[] values = getValues(field.getValues());
params.set(name, values);
} else {
params.set(name, field.getValue().toString());
}
}
return params;
}
示例7: mutate
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
protected final SolrInputField mutate(final SolrInputField srcField) {
List<String> messages = null;
SolrInputField result = new SolrInputField(srcField.getName());
for (final Object srcVal : srcField.getValues()) {
final Object destVal = mutateValue(srcVal);
if (SKIP_FIELD_VALUE_LIST_SINGLETON == destVal) {
log.debug("field '{}' {} value '{}' is not mutatable, so no values will be mutated",
new Object[] { srcField.getName(), srcVal.getClass().getSimpleName(), srcVal });
return srcField;
}
if (DELETE_VALUE_SINGLETON == destVal) {
if (log.isDebugEnabled()) {
if (null == messages) {
messages = new ArrayList<>();
}
messages.add(String.format(Locale.ROOT, "removing value from field '%s': %s '%s'",
srcField.getName(), srcVal.getClass().getSimpleName(), srcVal));
}
} else {
if (log.isDebugEnabled()) {
if (null == messages) {
messages = new ArrayList<>();
}
messages.add(String.format(Locale.ROOT, "replace value from field '%s': %s '%s' with %s '%s'",
srcField.getName(), srcVal.getClass().getSimpleName(), srcVal,
destVal.getClass().getSimpleName(), destVal));
}
result.addValue(destVal, 1.0F);
}
}
result.setBoost(srcField.getBoost());
if (null != messages && log.isDebugEnabled()) {
for (String message : messages) {
log.debug(message);
}
}
return 0 == result.getValueCount() ? null : result;
}
示例8: doRemove
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
private void doRemove(SolrInputDocument oldDoc, SolrInputField sif, Object fieldVal) {
final String name = sif.getName();
SolrInputField existingField = oldDoc.get(name);
if (existingField != null) {
final Collection<Object> original = existingField.getValues();
if (fieldVal instanceof Collection) {
original.removeAll((Collection) fieldVal);
} else {
original.remove(fieldVal);
}
oldDoc.setField(name, original);
}
}
示例9: getInstance
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
SolrInputField result = new SolrInputField(src.getName());
result.setValue(src.getValueCount(),
src.getBoost());
return result;
}
};
}
示例10: processAdd
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
/**
* 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 {
// semantics of what happens if dest has diff name are hard
// we could treat it as a copy, or a rename
// 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);
}
示例11: writeXML
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
public static void writeXML( SolrInputDocument doc, Writer writer ) throws IOException
{
writer.write("<doc boost=\""+doc.getDocumentBoost()+"\">");
for( SolrInputField field : doc ) {
float boost = field.getBoost();
String name = field.getName();
for( Object v : field ) {
String update = null;
if (v instanceof Map) {
// currently only supports a single value
for (Entry<Object,Object> entry : ((Map<Object,Object>)v).entrySet()) {
update = entry.getKey().toString();
v = entry.getValue();
if (v instanceof Collection) {
Collection values = (Collection) v;
for (Object value : values) {
writeVal(writer, boost, name, value, update);
boost = 1.0f;
}
} else {
writeVal(writer, boost, name, v, update);
boost = 1.0f;
}
}
} else {
writeVal(writer, boost, name, v, update);
// only write the boost for the first multi-valued field
// otherwise, the used boost is the product of all the boost values
boost = 1.0f;
}
}
}
writer.write("</doc>");
}
示例12: processAdd
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
/**
* 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<String>(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 {
// semantics of what happens if dest has diff name are hard
// we could treat it as a copy, or a rename
// 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);
}
示例13: processAdd
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
/**
* 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<String>(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 {
// semantics of what happens if dest has diff name are hard
// we could treat it as a copy, or a rename
// for now, don't allow it.
if (! fname.equals(dest.getName()) ) {
throw new SolrException(SERVER_ERROR,
"mutute returned field with different name: "
+ fname + " => " + dest.getName());
}
doc.put(dest.getName(), dest);
}
}
super.processAdd(cmd);
}
示例14: assertFieldValues
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
public static void assertFieldValues(SolrInputDocument doc, SolrInputField expectedValues) {
String expectedFieldName = expectedValues.getName();
Collection<String> fieldNames = doc.getFieldNames();
assertTrue("Document doesn't contain field with name " + expectedFieldName, fieldNames.contains(expectedFieldName));
SolrInputField field = doc.getField(expectedFieldName);
assertEquals(expectedValues.getValueCount(), field.getValueCount());
Collection<Object> values = field.getValues();
for (Object expectedVal : expectedValues.getValues()) {
assertTrue("Field with name " + expectedFieldName + " doesn't contain value " + expectedVal, values.contains(expectedVal));
}
}
示例15: writeXML
import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
public static void writeXML( SolrInputDocument doc, Writer writer ) throws IOException
{
writer.write("<doc boost=\""+doc.getDocumentBoost()+"\">");
for( SolrInputField field : doc ) {
float boost = field.getBoost();
String name = field.getName();
for( Object v : field ) {
String update = null;
if (v instanceof Map) {
// currently only supports a single value
for (Entry<Object,Object> entry : ((Map<Object,Object>)v).entrySet()) {
update = entry.getKey().toString();
v = entry.getValue();
if (v instanceof Collection) {
Collection values = (Collection) v;
for (Object value : values) {
writeVal(writer, boost, name, value, update);
boost = 1.0f;
}
} else {
writeVal(writer, boost, name, v, update);
boost = 1.0f;
}
}
} else {
writeVal(writer, boost, name, v, update);
// only write the boost for the first multi-valued field
// otherwise, the used boost is the product of all the boost values
boost = 1.0f;
}
}
}
if (doc.hasChildDocuments()) {
for (SolrInputDocument childDocument : doc.getChildDocuments()) {
writeXML(childDocument, writer);
}
}
writer.write("</doc>");
}