# Problem with "Thinking Sphinx"

**URL:** <https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579>\
**Category:** Rails\
**Created:** [August 2, 2010, 3:51pm UTC](https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579 "2010-08-02T15:51:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 2, 2010, 3:51pm UTC](https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579/1 "2010-08-02T15:51:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 2, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579/2 "2010-08-02T16:14:47Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> "  
> sql\_query\_pre = SET NAMES utf8  
> FROM `posts`
> 
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

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

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 2, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579/3 "2010-08-02T16:22:09Z")

</div>

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:in`method\_missing’  
> > from (irb):2

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 2, 2010, 4:28pm UTC](https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579/4 "2010-08-02T16:28:16Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> #ThinkingSphinx::Search:0xb6f1bde4

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

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [August 3, 2010, 1:40am UTC](https://www.ruby-forum.com/t/problem-with-thinking-sphinx/192579/5 "2010-08-03T01:40:56Z")

</div>

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](http://groups.google.com/group/thinking-sphinx)

Cheers

–  
Pat
