I have a places database that uses the `woeid` column as the primary key, 
set via the model's primary_key= method. I have also set :primary_key => 
'woeid' in my index definition file, however the sphinx_internal_id still 
uses the id column, and thus when trying to populate it fails and gives a 
StaleIdsException. It seems the SQL it uses to try and find the records is 
fine, as it searches by id, not woeid, however the context[:results] set is 
always an array of nil objects even though the context[:raw] SQL results 
exist.

No matter what I change in the index definition nothing in the 
development.sphinx.conf changes and it tosses errors, however if I remove 
the custom primary key from the model altogether for testing and let it do 
its thing with just the standard ID everything works fine with Thinking 
Sphinx too. I know via the docs that custom primary keys should work, but 
it doesn't seem to be the case for me. You will notice below that the 
sql_query select changes as does the sql_query_info but not the 
`sphinx_internal_id`. I'm not sure though if that needs to change or not.

Also, is min_infix_length no longer an option available to change per index 
in the index definition? It doesn't seem to make a difference being in my 
definition or not.

## Index definition

ThinkingSphinx::Index.define :geoplanet_place, :with => :active_record do
  # fields
  indexes "CONCAT_WS(', ', geoplanet_places.name, abbr.name)", :as=>:name, 
:sortable=>true
  indexes :ancestry
  
  # options
  set_property :min_infix_len => 1
end


## With custom primary_key on the model

source geoplanet_place_core_0
{
  type = mysql
  sql_host = localhost
  sql_user = root
  sql_pass = 
  sql_db = capture_3_dev
  sql_port = 3306
  sql_sock = /tmp/mysql.sock
  sql_query = SELECT SQL_NO_CACHE `geoplanet_places`.`woeid` * 8 + 4 AS 
`woeid`, 'GeoplanetPlace' AS `sphinx_internal_class_name`, CONCAT_WS(', ', 
geoplanet_places.name, abbr.name) AS `name`, `geoplanet_places`.`ancestry` 
AS `ancestry`, `geoplanet_places`.`id` AS `sphinx_internal_id`, 
'GeoplanetPlace' AS `sphinx_internal_class`, 0 AS `sphinx_deleted` FROM 
`geoplanet_places`  WHERE (`geoplanet_places`.`woeid` >= $start AND 
`geoplanet_places`.`woeid` <= $end) GROUP BY `geoplanet_places`.`woeid`, 
`geoplanet_places`.`ancestry`, `geoplanet_places`.`id` ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`geoplanet_places`.`woeid`), 1), 
IFNULL(MAX(`geoplanet_places`.`woeid`), 1) FROM `geoplanet_places` 
  sql_attr_uint = sphinx_internal_id
  sql_attr_uint = sphinx_deleted
  sql_attr_string = sphinx_internal_class
  sql_field_string = name
  sql_query_info = SELECT `geoplanet_places`.* FROM `geoplanet_places` 
 WHERE (`geoplanet_places`.`woeid` = ($id - 4) / 8)
}

index geoplanet_place_core
{
  path = 
/Users/Bryan/Sites/rubyapps/pc_3.0/db/sphinx/development/geoplanet_place_core
  docinfo = extern
  charset_type = utf-8
  min_infix_len = 3
  enable_star = 1
  html_strip = 1
  source = geoplanet_place_core_0
}



## Without custom primary_key on the model

source geoplanet_place_core_0
{
  type = mysql
  sql_host = localhost
  sql_user = root
  sql_pass = 
  sql_db = capture_3_dev
  sql_port = 3306
  sql_sock = /tmp/mysql.sock
  sql_query = SELECT SQL_NO_CACHE `geoplanet_places`.`id` * 8 + 4 AS `id`, 
'GeoplanetPlace' AS `sphinx_internal_class_name`, CONCAT_WS(', ', 
geoplanet_places.name, abbr.name) AS `name`, `geoplanet_places`.`ancestry` 
AS `ancestry`, `geoplanet_places`.`id` AS `sphinx_internal_id`, 
'GeoplanetPlace' AS `sphinx_internal_class`, 0 AS `sphinx_deleted` FROM 
`geoplanet_places`  WHERE (`geoplanet_places`.`id` >= $start AND 
`geoplanet_places`.`id` <= $end) GROUP BY `geoplanet_places`.`id`, 
`geoplanet_places`.`ancestry`, `geoplanet_places`.`id` ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`geoplanet_places`.`id`), 1), 
IFNULL(MAX(`geoplanet_places`.`id`), 1) FROM `geoplanet_places` 
  sql_attr_uint = sphinx_internal_id
  sql_attr_uint = sphinx_deleted
  sql_attr_string = sphinx_internal_class
  sql_field_string = name
  sql_query_info = SELECT `geoplanet_places`.* FROM `geoplanet_places` 
 WHERE (`geoplanet_places`.`id` = ($id - 4) / 8)
}

index geoplanet_place_core
{
  path = 
/Users/Bryan/Sites/rubyapps/pc_3.0/db/sphinx/development/geoplanet_place_core
  docinfo = extern
  charset_type = utf-8
  min_infix_len = 3
  enable_star = 1
  html_strip = 1
  source = geoplanet_place_core_0
}


## Exception

GeoplanetPlace Load (0.6ms)  SELECT `geoplanet_places`.* FROM 
`geoplanet_places` WHERE `geoplanet_places`.`id` IN (695534, 695541, 
826792, 582045, 583986, 583996, 584138, 584239, 586989, 586990, 587205, 
587500, 587741, 828161, 589192, 591877, 592062, 828995, 593536, 829204)
  GeoplanetPlace Load (0.6ms)  SELECT `geoplanet_places`.* FROM 
`geoplanet_places` WHERE `geoplanet_places`.`id` IN (594973, 597426, 
699609, 699722, 600089, 600142, 600772, 601219, 602427, 602434, 603969, 
604449, 604750, 605131, 606576, 607423, 701675, 608191, 701770, 608424)
  GeoplanetPlace Load (0.6ms)  SELECT `geoplanet_places`.* FROM 
`geoplanet_places` WHERE `geoplanet_places`.`id` IN (609842, 613293, 
613401, 616105, 703517, 703682, 703985, 704215, 620548, 621075, 621101, 
621621, 621622, 622049, 623856, 835614, 624719, 625099, 625289, 626546)

ThinkingSphinx::Search::StaleIdsException: 
ThinkingSphinx::Search::StaleIdsException
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/stale_id_checker.rb:36:in
 
`raise_exception'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/stale_id_checker.rb:20:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/stale_id_checker.rb:6:in
 
`block in call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/stale_id_checker.rb:5:in
 
`each'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/stale_id_checker.rb:5:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/active_record_translator.rb:9:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/inquirer.rb:19:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/geographer.rb:9:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/sphinxql.rb:11:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/middlewares/stale_id_filter.rb:10:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/middleware-0.1.0/lib/middleware/runner.rb:31:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/middleware-0.1.0/lib/middleware/builder.rb:102:in
 
`call'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/thinking-sphinx-3.0.1/lib/thinking_sphinx/search.rb:58:in
 
`populate'
from (irb):3
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in
 
`start'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in
 
`start'
from 
/Users/Bryan/.rvm/gems/ruby-1.9.3-p125@capture-rails3/gems/railties-3.2.11/lib/rails/commands.rb:41:in
 
`<top (required)>'
from script/rails:6:in `require' 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to