class KNearestNeighborScopeDetector implements ScopeDetector, Closeable {

    @Override
    public GeoCoordinate getScope(String text) {
        try {
            Query query = queryCreator.createQuery(text, reader, analyzer);
            LOGGER.trace("{} = {}", query.getClass().getSimpleName(), query);
            TopDocs searchResult = searcher.search(query, k);
            if (searchResult.totalHits == 0) {
                return null;
            }
            List<GeoCoordinate> coordinates = new ArrayList<>();
            float maxScore = searchResult.scoreDocs[0].score;
            for (int i = 0; i < searchResult.scoreDocs.length; i++) {
                ScoreDoc scoreDoc = searchResult.scoreDocs[i];
                Document document = searcher.doc(scoreDoc.doc);
                double lat = document.getField(FIELD_LAT).numericValue().doubleValue();
                double lng = document.getField(FIELD_LNG).numericValue().doubleValue();
                try {
                    GeoCoordinate coordinate = new ImmutableGeoCoordinate(lat, lng);
                    // multiply the score, so that we add n items to the list
                    // from which we determine the center
                    int factor = Math.round(10 * scoreDoc.score / maxScore);
                    LOGGER.trace("{} : {} (n={})", coordinate, scoreDoc.score / maxScore, factor);
                    coordinates.addAll(Collections.nCopies(factor, coordinate));
                } catch (IllegalArgumentException e) {
                    // weird shit
                }
            }
            if (coordinates.isEmpty()) {
                return null;
            }
            StopWatch stopWatch = new StopWatch();
            GeoCoordinate center = GeoUtils.getCenterOfMinimumDistance(coordinates);
            LOGGER.trace("calculation for {} took {}", coordinates.size(), stopWatch);
            return center;
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    public  KNearestNeighborScopeDetector(NearestNeighborScopeModel model, int k, QueryCreator queryCreator);
    public  KNearestNeighborScopeDetector(NearestNeighborScopeModel model, int k);

}