本文介绍了在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.

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

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

pendingLatitude->"0041.811846"和pendingLongitude->-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?

谢谢.

推荐答案

以下是有关搜索的最前沿有关问题的专家Uwe Schindler在Lucene中的数值字段.您可能需要使用较旧(但较慢)的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中正确索引纬度和经度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:34