title: Inconsistent result from sphinxsearch when doing geo distance search
body: <p>I have an application that uses sphinxsearch and have a situation in which there needs to do some searching based on distance, like within 1 mile, 5 mile, 20 miles, 100 miles. It works fine on most occasions. But sometimes, suppose if we search for data within 20 miles and say we have 5 result data, it returns correctly. Next, if we do a search within 100 miles, it returns fewer data compared to the 20 mile search. However, this is fixed if we re-index the data and try the search again. After re-indexing, it runs well for some days. </p>
  
  <p>Anybody knows why this happens and how to fix it ? </p>
  
  <p><strong>sphinx.conf:</strong></p>
  
  <pre><code>source src1
  {
  
  type                    = mysql
  
  #####################################################################
  ## SQL settings (for 'mysql' and 'pgsql' types)
  #####################################################################
  
  # some straightforward parameters for SQL source types
  sql_host                = localhost
  sql_user                = my_user
  sql_pass                = my_pass
  sql_db                  = my_db
  sql_port                = 3306  # optional, default is 3306
  
  
  
  # main document fetch query
  # mandatory, integer document ID field MUST be the first selected column
  sql_query               = \
      SELECT 1000000000000000+id as id , name, NULL as address, keywords as keyword, 1 as type \
      FROM tbl1 \
              UNION \
          SELECT 2000000000000000+id as id , name, address, NULL as keyword, 2 as type  \
      FROM tbl2 \
      UNION \
          SELECT 3000000000000000+id as id , name, NULL as address, NULL as keyword, 3 as type  \
      FROM tbl3 \
      UNION \
          SELECT 4000000000000000+id as id , name, NULL as address, NULL as keyword, 4 as type  \
      FROM tbl4
  
      sql_field_string = name
      sql_attr_uint = type
      sql_ranged_throttle = 0 
  }
  
  source filter_tbl1
  {
  
  type                    = mysql
  
  #####################################################################
  ## SQL settings (for 'mysql' and 'pgsql' types)
  #####################################################################
  
  # some straightforward parameters for SQL source types
  sql_host                = localhost
  sql_user                = my_user
  sql_pass                = my_pass
  sql_db                  = my_db
  sql_port                = 3306  # optional, default is 3306
  
  
  
  # main document fetch query
  # mandatory, integer document ID field MUST be the first selected column
  sql_query               = \
      SELECT CONCAT(t1.id,t5.cid) as id, t1.id as t1id, c.name AS cname, latitude * pi() / 180 as latitude, \
      longitude * pi() / 180 as longitude, 1 as type FROM `tbl1` AS t1 \
      JOIN  tbl5 AS t5 ON t5.etId = t1.id JOIN tbl4 AS c ON t5.cid  = c.id   \
              LEFT JOIN `tbl2` AS t2 ON t2.id = t1.locationId JOIN `tbl6` AS cc ON t2.cityId = cc.id   \
      WHERE t1.isPublic='yes' AND t1.active ='yes' AND endDate &gt;= CURDATE()
  
  
      sql_field_string = t1id
  sql_field_string = cname
      sql_attr_float = latitude
      sql_attr_float = longitude
  sql_attr_uint = type
  sql_ranged_throttle = 0 
  }
  
  source filter_active
  {
  
  type                    = mysql
  
  #####################################################################
  ## SQL settings (for 'mysql' and 'pgsql' types)
  #####################################################################
  
  # some straightforward parameters for SQL source types
  sql_host                = localhost
  sql_user                = my_user
  sql_pass                = my_pass
  sql_db                  = my_db
  sql_port                = 3306  # optional, default is 3306
  
  
  
  # main document fetch query
  # mandatory, integer document ID field MUST be the first selected column
  sql_query               = \
      SELECT t1.id as id, t1.isPublic as isPublic, t1.active as active, latitude * pi() / 180 as latitude, longitude * pi() / 180 as longitude, \
              1 as type \
      FROM `tbl1` AS t1 \
              JOIN  tbl5 AS t5 ON t5.etId = t1.id JOIN tbl4 AS c ON t5.cid = c.id  \
      LEFT JOIN `tbl2` AS t2 ON t2.id = t1.locationId JOIN `tbl6` AS cc ON t2.cityId = cc.id   \
      WHERE t1.isPublic='yes' AND t1.active ='yes' AND endDate &gt;= CURDATE()
  
  
  sql_field_string = isPublic
  sql_field_string = active
  sql_attr_float = latitude
      sql_attr_float = longitude
  sql_attr_uint  = type
  sql_ranged_throttle = 0 
  }
  
  source src1throttled : src1
  {
  sql_ranged_throttle         = 100
  }
  source filter_tbl1throttled : filter_tbl1
  {
  sql_ranged_throttle         = 100
  }
  source filter_activethrottled : filter_active
  {
  sql_ranged_throttle         = 100
  }
  
  index loop_srch_local
  {
  
  source          = src1
  path            = /usr/local/sphinx/var/data/loop_srch_local
  
  min_prefix_len      = 1
      # min_infix_len     = 1
  enable_star     = 1
  expand_keywords         = 1 
      prefix_fields = name, address, keyword
      dict            = keywords
  charset_type = utf-8
  }
  
  index loop_srch
  {    
      type = rt
  
      path = /usr/local/sphinx/var/data/loop_srch   
  
  min_prefix_len      = 2
      # min_infix_len     = 1
  enable_star     = 1
  expand_keywords         = 1 
      prefix_fields           = name, address, keyword
      dict            = keywords
      charset_type = utf-8
  
  
      # rt_attr_bigint = id  
      rt_field = name
      rt_field = address
      rt_field = keyword
      rt_attr_uint = type
  }
  
  index loop_filt_tabl1
  {    
      type = rt
  
      path = /usr/local/sphinx/var/data/loop_filt_tabl1
  
   rt_field = t1id    
   rt_field = cname
   rt_attr_float = latitude
   rt_attr_float = longitude
   rt_attr_uint = type
  
  dict            = keywords
  min_word_len        = 3
  #min_prefix_len     = 3
      min_infix_len       = 1
  enable_star     = 1
  html_strip      = 0
  inplace_enable      = 0
  
      charset_type = utf-8
  }
  
  index loop_filt_tbl1_local
  {
  
  source          = filter_tbl1
  path            = /usr/local/sphinx/var/data/filter_tbl1_local
  
  dict            = keywords
  min_word_len        = 3
  #min_prefix_len     = 3
      min_infix_len       = 1
  enable_star     = 1
  html_strip      = 0
  inplace_enable      = 0
  
      charset_type = utf-8
  
  }
  
  index loop_filt_active
  {    
      type = rt
  
       path = /usr/local/sphinx/var/data/loop_filt_active
  
   rt_field = isPublic
   rt_field =  active
   rt_attr_float = latitude
   rt_attr_float = longitude
   rt_attr_uint = type
  
  dict            = keywords
  min_word_len        = 3
  #min_prefix_len     = 3
      min_infix_len       = 1
  enable_star     = 1
  html_strip      = 0
  inplace_enable      = 0
  
      charset_type = utf-8
  }
  
  index loop_filt_active_local
  {
  
  source          = filter_active
  path            = /usr/local/sphinx/var/data/filter_active_local
  
  dict            = keywords
  min_word_len        = 3
  #min_prefix_len     = 3
      min_infix_len       = 1
  enable_star     = 1
  html_strip      = 0
  inplace_enable      = 0
  
      charset_type = utf-8
  }
  
  
  index loop_srchstemmed : loop_srch_local
  {
  path            = /usr/local/sphinx/var/data/loop_srchstemmed
  morphology      = stem_en
  }
  
  index dist1
  {
  # 'distributed' index type MUST be specified
  type                = distributed
  
  # local index to be searched
  # there can be many local indexes configured
  local               = loop_srch_local
  local               = loop_srchstemmed
  local               = loop_filt_tabl1_local
  local               = loop_filt_active_local    
  
  # remote agent
  # multiple remote agents may be specified
  # syntax for TCP connections is 'hostname:port:index1,[index2[,...]]'
  # syntax for local UNIX connections is '/path/to/socket:index1,[index2[,...]]'
  agent               = localhost:9313:remote1
  agent               = localhost:9314:remote2,remote3
  # agent             = /var/run/searchd.sock:remote4
  
  # blackhole remote agent, for debugging/testing
  # network errors and search results will be ignored
  #
  # agent_blackhole       = testbox:9312:testindex1,testindex2
  
  
  # remote agent connection timeout, milliseconds
  # optional, default is 1000 ms, ie. 1 sec
  agent_connect_timeout   = 1000
  
  # remote agent query timeout, milliseconds
  # optional, default is 3000 ms, ie. 3 sec
  agent_query_timeout     = 3000
  }
  
  indexer
  {
  # memory limit, in bytes, kiloytes (16384K) or megabytes (256M)
  # optional, default is 32M, max is 2047M, recommended is 256M to 1024M
  mem_limit           = 32M
  
  # maximum IO calls per second (for I/O throttling)
  # optional, default is 0 (unlimited)
  #
  # max_iops          = 40
  
  
  # maximum IO call size, bytes (for I/O throttling)
  # optional, default is 0 (unlimited)
  #
  # max_iosize        = 1048576
  
  
  # maximum xmlpipe2 field length, bytes
  # optional, default is 2M
  #
  # max_xmlpipe2_field    = 4M
  
  
  # write buffer size, bytes
  # several (currently up to 4) buffers will be allocated
  # write buffers are allocated in addition to mem_limit
  # optional, default is 1M
  #
  # write_buffer      = 1M
  }
  
  searchd
  {
  # hostname, port, or hostname:port, or /unix/socket/path to listen on
  # multi-value, multiple listen points are allowed
  # optional, default is 0.0.0.0:9312 (listen on all interfaces, port 9312)
  #
  # listen                = 127.0.0.1
  listen              = 0.0.0.0:9312
  listen              = 9306:mysql41
  # listen                = /var/run/searchd.sock
  
  
  # log file, searchd run info is logged here
  # optional, default is 'searchd.log'
  log                 = /usr/local/sphinx/var/log/searchd.log
  
  # query log file, all search queries are logged here
  # optional, default is empty (do not log queries)
  query_log           = /usr/local/sphinx/var/log/query.log
  
  # client read timeout, seconds
  # optional, default is 5
  read_timeout        = 5
  
  # request timeout, seconds
  # optional, default is 5 minutes
  client_timeout      = 300
  
  # maximum amount of children to fork (concurrent searches to run)
  # optional, default is 0 (unlimited)
  max_children        = 30
  
  # PID file, searchd process ID file name
  # mandatory
  pid_file            = /var/run/sphinxsearch/searchd.pid
  #pid_file           = /var/run/sphinx-searchd.pid
  
  # max amount of matches the daemon ever keeps in RAM, per-index
  # WARNING, THERE'S ALSO PER-QUERY LIMIT, SEE SetLimits() API CALL
  # default is 1000 (just like Google)
  max_matches         = 1000
  
  # seamless rotate, prevents rotate stalls if precaching huge datasets
  # optional, default is 1
  seamless_rotate     = 1
  
  # whether to forcibly preopen all indexes on startup
  # optional, default is 0 (do not preopen)
  preopen_indexes     = 0
  
  # whether to unlink .old index copies on succesful rotation.
  # optional, default is 1 (do unlink)
  unlink_old          = 1
  
  # attribute updates periodic flush timeout, seconds
  # updates will be automatically dumped to disk this frequently
  # optional, default is 0 (disable periodic flush)
  #
  # attr_flush_period = 900
  
  
  # instance-wide ondisk_dict defaults (per-index value take precedence)
  # optional, default is 0 (precache all dictionaries in RAM)
  #
  # ondisk_dict_default   = 1
  
  
  # MVA updates pool size
  # shared between all instances of searchd, disables attr flushes!
  # optional, default size is 1M
  mva_updates_pool    = 1M
  
  # max allowed network packet size
  # limits both query packets from clients, and responses from agents
  # optional, default size is 8M
  max_packet_size     = 8M
  
  # crash log path
  # searchd will (try to) log crashed query to 'crash_log_path.PID' file
  # optional, default is empty (do not create crash logs)
  #
  # crash_log_path        = /usr/local/sphinx/var/log/crash
  
  
  # max allowed per-query filter count
  # optional, default is 256
  max_filters         = 256
  
  # max allowed per-filter values count
  # optional, default is 4096
  max_filter_values   = 4096
  
  
  # socket listen queue length
  # optional, default is 5
  #
  # listen_backlog        = 5
  
  
  # per-keyword read buffer size
  # optional, default is 256K
  #
  # read_buffer           = 256K
  
  
  # unhinted read size (currently used when reading hits)
  # optional, default is 32K
  #
  # read_unhinted     = 32K
      workers               = threads
  }
  </code></pre>
  
  <p><strong>client code</strong></p>
  
  <pre><code>$cl = new SphinxClient();
  $cl-&gt;SphinxClient();
  $cl-&gt;SetMatchMode( SPH_MATCH_EXTENDED2 );
  $cl-&gt;SetRankingMode( SPH_RANK_PROXIMITY_BM25 );
  
  $latitudeRadians  = $latitude*pi()/180 ; // some value for $latitude
  $longitudeRadians = $longitude*pi()/180 ;// some value for $longitude
  $cl-&gt;SetGeoAnchor('venue_latitude', 'venue_longitude', $latitudeRadians, $longitudeRadians);
  
  $minLimit  = 0.00 ;
  $maxLimit  = 15*1609.344 ; //for within 15 miles. Will vary depending on the choice.
  
  $cl-&gt;SetFilterFloatRange('@geodist', floatval($minLimit), floatval($maxLimit));
  $result = $cl-&gt;Query("","loop_filt_tabl1");
  </code></pre>