### Question:
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); 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) { } } 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); } } KNearestNeighborScopeDetector(NearestNeighborScopeModel model, int k, QueryCreator queryCreator);  KNearestNeighborScopeDetector(NearestNeighborScopeModel model, int k); @Override GeoCoordinate getScope(String text); @Override String toString(); @Override void close(); @SuppressWarnings("resource") static void main(String[] args); static final QueryCreator BOOLEAN_QUERY_CREATOR; static final QueryCreator MORE_LIKE_THIS_QUERY_CREATOR; }### Answer:
@Test @SuppressWarnings("resource") public void testNearestNeighborScopeDetector() throws IOException { FeatureSetting featureSetting = FeatureSettingBuilder.words().create(); List<LocationDocument> docs = getTestDocs(); NearestNeighborScopeModel model = new NearestNeighborScopeDetectorLearner(new RAMDirectory(), featureSetting) .train(docs); ScopeDetector detector = new KNearestNeighborScopeDetector(model, 1, BOOLEAN_QUERY_CREATOR); GeoCoordinate scope = detector.getScope(TEST_TEXT); assertEquals(35.684, scope.getLatitude(), DELTA); assertEquals(139.774, scope.getLongitude(), DELTA); detector = new KNearestNeighborScopeDetector(model, 3, BOOLEAN_QUERY_CREATOR); scope = detector.getScope(TEST_TEXT); assertEquals(35.684, scope.getLatitude(), DELTA); assertEquals(139.774, scope.getLongitude(), DELTA); }