Problem with "Thinking Sphinx"

Hi,
I am implementing the “sphinx” search using “Thinking Sphinx” search.
I have done everything configured.
I have added the index fields in my model like this
"
define_index do
indexes :name,:sortable => true
indexes description
has created_at, updated_at
end
"
My sphinx configuration file is as
"
source post_core_0
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = development
sql_sock = /var/lib/mysql/mysql.sock
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = ‘+0:00’
sql_query = SELECT SQL_NO_CACHE posts.id * 1 + 0 AS id ,
posts.name AS name, posts.description AS description,
posts.id AS sphinx_internal_id, 1921285768 AS class_crc, 0 AS
sphinx_deleted, IFNULL(posts.name, ‘’) AS name_sort,
UNIX_TIMESTAMP(posts.created_at) AS created_at,
UNIX_TIMESTAMP(posts.updated_at) AS updated_at FROM posts
WHERE posts.id >= $start AND posts.id <= $end AND deleted = 0
GROUP BY posts.id ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(id), 1), IFNULL(MAX(id), 1)
FROM posts
sql_attr_uint = sphinx_internal_id
sql_attr_uint = class_crc
sql_attr_timestamp = created_at
sql_attr_timestamp = updated_at
sql_attr_str2ordinal = name_sort
sql_query_info = SELECT * FROM posts WHERE id = (($id - 0) / 1)
}"

The searching works well but I am seeing in the log that it is firing a
queri like " SELECT * FROM posts WHERE id = (1,2)"

Is my configuration right?

Also, if I am doing indexing like " indexes description, :as=>
:post_desc" and if I try to access it like this:-
"search=ThinkingSphinx.search “test”
puts search.post_desc
"
Giving me an error that “post_desc” is undefined.

Can anyone tell me wwhat is happening?

Thanks,
Mike

try search = C.search ‘test’
C == Class that implements thinking sphinx

finally:

search.each do |s|
s.post_desc
end

2010/8/2 Mike D. [email protected]

"
sql_query_pre = SET NAMES utf8
FROM posts

[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


att: Luciano S.
http://www.lucianosousa.net
*Ruby on Rails Developer
*Linux User #456387
*Contato: (21) 7639-5049

Hi,
I am tried like this:-
Still no success
s=Post.search “pune”
=> [#<Post id: 3, name: “Neovasolution”, description: “This is pune
company”, created_at: “2010-07-14 12:17:16”, updated_at: “2010-07-14
12:17:16”, delta: false>]

s.post_desc
NoMethodError: undefined method desc' for #<ThinkingSphinx::Search:0xb6f1bde4> from /usr/local/ruby/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.18/lib/thinking_sphinx/search.rb:116:inmethod_missing’
from (irb):2

Thanks,
Mike

this is a valid return:
=> [#<Post id: 3, name: “Neovasolution”, description: “This is pune
company”, created_at: “2010-07-14 12:17:16”, updated_at: “2010-07-14
12:17:16”, delta: false>]
*
*
for access after try:
s.each do |sa|

  • sa.post_desc*
    end

2010/8/2 Mike D. [email protected]

#ThinkingSphinx::Search:0xb6f1bde4


att: Luciano S.
http://www.lucianosousa.net
*Ruby on Rails Developer
*Linux User #456387
*Contato: (21) 7639-5049

Hi Mike

The reason for the message in the logs is that Thinking Sphinx/Sphinx
only knows the ids of your search results, and needs to load the
actual objects to return - hence why it talks to the database as well.

As for post_desc - this isn’t available as a method anywhere (on the
search collection or search results) - the alias you’ve given that
column is only for Sphinx, not Ruby. So you can use it when searching:

Post.search :conditions => {:post_desc => ‘foo’}

But if you want the value of post_desc, you will need to access it as
description:

post = Post.search(‘foo’).first
post ? post.description : ‘No Post’

Hope this clarifies things. If you have any more questions, feel free
to ask on the Thinking Sphinx Google Group (I only spotted your posts
here via some noisy twitter bots):
http://groups.google.com/group/thinking-sphinx

Cheers


Pat