<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.lucene.spatial.tier;

import java.io.IOException;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.logging.Logger;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.spatial.NumberUtils;
import org.apache.lucene.spatial.tier.DistanceHandler.Precision;




public class LatLongDistanceFilter extends DistanceFilter {

  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  double distance;
  double lat;
  double lng;
  String latField;
  String lngField;
  Logger log = Logger.getLogger(getClass().getName());
  int offset =0;
  int nextOffset = 0;
  
  Map<Integer,Double> distances = null;
  private Precision precise = null;
  
  /**
   * Provide a distance filter based from a center point with a radius
   * in miles
   * @param lat
   * @param lng
   * @param miles
   * @param latField
   * @param lngField
   */
  public LatLongDistanceFilter(double lat, double lng, double miles, String latField, String lngField){
    distance = miles;
    this.lat = lat;
    this.lng = lng;
    this.latField = latField;
    this.lngField = lngField;
  }
  
  
  public Map<Integer,Double> getDistances(){
    return distances;
  }
  
  public Double getDistance(int docid){
    return distances.get(docid);
  }
  
  @Override
  public BitSet bits(IndexReader reader) throws IOException {

    /* Create a BitSet to store the result */
    int maxdocs = reader.numDocs();
    BitSet bits = new BitSet(maxdocs);
    
    setPrecision(maxdocs);
    // create an intermediate cache to avoid recomputing
    //   distances for the same point 
    //   TODO: Why is this a WeakHashMap? <commit_msg>LUCENE-1387: fix numDocs -> maxDoc<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.lucene.spatial.tier;

import java.io.IOException;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.logging.Logger;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.spatial.NumberUtils;
import org.apache.lucene.spatial.tier.DistanceHandler.Precision;




public class LatLongDistanceFilter extends DistanceFilter {

  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  double distance;
  double lat;
  double lng;
  String latField;
  String lngField;
  Logger log = Logger.getLogger(getClass().getName());
  int offset =0;
  int nextOffset = 0;
  
  Map<Integer,Double> distances = null;
  private Precision precise = null;
  
  /**
   * Provide a distance filter based from a center point with a radius
   * in miles
   * @param lat
   * @param lng
   * @param miles
   * @param latField
   * @param lngField
   */
  public LatLongDistanceFilter(double lat, double lng, double miles, String latField, String lngField){
    distance = miles;
    this.lat = lat;
    this.lng = lng;
    this.latField = latField;
    this.lngField = lngField;
  }
  
  
  public Map<Integer,Double> getDistances(){
    return distances;
  }
  
  public Double getDistance(int docid){
    return distances.get(docid);
  }
  
  @Override
  public BitSet bits(IndexReader reader) throws IOException {

    /* Create a BitSet to store the result */
    int maxdocs = reader.maxDoc();
    BitSet bits = new BitSet(maxdocs);
    
    setPrecision(maxdocs);
    // create an intermediate cache to avoid recomputing
    //   distances for the same point 
    //   TODO: Why is this a WeakHashMap? 
{'fraction_non_alphanumeric': 0.08342989571263036, 'fraction_numerical': 0.0034762456546929316, 'mean_word_length': 3.4531384350816854, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '20771', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1483, 'n_words': 539}