Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public class ConcatFieldsClassBridge implements FieldBridge, ParameterizedBridge
  2. {
  3. private String sepChar;
  4. private String[] toConcatFields;
  5.  
  6. public void setParameterValues(Map parameters)
  7. {
  8. this.sepChar = (String)parameters.get("sepChar");
  9. this.toConcatFields = (String[])parameters.get("fields");
  10. }
  11.  
  12. public void set(String name, Object object, Document document, LuceneOptions luceneOptions)
  13. {
  14. Class aClass = object.getClass();
  15. Class[] paramTypes = new Class[1];
  16. paramTypes[0] = String.class; // get the actual param type
  17.  
  18. String fieldValue = "";
  19.  
  20. for (int i = 0; i < this.toConcatFields.length; i++) {
  21. String methodName = "get" + toConcatFields[i];
  22. Method m = null;
  23.  
  24. try {
  25. m = aClass.getMethod(methodName, paramTypes);
  26. } catch (NoSuchMethodException nsme) {
  27. nsme.printStackTrace();
  28. }
  29.  
  30. String objectValue;
  31.  
  32. try {
  33. objectValue = m.invoke(object);
  34. } catch (IllegalAccessException iae) {
  35. iae.printStackTrace();
  36. } catch (InvocationTargetException ite) {
  37. ite.printStackTrace();
  38. }
  39.  
  40. if (objectValue == null) {
  41. fieldValue += "";
  42. } else {
  43. fieldValue += objectValue + sepChar;
  44. }
  45. }
  46.  
  47. Field field = new Field(name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector());
  48. field.setBoost(luceneOptions.getBoost());
  49.  
  50. document.add(field);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement