I've been using Search 3.2 for some time, employing double2sortableStr to handle Double values in my classes. I may have been doing it 'wrong' all along, and I'd appreciate some advice now I'm trying to move to Search 3.3.
e.g. one of my Entity classes has a attribute of type double:
Code:
@Column(name="price")
@Field(name="price", index=Index.UN_TOKENIZED, store=Store.YES)
@FieldBridge(impl = SortableDoubleBridge.class)
@Analyzer(impl=org.apache.lucene.analysis.SimpleAnalyzer.class)
private double price;
SortableDoubleBridge is like this:
Code:
import org.apache.solr.util.NumberUtils;
public class SortableDoubleBridge implements TwoWayStringBridge, ParameterizedBridge {
@Override
public Object stringToObject(String stringValue) {
return NumberUtils.SortableStr2double(stringValue);
}
@Override
public String objectToString(Object object) {
return NumberUtils.double2sortableStr((Double)object);
}
I built queries with code like this:
Code:
import org.apache.solr.util.NumberUtils;
final RangeFilter priceFilter = new RangeFilter("price",
NumberUtils.double2sortableStr(fromPrice),
NumberUtils.double2sortableStr(toPrice),
true, true);
I am aware RangeFilter is deprecated, but had trouble getting any other solution to work.
Using the libraries distributed with 3.3, I find solr.NumberUtils no longer exists, and perhaps the @NumericField annotation is 'the way forward' now. However, the docs say some padding is still required.
Should I still try to use solr.NumberUtils.double2sortableStr, or is there a better feature to use with Search 3.3? (e.g. @NumericField)
Perhaps I should create a custom Bridge and map doubles to my own padded String representation to be stored in the index? Surely such a bridge already exists?
For simple financial data (e.g. where we know the precision should be 2 or 4 decimal places), what is the recommended way to index and search such values with 3.3? Is there an example somewhere?
A little good advice would go a long way :)
Thanks
Nick