在 Lucene 中正确索引纬度和经度值 [英] Correctly indexing latitude and longitude values in Lucene

查看:14
本文介绍了在 Lucene 中正确索引纬度和经度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Lucene API 开发在给定半径内基于​​美国的最近城市搜索"功能.我在 Lucene 中索引城市的纬度和经度值如下:

Am working on a "US based nearest city search within a given radius" functionality using Lucene API. Am indexing city's lat and long values in Lucene as follows:

doc.Add(new Field("latitude", paddedLatitude, Field.Store.YES, Field.Index.UN_TOKENIZED));

doc.Add(new Field("longitude", paddedLongitude, Field.Store.YES, Field.Index.UN_TOKENIZED));

由于 Lucene 只理解字符串而不理解数字,所以我填充了 lat 和 long 值.

Since Lucene only understands strings and not numbers, am padding lat and long values.

例如,如果原始 lat 和 long 分别为 41.811846 和 -87.820628,则填充后的值如下所示:

For example, if original lat and long are 41.811846 and -87.820628 respectively, after padding,values look like:

paddedLatitude -->"0041.811846" 和 paddedLongitude-->"-087.820628"

paddedLatitude -->"0041.811846" and paddedLongitude-->"-087.820628"

在构建最近的城市查询时(使用 Lucene 的 ConstantScoreRangeQuery 类)进行相同的填充.

Am doing the same padding while building the nearest city query(using Lucene's ConstantScoreRangeQuery class).

鉴于 lat 和 long 值可能是十进制/负数,这是对它们进行索引的正确方法,以便当 lucene 对这些执行数字范围/比较操作时,我可以在搜索结果中获得正确的最近城市价值观?

Given the fact that lat and long values could be decimal/negative numbers, is this the right approach to index them so that I would get correct nearest cities in the search results when lucene would perform a number Range/comparison operation on these values?

谢谢.

推荐答案

这里是关于 搜索的前沿Lucene 中的数值场,作者 Uwe Schindler,该主题的专家.您可能需要使用较旧(且速度较慢)的 ConstantScoreRangeQuery,因为 Lucene.net 有点落后于 Lucene,并且链接中描述的类 NumericRangeQuery 尚未在 Java Lucene 中发布.

Here's the bleeding edge about Searching Numerical Fields in Lucene by Uwe Schindler, the expert on the subject. You may need to use the older (and slower) ConstantScoreRangeQuery because Lucene.net is a bit behind Lucene, and the class NumericRangeQuery described in the link was not yet released in Java Lucene.

这篇关于在 Lucene 中正确索引纬度和经度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆