# Search on fields

**URL:** <https://www.ruby-forum.com/t/search-on-fields/99198>\
**Category:** Ferret\
**Created:** [July 20, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/search-on-fields/99198 "2006-07-20T22:46:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanesam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7993a0/32.png) [@vanesam](https://www.ruby-forum.com/u/vanesam)\
**Post date:** [July 20, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/search-on-fields/99198/1 "2006-07-20T22:46:22Z")

</div>

Hi,

I wonder if it is possible to perform the “find\_by\_contents” on a subset  
of fields indexed in acts\_as\_ferret.If so, how?

In my code I have:

acts\_as\_ferret (:fields =\> [‘title’, ‘focus’, ‘purpose’])

However, I like to have two search options one on all fields and one  
only on the title.

Any help is most appreciated.

Thanks,

---

<div class="post-metadata">

**Author:** ![vanesam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7993a0/32.png) [@vanesam](https://www.ruby-forum.com/u/vanesam)\
**Post date:** [July 21, 2006, 1:31am UTC](https://www.ruby-forum.com/t/search-on-fields/99198/2 "2006-07-21T01:31:15Z")

</div>

On 7/21/06, Vanesa M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> only on the title.
> 
> Any help is most appreciated.
> 
> Thanks,

Hi Venesa,

You can search a specific field by prepending the query with the field  
name. For example %{title:“Lord of the Rings” purpose:“enjoyment”}.  
Or, if you don’t want the users typing in field names, you could  
modify the query\_string to search only the title field like this;

```
query_string = "title:(#{query_string})"

```

Hope that helps,  
Dave

PS : (Jens, please correct me if this won’t work with acts\_as\_ferret)

---

<div class="post-metadata">

**Author:** ![vanesam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7993a0/32.png) [@vanesam](https://www.ruby-forum.com/u/vanesam)\
**Post date:** [July 21, 2006, 7:00am UTC](https://www.ruby-forum.com/t/search-on-fields/99198/3 "2006-07-21T07:00:22Z")

</div>

Thanks David, This works.  
-Vanesa

David B. wrote:

> On 7/21/06, Vanesa M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > only on the title.
> > 
> > Any help is most appreciated.
> > 
> > Thanks,
> 
> Hi Venesa,
> 
> You can search a specific field by prepending the query with the field  
> name. For example %{title:“Lord of the Rings” purpose:“enjoyment”}.  
> Or, if you don’t want the users typing in field names, you could  
> modify the query\_string to search only the title field like this;
> 
> ```
> query_string = "title:(#{query_string})"
> 
> ```
> 
> Hope that helps,  
> Dave
> 
> PS : (Jens, please correct me if this won’t work with acts\_as\_ferret)
