lucene3.0中如何对浮点型数据进行索引,并在浮点型数据的范围内进行搜索?

MultiArrow 2010-03-03
如题,想用lucene对数据库表建立索引,表中有一浮点型字段,该字段是搜索时当做过滤条件的。并且过滤该字段时是按范围过滤的?上网找了一些资料,发现按时间范围过滤的很多,却没有浮点型的,应该用什么方法解决?
MultiArrow 2010-03-03
看了API,NumericRangeQuery方法可用,但是里面有一个句话:
NOTE: This API is experimental and might change in incompatible ways in the next release
还在试验阶段 ,不知道这个的可靠性有多高,会不会有很多BUG?
imjl 2010-03-03
参考下solr的float排序把
illu 2010-03-03
我是将浮点数乘以100  因为是保留2位小数
然后用NumberTool 的longToString 建立索引
TonyLian 2010-03-03
illu 写道
我是将浮点数乘以100  因为是保留2位小数
然后用NumberTool 的longToString 建立索引


我也是转成String
MultiArrow 2010-03-03
TonyLian 写道
illu 写道
我是将浮点数乘以100  因为是保留2位小数
然后用NumberTool 的longToString 建立索引


我也是转成String

转成String如何在一定范围内查询呢?比如说我要查询22.3333至40.3333333的数据,转成String可以如何做得到?
建立索引时用了这种方法:
NumericField gpsx = new NumericField(fieldname, Field.Store.YES, true);
		gpsx.setFloatValue(22.333333f);
		doc.add(gpsx);

搜索时:
org.apache.lucene.search.Query query3=NumericRangeQuery.newFloatRange("gpsX",23.3333f,40.3333333,true,true);

效果貌似还可以,但是API说NumericField,NumericRangeQuery.newFloatRange这些方法都是试验阶段,心里有点不踏实啊
可是我又不会其它的方法了。
PS:用的是lucene3.0
MultiArrow 2010-03-03
还有,NumberTool在3.0中被标为Deprecated了。
illu 2010-03-03
MultiArrow 写道
还有,NumberTool在3.0中被标为Deprecated了。

For new indexes use NumericUtils instead, which provides a sortable binary representation (prefix encoded) of numeric values.

你可以研究研究NumericUtils  这个么
我还在用2.4  囧 所以numbertools就搞定了。。
MultiArrow 2010-03-03
illu 写道
MultiArrow 写道
还有,NumberTool在3.0中被标为Deprecated了。

For new indexes use NumericUtils instead, which provides a sortable binary representation (prefix encoded) of numeric values.

你可以研究研究NumericUtils  这个么
我还在用2.4  囧 所以numbertools就搞定了。。

NumericUtils也有这句话:
NOTE: This API is experimental and might change in incompatible ways in the next release
先用着吧,等待后续版本
TonyLian 2010-03-03
好在你保存的经纬度,可以恒定小数点精度的。

可以像3楼那样, 乘以 1000000 之后去整 为 long,再转String,
转的时候记得前面补'0',保证转出来的所有String都是等长的就OK了。
(NumberTool、NumericUtils之类的估计也是补'0')

Global site tag (gtag.js) - Google Analytics