Hi,
I have a custom Bridge for my Set, that generates a String like this when indexed by Lucene: "value1 value2 value3". I'm trying to use a Filter @Factory to filter the result inside the String returned by my custom Bridge, like this:
- Returned by Bridge: "value1 value2 value3"
- Filter the results that contains only: "value2", for example.
How can I do that? I'm trying the code bellow, and everything is working fine, but my custom Filter @Factory.
- Bridge:
Code:
public class NegotiationTypeBridge implements TwoWayFieldBridge
{
@Override
public void set(String name, Object value, Document document, LuceneOptions options)
{
if (!(value instanceof Set<?>))
{
throw new IllegalArgumentException("The object must be a Set.");
}
StringBuilder negotiations = new StringBuilder("");
final String token = " ";
@SuppressWarnings("unchecked")
Set<NegotiationType> negotiationTypes = (Set<NegotiationType>) value;
for (NegotiationType negotiationType : negotiationTypes)
{
negotiations.append(negotiationType.getDescription());
negotiations.append(token);
}
Field field = new Field(name, negotiations.toString().trim(), options.getStore(),
options.getIndex());
if (options.getBoost() != null)
{
field.setBoost(options.getBoost());
}
document.add(field);
}
public Object get(String name, Document document)
{
Field field = (Field) document.getField("negotiationTypes");
return field.stringValue();
}
public String objectToString(Object object)
{
String negotiationTypes = (String) object;
return negotiationTypes;
}
}
Filter @Factory:
Code:
public class NegotiationTypeFilterFactory
{
private String negotiationType;
public void setNegotiationType(String negotiationType)
{
this.negotiationType = negotiationType;
}
@Factory
public Filter buildFilter()
{
Term term = new Term("negotiationTypes", negotiationType);
TermQuery query = new TermQuery(term);
Filter filter = new QueryWrapperFilter(query);
filter = new CachingWrapperFilter(filter);
return filter;
}
@Key
public FilterKey getKey()
{
StandardFilterKey key = new StandardFilterKey();
key.addParameter(negotiationType);
return key;
}
}
Thank you!