I have a custom dateBridge because I wanted to add a prefix to my date field name. It works exactly how I expected for MyClassA and MyClassB creating fields:
classA.date
classB.date
However, if I @IndexedEmbedded a MyClassB object with prefix "classA" I get:
classA.embeddedClassB.id //intended
classB.classA.embeddedClassB.date //unintended
My desired field is:
classA.embeddedClassB.classB.date
This is happening because of the last line:
Code:
public class MyCalendarBridge implements FieldBridge, ParameterizedBridge {
String paramKey = "prefix";
String prefix = ""; //default
@SuppressWarnings("rawtypes")
@Override
public void setParameterValues(Map parameters) {
Object prefix = parameters.get(paramKey);
if(prefix != null) {
this.prefix = prefix.toString() + ".";
}
}
@Override
public void set(String name, Object object, Document doc, LuceneOptions lucene) {
name = prefix + name;
// ...
doc.add(new Field(name + ".date", "thedate", store, index, tv));
}}
How do I restructure things to make it work as intended?
EDIT: I ended up changing the name as follows. It's kind of a hack though, and I'd rather have my fieldBridge behave the same way an @IndexedEmbedded(prefix="whatever") works.
Code:
public void set(String name, Object object, Document doc, LuceneOptions lucene) {
String a, b;
a = name.substring(0, name.lastIndexOf('.')+1);
b = name.substring(a.length());
name = a + prefix + b;
// ...