5
A
回答
4
晚会有点晚,但是,空间图书馆是开始的地方。其背后的基础是:
1)添加纬度和长域到您的文档
doc.Add(new Field("Latitude",
NumericUtils.DoubleToPrefixCoded(Latitude),
Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("Longitude",
NumericUtils.DoubleToPrefixCoded(Longitude),
Field.Store.YES, Field.Index.NOT_ANALYZED));
2)创建粒度的每一层,你的搜索需要支持绘图仪
IProjector projector = new SinusoidalProjector();
var ctp = new CartesianTierPlotter(0, projector,
Fields.LocationTierPrefix);
StartTier = ctp.BestFit(MaxKms);
EndTier = ctp.BestFit(MinKms);
Plotters = new Dictionary<int, CartesianTierPlotter>();
for (var tier = StartTier; tier <= EndTier; tier++)
{
Plotters.Add(tier, new CartesianTierPlotter(tier,
projector,
Fields.LocationTierPrefix));
}
3)使用您的绘图仪为您的文档编制索引
private static void AddCartesianTiers(double latitude,
double longitude,
Document document)
{
for (var tier = StartTier; tier <= EndTier; tier++)
{
var ctp = Plotters[tier];
var boxId = ctp.GetTierBoxId(latitude, longitude);
document.Add(new Field(ctp.GetTierFieldName(),
NumericUtils.DoubleToPrefixCoded(boxId),
Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
}
}
随着你的索引文件,你可以移动到建立一个查询。本例中使用ConstantScoreQuery,但你可以换是出于对你的远程评分:
/* Builder allows us to build a polygon which we will use to limit
* search scope on our cartesian tiers, this is like putting a grid
* over a map */
var builder = new CartesianPolyFilterBuilder(Fields.LocationTierPrefix);
/* Bounding area draws the polygon, this can be thought of as working
* out which squares of the grid over a map to search */
var boundingArea = builder.GetBoundingArea(Latitude,
Longitude,
DistanceInKilometres * ProductSearchEngine.KmsToMiles);
/* We refine, this is the equivalent of drawing a circle on the map,
* within our grid squares, ignoring the parts the squares we are
* searching that aren't within the circle - ignoring extraneous corners
* and such */
var distFilter = new LatLongDistanceFilter(boundingArea,
DistanceInKilometres * KmsToMiles,
Latitude,
Longitude,
ProductSearchEngine.Fields.Latitude,
ProductSearchEngine.Fields.Longitude);
/* We add a query stating we will only search against products that have
* GeoCode information */
var query = new TermQuery(new Term(Fields.HasGeoCode,
FieldFlags.HasField));
/* Add our filter, this will stream through our results and
* determine eligibility */
masterQuery.Add(new ConstantScoreQuery(distanceFilter),
BooleanClause.Occur.MUST);
所有这一切都从一个博客帖子我只是写,而在寻找类似的问题而采取的。你可以看到它在http://www.leapinggorilla.com/Blog/Read/1005/spatial-search-in-lucenenet
相关问题
- 1. Proximity搜索示例Lucene.Net
- 2. Lucene.Net并行搜索
- 3. Sitecore TreelistEx搜索Lucene.NET
- 4. Lucene.net搜索引擎
- 5. Lucene.NET分面搜索
- 6. Lucene.Net搜索列表
- 7. Lucene.NET分面搜索
- 8. Lucene.NET搜索索引方法
- 9. lucene.net - 搜索词太短?
- 10. NHibernate搜索Lucene.NET SearchFactory为null
- 11. Lucene.NET搜索过滤器
- 12. Lucene.net模糊短语搜索
- 13. 缓存Lucene.net搜索结果
- 14. Lucene.net不能搜索“.net”
- 15. Lucene.net文件夹搜索
- 16. Lucene.Net TermQuery通配符搜索
- 17. Lucene.Net搜索像A071,A072,A073
- 18. Lucene.net多字段搜索
- 19. 慢Lucene.Net搜索性能
- 20. Lucene.net搜索和下划线
- 21. 使用Lucene.Net搜索策略
- 22. Lucene.Net搜索用下划线
- 23. 在Lucene.Net中计数搜索结果
- 24. Lucene.Net。如何在HTML实体中搜索
- 25. Lucene.NET更新不删除搜索条件
- 26. Lucene.NET&Facete搜索解决方案
- 27. 列使用Lucene.NET搜索时优先
- 28. 使用lucene.net进行条件搜索
- 29. Lucene.Net产品关键字搜索
- 30. Lucene.net&NHibernate搜索并发问题
好问题。我也想知道。 –