Hi,
i'm using Spring, Hibernate and Hibernate Search (3.0.1). I mapped an object to be indexed as explained in the doc. My object (Node) has a key/value map attribute where the value is another object (NodeProperty). It's a kind of exensibility. Here the definition:
Code:
@Field(index = Index.TOKENIZED, store = Store.YES)
@FieldBridge(impl = PropertyBridge.class)
private Map<String, NodeProperty> properties = new TreeMap<String, NodeProperty>();
I used a FiledBridge to index the properties contained in the map. Here the code of the PropertyBridge
Code:
public class PropertyBridge implements FieldBridge {
public void set(String name, Object value, Document document, Store store, Index index, Float boost) {
if (value != null) {
Map<String, NodeProperty> properties = (Map<String, NodeProperty>) value;
for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
Field field = new Field(key, properties.get(key).getValue().toString(), store, index);
if (boost != null)
field.setBoost(boost);
document.add(field);
}
}
}
}
Running the indexing everything works fine. I can query my node using Lucene.
My problems comes when I tried to use the query setting projection. If i use a field mapped on a Node's attribute works fine. Using a field mapped on a key of the map (NodeProperty) return always null. I read that i need to implements a TwoWayFieldBridge so I changed the interface and added the two methods set() and objectToString() but during the search these methods are never called.
Code:
public class PropertyBridge implements TwoWayFieldBridge {
@SuppressWarnings("unchecked")
public void set(String name, Object value, Document document, Store store, Index index, Float boost) {
if (value != null) {
Map<String, NodeProperty> properties = (Map<String, NodeProperty>) value;
for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
Field field = new Field(key, properties.get(key).getValue().toString(), store, index);
if (boost != null)
field.setBoost(boost);
document.add(field);
}
}
}
public Object get(String name, Document document) {
System.out.println(name + " " + document);
return name;
}
public String objectToString(Object object) {
System.out.println(object.toString());
return object.toString();
}
}
Looking the code of the bridge the properties are stored in the index.
I miss something?
Thanks
Andrew