SpatialQuery使用Lucene进行基于位置的搜索 [英] SpatialQuery for location based search using Lucene

查看:143
本文介绍了SpatialQuery使用Lucene进行基于位置的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的lucene索引的经度和纬度字段索引如下:

My lucene index has got latitude and longitudes fields indexed as follows:

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

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

我想从此索引中检索一组文档,这些文档的经度和纬度值在给定范围内.

I want to retrieve a set of documents from this index whose lat and long values are in a given range.

您已经知道,纬度和经度可能为负值.如何在Lucene中正确存储带符号的十进制数字? 下面提到的方法会给出正确的结果,还是有其他方法可以做到这一点?

As you already know, Lat and long could be negative values. How do i correctly store signed decimal numbers in Lucene? Would the approach mentioned below give correct results or is there any other way to do this?

 Term lowerLatitude = new Term("latitude", bounds.South.ToString() );
                Term upperLatitude = new Term("latitude", bounds.North.ToString());
                RangeQuery latitudeRangeQuery = new RangeQuery(lowerLatitude, upperLatitude, true);
                findLocationQuery.Add(latitudeRangeQuery, BooleanClause.Occur.SHOULD);



                Term lowerLongitude = new Term("longitude", bounds.West.ToString());
                Term upperLongitude = new Term("longitude", bounds.East.ToString());
                RangeQuery longitudeRangeQuery = new RangeQuery(lowerLongitude, upperLongitude, true);
                findLocationQuery.Add(longitudeRangeQuery, BooleanClause.Occur.SHOULD);

此外,我想知道Lucene的ConstantScoreRangeQuery如何比RangeQuery类更好.

Also,I wanted to know how Lucene's ConstantScoreRangeQuery is better than RangeQuery class.

在这种情况下,我面临另一个问题: 我拥有以下3个城市的索引文件之一:

Am facing another problem in this context: I've one of the documents in the index with the following 3 cities:

  • 伊利诺伊州里昂

  • Lyons, IL

伊利诺伊州橡树溪

加利福尼亚州旧金山

如果我以"Lyons,IL"作为输入,则出现此记录. 但是,如果我输入加利福尼亚州旧金山市的信息,则不会.

If i give input as "Lyons, IL" then this record comes up. But if i give San Francisco, CA as input, then it does not.

但是,如果我按以下方式存储此文档的城市:

However, if i store the cities for this document as follows:

  • 加利福尼亚州旧金山

  • San Francisco, CA

伊利诺伊州里昂

伊利诺伊州橡树溪

当我输入加利福尼亚州旧金山市的信息时,该记录就会显示在搜索结果中.

and when i give San Francisco, CA as input, then this record shows in the search results.

我想要的是,如果我输入3个城市中的任何一个,我都应该在搜索结果中获取此文档.

What i want here is that if i type any of the 3 cities in input,I should get this document in the search results.

请帮助我实现这一目标.

Please help me achieve this.

谢谢.

推荐答案

按照skaffman的建议,您可以使用相同的

Following up on skaffman's suggestion, you can use the same tile coordinate system used by all the popular map apps. Choose whatever zoom level is granular enough for your needs, and don't forget to pad with leading zeros.

关于 RangeQuery ,它比ConstantScoreRangeQuery慢,并且限制了值的范围.

Regarding RangeQuery, it's slower than ConstantScoreRangeQuery and limits the range of values.

关于城市国家问题,我们只能推测.但是首先要检查的是索引术语和已解析查询是您所期望的.

Regarding the city-state problem, we can only speculate. But the first things to check are that the indexed terms and the parsed query are what you expect them to be.

这篇关于SpatialQuery使用Lucene进行基于位置的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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