Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.browseengine.bobo.geosearch.solo.search.impl;
  
  import java.util.Iterator;
  
  

Author(s):
gcooney
 
 public class GeoOnlySearcher {
     
     public static final byte[] EMPTY_UUID = new byte[0];
     String indexName;
     
     
     public GeoOnlySearcher(GeoSearchConfig configDirectory directoryString indexName) {
         this. = config;
         this. = directory;
         this. = indexName;
         
          = new GeoConverter();
     }
     
     public GeoOnlyHits search(GeoQuery queryint startint countthrows IOException {
         
         CartesianCoordinateUUID minCoordinate = buildMinCoordinate(centroidCoordinatequery.getRangeInKm());
         CartesianCoordinateUUID maxCoordinate = buildMaxCoordinate(centroidCoordinatequery.getRangeInKm());
 
         GeoSegmentReader<IDGeoRecordsegmentReader = getGeoSegmentReader();
 
         IDGeoRecord minRecord = .toIDGeoRecord(minCoordinate);
         IDGeoRecord maxRecord = .toIDGeoRecord(maxCoordinate);
         Iterator<IDGeoRecordhitIterator = segmentReader.getIterator(minRecordmaxRecord);
         
         return collectHits(centroidCoordinatehitIteratorminCoordinatemaxCoordinatestartcount);
     }
 
         String fileName =  + "." + .getGeoFileExtension();
         GeoSegmentReader<IDGeoRecordsegmentReader = new GeoSegmentReader<IDGeoRecord>(
                 fileName..getBufferSizePerGeoSegmentReader(), 
                 );
         return segmentReader;
     }
     
     private GeoOnlyHits collectHits(CartesianCoordinateUUID centroidCoordinateIterator<IDGeoRecordhitIterator
             CartesianCoordinateUUID minCoordinateCartesianCoordinateUUID maxCoordinate,
             int startint count) {
         
         int totalHits = 0;
         GeoOnlyHitQueue hitQueue = new GeoOnlyHitQueue(start+count);
         while (hitIterator.hasNext()) {
             IDGeoRecord record = hitIterator.next();
             CartesianCoordinateUUID hitCoordinate = .toCartesianCoordinate(record);
             if (minCoordinate.x <= hitCoordinate.x && hitCoordinate.x <= maxCoordinate.x 
                     && minCoordinate.y <= hitCoordinate.y && hitCoordinate.y <= maxCoordinate.y 
                     && minCoordinate.z <= hitCoordinate.z && hitCoordinate.z <= maxCoordinate.z
                     ) {
                 totalHits++;
                 
                 float score = CartesianComputeDistance.computeDistanceSquared(
                         hitCoordinate.xhitCoordinate.yhitCoordinate.z
                         centroidCoordinate.xcentroidCoordinate.ycentroidCoordinate.z);
                 GeoOnlyHit geoHit = new GeoOnlyHit(scorehitCoordinate.uuid);
                 hitQueue.insertWithOverflow(geoHit);
             }
         }
         
         int inRangeHits =  count;
         if (inRangeHits > hitQueue.size() - start) {
             inRangeHits = Math.max(0, hitQueue.size() - start);
         }
         GeoOnlyHit[] hits = new GeoOnlyHit[inRangeHits];
         for (int i = inRangeHits - 1; i >= 0; i--) {
             hits[i] = hitQueue.pop();
         }
         
         return new GeoOnlyHits(totalHitshits);
    }
    
    private CartesianCoordinateUUID buildMinCoordinate(CartesianCoordinateUUID centroidCoordinatefloat rangeInKm) {
        int rangeInUnits = Conversions.radiusMetersToIntegerUnits(rangeInKm * 1000);
        int minX = Conversions.calculateMinimumCoordinate(centroidCoordinate.xrangeInUnits);
        int minY = Conversions.calculateMinimumCoordinate(centroidCoordinate.yrangeInUnits);
        int minZ = Conversions.calculateMinimumCoordinate(centroidCoordinate.zrangeInUnits);
        return new CartesianCoordinateUUID(minXminYminZ);
    }
    
    private CartesianCoordinateUUID buildMaxCoordinate(CartesianCoordinateUUID centroidCoordinatefloat rangeInKm){
        int rangeInUnits = Conversions.radiusMetersToIntegerUnits(rangeInKm * 1000);
        int maxX = Conversions.calculateMaximumCoordinate(centroidCoordinate.xrangeInUnits);
        int maxY = Conversions.calculateMaximumCoordinate(centroidCoordinate.yrangeInUnits);
        int maxZ = Conversions.calculateMaximumCoordinate(centroidCoordinate.zrangeInUnits);
        return new CartesianCoordinateUUID(maxXmaxYmaxZ);
    }
New to GrepCode? Check out our FAQ X