@Override public void index(int docID, GeoCoordinateField field) { String fieldName = field.name(); GeoCoordinate coordinate = field.getGeoCoordinate(); LatitudeLongitudeDocId longLatDocId = new LatitudeLongitudeDocId(coordinate.getLatitude(), coordinate.getLongitude(), docID); IFieldNameFilterConverter fieldNameFilterConverter = geoConverter.makeFieldNameFilterConverter(); CartesianGeoRecord geoRecord = geoConverter.toCartesianGeoRecord(fieldNameFilterConverter, fieldName, longLatDocId); // For now, we need to synchronize this since we can only safely have one thread at a // time adding an item to a treeset. One alternative strategy is to add geoRecords to // an object with better concurrency while indexing and then sort using the TreeSet on // flush synchronized (treeLock) { fieldTree.add(geoRecord); fieldNames.add(fieldName); } return; }
@Override DocWriter processDocument() throws IOException { // this is where we process the geo-search components of the document Document doc = docState.doc; int docID = docState.docID; List<Fieldable> fields = doc.getFields(); List<GeoCoordinateField> geoFields = new Vector<GeoCoordinateField>(); for (Fieldable field : fields) { if (field instanceof GeoCoordinateField) { geoFields.add((GeoCoordinateField) field); } } for (GeoCoordinateField geoField : geoFields) { // process field into GeoIndex here geoIndexer.index(docID, geoField); doc.removeFields(geoField.name()); } return defaultDocConsumerPerThread.processDocument(); }
/** * Adds a record to the geo only index * * @param uuid * @param field */ public void index(byte[] uuid, GeoCoordinateField field) { if (uuid.length != config.getBytesForId()) { throw new IllegalArgumentException( "invalid uuid length: " + uuid.length + ". Expected uuid to be of length " + config.getBytesForId() + "."); } IGeoConverter converter = config.getGeoConverter(); GeoCoordinate geoCoordinate = field.getGeoCoordinate(); IDGeoRecord geoRecord = converter.toIDGeoRecord(geoCoordinate.getLatitude(), geoCoordinate.getLongitude(), uuid); newRecords.add(geoRecord); }