# Ultrasphinx: adding field\_name in search query

**URL:** <https://www.ruby-forum.com/t/ultrasphinx-adding-field-name-in-search-query/156021>\
**Category:** Rails\
**Created:** [December 19, 2008, 11:59am UTC](https://www.ruby-forum.com/t/ultrasphinx-adding-field-name-in-search-query/156021 "2008-12-19T11:59:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [December 19, 2008, 11:59am UTC](https://www.ruby-forum.com/t/ultrasphinx-adding-field-name-in-search-query/156021/1 "2008-12-19T11:59:40Z")

</div>

Hi all,

I want to search for a keyword in a particular field, for example say I  
want to search for the keyword “rails” in the field title so how can I  
include the field\_name in query string.

s=Ultrasphinx::Search.new(:query =\> “@title rails”)

or

s=Ultrasphinx::Search.new(:query =\> “title: rails”)

or

s=Ultrasphinx::Search.new(:query =\> “@title: rails”)

Thanks in advance,  
T.Veeraa.

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [December 20, 2008, 5:41am UTC](https://www.ruby-forum.com/t/ultrasphinx-adding-field-name-in-search-query/156021/2 "2008-12-20T05:41:49Z")

</div>

Veera S. wrote:

> Hi all,
> 
> I want to search for a keyword in a particular field, for example say I  
> want to search for the keyword “rails” in the field title so how can I  
> include the field\_name in query string.
> 
> s=Ultrasphinx::Search.new(:query =\> “@title rails”)
> 
> or
> 
> s=Ultrasphinx::Search.new(:query =\> “title: rails”)
> 
> or
> 
> s=Ultrasphinx::Search.new(:query =\> “@title: rails”)
> 
> Thanks in advance,  
> T.Veeraa.

finally I found

s=Ultrasphinx::Search.new(:query =\> “title: rails”)

above is the write syntax to include the field\_name inside search query  
as per the documentation.

But when you are using this for exact phrase match, it not working.

s=Ultrasphinx::Search.new(:query =\> ‘title: “ruby on rails”’)

am searching for the exact phrase “ruby on rails” in title field it  
matches exact phrase, thats good, but when am trying the same phrase  
with another field also returning the same result. Hence not its not  
looking into the field what I specified.
