# UltraSphinx for Rails

**URL:** <https://www.ruby-forum.com/t/ultrasphinx-for-rails/147293>\
**Category:** Rails\
**Created:** [August 30, 2008, 12:38pm UTC](https://www.ruby-forum.com/t/ultrasphinx-for-rails/147293 "2008-08-30T12:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatoliy85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@anatoliy85](https://www.ruby-forum.com/u/anatoliy85)\
**Post date:** [August 30, 2008, 12:38pm UTC](https://www.ruby-forum.com/t/ultrasphinx-for-rails/147293/1 "2008-08-30T12:38:59Z")

</div>

help me please to solve it:

## i have the following configuration of UltraSphinx:

## config/ultrasphinx/development.conf:

## … sql\_query = SELECT user.id as user\_id, user.created\_at as created\_at, profile.first\_name as first\_name, profile.last\_name as last\_name, profile.city\_name as city\_name, profile.interests as interests, country.id as country\_id, space.name as space\_name, profile\_language.language\_id as language\_id FROM users as user INNER JOIN my\_prof as profile on profile.user\_id=user.id LEFT OUTER JOIN my\_country as country on profile.country\_id=country.id LEFT OUTER JOIN my\_space as space on space.owner\_id=user.id LEFT OUTER JOIN my\_languages as profile\_language on profile\_language.profile\_id=profile.id WHERE user.id \>= $start AND user.id \<= $end …

i want implement a full text search only for the next columns:  
first\_name, last\_name, e\_mail.  
But in result, for example, “Ultrasphinx::Search.new(:query =\>  
‘kjhui’).run” get a hash of the following keys(columns name) with  
value(result query):  
for example:  
:user\_id =\> 1, :created\_at =\> ‘12.05.08’, :first\_name =\> ‘kjhui’,  
:last\_name =\> ‘test’, :city\_name =\> ‘Chech’, :interests =\> ‘football’,  
:country\_id =\> 12, :space\_name =\> ‘street’, :language\_id =\> 45

How can i do it?

Help me please.

---

<div class="post-metadata">

**Author:** ![anatoliy85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@anatoliy85](https://www.ruby-forum.com/u/anatoliy85)\
**Post date:** [August 30, 2008, 4:34pm UTC](https://www.ruby-forum.com/t/ultrasphinx-for-rails/147293/2 "2008-08-30T16:34:45Z")

</div>

Your UltraSphinx setup and the returned columns  
of a query have nothing to do with each other.

The US setup only defines how US should query  
the database to git it’s index values

is\_indexed :fields =\> [first\_name, last\_name, e\_mail],  
:delta =\> {:field =\> “updated\_at”}

would be all you need in your User model

@search = Ultrasphinx::Search.new(:query =\> ‘kjhui’)  
@users = @search.run

should return the full set of columns in the users table

---

<div class="post-metadata">

**Author:** ![anatoliy85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@anatoliy85](https://www.ruby-forum.com/u/anatoliy85)\
**Post date:** [August 30, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/ultrasphinx-for-rails/147293/3 "2008-08-30T17:13:27Z")

</div>

Thorsten M. wrote:

> Your UltraSphinx setup and the returned columns  
> of a query have nothing to do with each other.
> 
> The US setup only defines how US should query  
> the database to git it’s index values
> 
> is\_indexed :fields =\> [first\_name, last\_name, e\_mail],  
> :delta =\> {:field =\> “updated\_at”}
> 
> would be all you need in your User model
> 
> @search = Ultrasphinx::Search.new(:query =\> ‘kjhui’)  
> @users = @search.run
> 
> should return the full set of columns in the users table

thanks for answer,

1. but how can i get data from other tables(my\_prof, my\_country,  
my\_space, my\_languages)?(I want to get data near as SQL query(that i  
write in config/ultrasphinx/development.conf) is returned)
2. Can US also returned data from users, my\_prof, my\_country, my\_space,  
my\_languages also?

How can i implement this?

Help me please to solve it problem.

---

<div class="post-metadata">

**Author:** ![anatoliy85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@anatoliy85](https://www.ruby-forum.com/u/anatoliy85)\
**Post date:** [September 9, 2009, 9:24pm UTC](https://www.ruby-forum.com/t/ultrasphinx-for-rails/147293/4 "2009-09-09T21:24:59Z")

</div>

> thanks for answer,
> 
> 1. but how can i get data from other tables(my\_prof, my\_country,  
> my\_space, my\_languages)?(I want to get data near as SQL query(that i  
> write in config/ultrasphinx/development.conf) is returned)
> 2. Can US also returned data from users, my\_prof, my\_country, my\_space,  
> my\_languages also?
> 
> How can i implement this?
> 
> Help me please to solve it problem.

I’m also wondering about this.

Is there a way to return which field(s) the search word is found in for  
each User? I’ve been looking, but have not found a way to do this.
