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. 緩存Lucene.net搜索結果
- 11. Lucene.Net搜索像A071,A072,A073
- 12. Lucene.net多字段搜索
- 13. Lucene.NET搜索過濾器
- 14. Lucene.Net TermQuery通配符搜索
- 15. NHibernate搜索Lucene.NET SearchFactory爲null
- 16. lucene.net - 搜索詞太短?
- 17. Lucene.net不能搜索「.net」
- 18. Lucene.Net搜索用下劃線
- 19. Lucene.net文件夾搜索
- 20. Lucene.net模糊短語搜索
- 21. Lucene.net搜索和下劃線
- 22. 使用Lucene.Net搜索策略
- 23. Lucene.Net 3.0.3搜索與詞幹或搜索最佳匹配
- 24. 如何搜索搜索字符串與Lucene.Net
- 25. Sitecore使用Lucene.Net搜索:在特定字段中搜索
- 26. Lucene.Net突出搜索關鍵字的搜索結果
- 27. 使用Lucene.Net搜索其他搜索結果
- 28. lucene.net search&order搜索結果hit.score c#
- 29. lucene.net不含空格的搜索查詢
- 30. Lucene.Net無法搜索關鍵字「The」
好問題。我也想知道。 –