2012-12-13 16 views
5

क्या किसी को भी lucene.net अनुक्रमणिका अक्षांश और देशांतर मान रखने के साथ कोई अनुभव है तो एक बिंदु से दूरी के आधार पर परिणामों का क्रमबद्ध सेट वापस कर दें?Lucene.net निकटता खोज

क्या लुसीन.Net.Spatial लाइब्रेरी मुझे इसके साथ मदद करेगा?

+1

पर देख सकते हैं। मुझे भी यह जानना चाहिए। –

उत्तर

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

+0

महान उदाहरण के लिए धन्यवाद। मुझे बाध्यता एरिया भाग में कोई समस्या है ... इसमें कुछ गड़बड़ है जहां यह केवल उन दस्तावेजों की पेशकश कर रहा है जो एक दूसरे के करीब हैं, लेकिन जिन निर्देशों से मैंने पूछा था, उससे दूर, इसलिए लेटलॉन्गडिस्टेंसफिल्टर उन्हें जांचता है और पाते हैं कि वे ' बहुत दूर है इसलिए कोई परिणाम वापस नहीं आ गया है। – Jarvis

+1

मैंने अपने ब्लॉग (http://leapinggorilla.com/Blog/Read/1010/spatial-search-in-lucenenet---worked-example) में एक और काम किया उदाहरण जोड़ा है। इसमें आपके पास एक डेमो ऐप फ़ंक्शनिंग देखने के लिए आवश्यक सभी कोड हैं, इसलिए उम्मीद है कि आपकी मदद करनी चाहिए। – Wolfwyrd

संबंधित मुद्दे