Advertisement
Guest User

Untitled

a guest
May 13th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. package com.datastax.bdp.cassandra.index.solr;
  2.  
  3. import java.io.IOException;
  4. import java.util.HashSet;
  5. import java.util.Set;
  6.  
  7. import org.apache.commons.lang.StringUtils;
  8. import org.apache.lucene.document.Document;
  9. import org.apache.solr.common.util.NamedList;
  10. import org.apache.solr.core.PluginInfo;
  11. import org.apache.solr.core.SolrCore;
  12. import org.apache.solr.schema.SchemaField;
  13. import org.apache.solr.util.plugin.PluginInfoInitialized;
  14.  
  15. public class CopyFieldInputTransformer extends FieldInputTransformer implements PluginInfoInitialized
  16. {
  17. private volatile SolrCore core;
  18. private volatile Set<String> sourceFields = new HashSet<String>();
  19. private volatile String destinationField;
  20.  
  21. public CopyFieldInputTransformer(SolrCore core)
  22. {
  23. this.core = core;
  24. }
  25.  
  26. public void init(PluginInfo info) {
  27. NamedList args = info.initArgs;
  28.  
  29. String source = (String)args.get("source");
  30.  
  31. if (StringUtils.isEmpty(source)) {
  32. throw new RuntimeException("source must be defined");
  33. }
  34.  
  35. String[] sources = StringUtils.split(source, ',');
  36. for (String s : sources) {
  37. this.sourceFields.add(s);
  38. }
  39.  
  40. destinationField = (String)args.get("destination");
  41.  
  42. if (StringUtils.isEmpty(destinationField)) {
  43. throw new RuntimeException("destination must be defined");
  44. }
  45. }
  46.  
  47. @Override
  48. public boolean evaluate(String field)
  49. {
  50. return (sourceFields.contains(field));
  51. }
  52.  
  53. @Override
  54. public void addFieldToDocument(String fieldName, float docBoost,
  55. String key, Document doc, SchemaField fieldInfo, String value,
  56. boolean makeLazy, SolrSecondaryIndex ssi) throws IOException
  57. {
  58. try
  59. {
  60. SchemaField destinationSchemaField = core.getSchema().getFieldOrNull(destinationField);
  61. if (sourceFields.contains(fieldName))
  62. {
  63. SolrSecondaryIndex.addFieldToDocument(core, docBoost, key, doc,
  64. destinationSchemaField, value, false);
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. throw new RuntimeException(ex);
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement