Bugs: Browse | Submit New | Admin

[#17630] Missing sphincter_index_id in search results causes NoMethodError

Date:
2008-01-30 19:19
Priority:
3
Submitted By:
Andy Stewart (airblade)
Assigned To:
Eric Hodel (drbrain)
Category:
Sphincter
State:
Open
Summary:
Missing sphincter_index_id in search results causes NoMethodError

Detailed description
Sphincter-1.1.0
Sphinx 0.9.8-svn-r1112

I found some of my searches in the console triggered NoMethodErrors in lib/sphincter/search.rb.  The stanza in question
is this (lines 175-178):

    ids = matches.map do |id, match|
      (id - match['attrs']['sphincter_index_id']) /
        Sphincter::Configure.index_count
    end

Debugging showed that the match hash did not have an 'attrs' key.  I was able to work around the problem by replacing
match['attrs']['sphincter_index_id'] with 0.

Here's what I did:

/path/to/rails/app $ script/console
Loading development environment (Rails 2.0.2)
>> User.search 'george'
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
        from /path/to/rails/app/vendor/gems/Sphincter-1.1.0/lib/sphincter/search.rb:180:in `search'
        from /path/to/rails/app/vendor/gems/Sphincter-1.1.0/lib/sphincter/search.rb:176:in `map'
        from /path/to/rails/app/vendor/gems/Sphincter-1.1.0/lib/sphincter/search.rb:176:in `search'

Here's an excerpt from my sphinx.conf:

source users
{
  index_html_attrs = 
  sql_db = cisapp_development
  sql_group_column = sphincter_index_id
  sql_attr_uint = sphincter_index_id   # added as suggested by deprecation warning
  sql_host = localhost
  sql_pass = waterpolo
  sql_query = SELECT (users.`id` * 1 + 0) AS `id`, 0 AS sphincter_index_id, 'User' AS sphincter_klass, users.`login`
AS `login` FROM users WHERE users.`id` >= $start AND users.`id` <= $end
  sql_query_info = SELECT * FROM users WHERE users.`id` = (($id - 0) / 1)
  sql_query_post = 
  sql_query_pre = SET NAMES utf8
  sql_query_range = SELECT MIN(`id`), MAX(`id`) FROM users
  sql_range_step = 20000
  sql_sock = /tmp/mysql.sock
  sql_user = andy
  strip_html = 0
  type = mysql
}

Let me know if I can provide any further information to help nail this bug.

Regards,
Andy Stewart

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-02-29 15:07
Sender: Andy Stewart

Hmm, please ignore this.

After further digging I realise I didn't understand how
Sphincter worked.  Consequently my workaround is fatally flawed.

The bug I encoutered was possibly caused by this one (which
I've fixed):

http://rubyforge.org/tracker/index.php?func=detail&aid=18483&
amp;group_id=1513&atid=5921
Date: 2008-01-30 19:32
Sender: Andy Stewart

Hmm, it looks like my work around causes 1 test to fail.  With
my workaround
in place I get this:

$ rake test
/usr/local/bin/ruby -w -Ilib:ext:bin:test -e 'require 
"test/test_sphincter_association_searcher.rb"; require
"test/test_sphincter_configure.rb"; require
"test/test_sphincter_search.rb";
require "test/test_sphincter_search_stub.rb"; require
"test/unit"'
Loaded suite -e
Started
.....................F....F..
Finished in 0.319033 seconds.

  1) Failure:
test_search(TestSphincterSearch)
[./test/test_sphincter_search.rb:49]:
<[11, 13, 12]> expected but was
<[12, 14, 13]>.

  2) Failure:
test_sphincter_convert_values(TestSphincterSearch) 
[./test/test_sphincter_search.rb:36]:
<[999932400]> expected but was
<[999903600]>.

29 tests, 60 assertions, 2 failures, 0 errors

That's compared to without my workaround, i.e. the original code,
which has
"just" the 1 test failure:

$ rake test
/usr/local/bin/ruby -w -Ilib:ext:bin:test -e 'require 
"test/test_sphincter_association_searcher.rb"; require
"test/test_sphincter_configure.rb"; require
"test/test_sphincter_search.rb";
require "test/test_sphincter_search_stub.rb"; require
"test/unit"'
Loaded suite -e
Started
..........................F..
Finished in 0.34495 seconds.

  1) Failure:
test_sphincter_convert_values(TestSphincterSearch) 
[./test/test_sphincter_search.rb:36]:
<[999932400]> expected but was
<[999903600]>.

29 tests, 66 assertions, 1 failures, 0 errors

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item