Hello,
I have made my fieldBridge to store a Set<String> :
Code:
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.hibernate.search.bridge.FieldBridge;
import org.hibernate.search.bridge.LuceneOptions;
public class SetStringFieldBridge implements FieldBridge {
public static final char SEPARATOR = ',';
@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
if ( value == null ) {
return;
}
// we expect a Set<String> here. checking for Set for simplicity
if ( ! (value instanceof Set )) {
throw new IllegalArgumentException("support limited to Set<String>");
}
@SuppressWarnings("unchecked")
Set<String> set = (Set<String>)value;
String values = StringUtils.join(set, SEPARATOR);
Field field = new Field(name, values, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector());
field.setBoost(luceneOptions.getBoost());
document.add(field);
}
}
Code:
@Field(index=Index.UN_TOKENIZED, store=Store.YES, analyzer=@Analyzer(impl=SimpleAnalyzer.class))
@FieldBridge(impl=SetStringFieldBridge.class)
@ElementCollection
@CollectionTable(name="v_logicalitem_downloadtype", joinColumns=@JoinColumn(name="logicalitem_id", insertable=false, updatable=false))
@Column(name="downloadtype")
private Set<String> downloadtypes;
Exemple of lucene-index :
In the index :
id | name | myset
1 | foo | value1,value2,value3
2 | bar | value1,value3
3 | bar | value3
Now I would like to use an analyser to make request into this field, because the SimpleAnalyzer is not build for this.
If my request is : 'myset:value3' only index with id=3 is return. And I would like also the id=2 and the id=1.