# Ultrasphinx - field is invalid - can't get :filters to work

**URL:** <https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765>\
**Category:** Rails\
**Created:** [September 16, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765 "2008-09-16T22:52:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [September 16, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/1 "2008-09-16T22:52:04Z")

</div>

I am having trouble getting the Ultrasphinx plug-in to filter search  
results using the :filters parameter; searches that use the :query  
parameter, however, work just fine. Every time I run a search using the  
:filters parameter I receive the following error:

Ultrasphinx::UsageError:field “xxx” is invalid

Here is how my model is configured:

class Product  
is\_indexed :fields =\> [“code”]  
end

And here is an example search that fails with the above exception:

search = Ultrasphinx::Search.new(:filters =\> {:code =\> “test”})  
search.run

And an example of a search that works just fine:

search = Ultrasphinx::Search.new(:query =\> “code:test”)  
search.run

I must be missing something simple. Any help would be greatly  
appreciated. Thanks in advance.

Regards,  
Jason

---

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [January 14, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/2 "2009-01-14T17:56:40Z")

</div>

It’s been a while, but, I believe I discovered that :filters are only  
applicable to association FK columns.

---

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [January 14, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/3 "2009-01-14T17:51:19Z")

</div>

I have exactly the same problem. Does anyone knows for a solution?

---

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [January 14, 2009, 7:57pm UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/4 "2009-01-14T19:57:15Z")

</div>

I can not make it work in any way. I’m dealing with this a whole workday  
today.

## So, I have tried all of these setups:

class Video \< ActiveRecord::Base  
…  
belongs\_to :topic  
…  
is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’],  
:include =\> [  
{:association\_name =\> ‘topic’, :field =\> ‘id’, :as =\>  
‘topic\_id’}  
],  
:delta =\> {:field =\> ‘created\_at’}  
…  
end

@sphinx = Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\>  
“Video”, :filters =\> {:topic\_id =\> 17} ).run.total\_entries

Ultrasphinx::UsageError: field “topic\_id” is invalid

* * *

is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’,‘topic\_id’],

@sphinx = Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\>  
“Video”, :filters =\> {:topic\_id =\> 17} ).run.total\_entries

Ultrasphinx::UsageError: field “topic\_id” is invalid

* * *

is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’],  
:include =\> [  
{:association\_name =\> ‘topic’, :field =\> ‘id’, :as =\>  
‘topic\_id2’}

@sphinx = Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\>  
“Video”, :filters =\> {:topic\_id2 =\> 17} ).run.total\_entries

Ultrasphinx::UsageError: field “topic\_id2” is invalid

* * *

After each change of configuration I run  
rake ultrasphinx:configure  
rake ultrasphinx:index

No real results. I just can’t make it work with :filters . I’m using  
ultrasphinx 1.11 .

Every idea and help is highly appreciated.

10x in advance.

---

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [January 22, 2009, 9:51am UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/5 "2009-01-22T09:51:56Z")

</div>

I had an advice from the Ultrasphinx official forum to try with aliasing  
the topic\_id as an unique id name. So I tried this configuration:

is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’,  
{:field =\> ‘topic\_id’, :as =\> ‘video\_topic\_id’}],  
:delta =\> {:field =\> ‘created\_at’}

(topic\_id is an integer column that is part of Video model)

After that running: rake ulrasphinx:configure; rake ultrasphinx:index;

## However the same error occurs:

> > Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\> “Video” ).run.total\_entries  
> > =\> 1
> 
> > Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\> “Video”, :filters =\> {:video\_topic\_id =\> 17} ).run.total\_entries  
> > Ultrasphinx::UsageError: field “video\_topic\_id” is invalid

* * *

In case that there’s someone who has successfully run a similar task,  
share your configurations, please.

Stanislav B. wrote:

> I can not make it work in any way. I’m dealing with this a whole workday  
> today.
> 
> ## So, I have tried all of these setups:
> 
> class Video \< ActiveRecord::Base  
> …  
> belongs\_to :topic  
> …  
> is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’],  
> :include =\> [  
> {:association\_name =\> ‘topic’, :field =\> ‘id’, :as =\>  
> ‘topic\_id’}  
> ],  
> :delta =\> {:field =\> ‘created\_at’}  
> …  
> end
> 
> @sphinx = Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\>  
> “Video”, :filters =\> {:topic\_id =\> 17} ).run.total\_entries
> 
> Ultrasphinx::UsageError: field “topic\_id” is invalid
> 
> * * *
> 
> is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’,‘topic\_id’],
> 
> @sphinx = Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\>  
> “Video”, :filters =\> {:topic\_id =\> 17} ).run.total\_entries
> 
> Ultrasphinx::UsageError: field “topic\_id” is invalid
> 
> * * *
> 
> is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’],  
> :include =\> [  
> {:association\_name =\> ‘topic’, :field =\> ‘id’, :as =\>  
> ‘topic\_id2’}
> 
> @sphinx = Ultrasphinx::Search.new(:query =\> “london”, :class\_names =\>  
> “Video”, :filters =\> {:topic\_id2 =\> 17} ).run.total\_entries
> 
> Ultrasphinx::UsageError: field “topic\_id2” is invalid
> 
> * * *
> 
> After each change of configuration I run  
> rake ultrasphinx:configure  
> rake ultrasphinx:index
> 
> No real results. I just can’t make it work with :filters . I’m using  
> ultrasphinx 1.11 .
> 
> Every idea and help is highly appreciated.
> 
> 10x in advance.

---

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [February 11, 2009, 10:21am UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/6 "2009-02-11T10:21:18Z")

</div>

Thank you. I’ll test your suggestion as soon as possible.

---

<div class="post-metadata">

**Author:** ![jfoxny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@jfoxny](https://www.ruby-forum.com/u/jfoxny)\
**Post date:** [February 10, 2009, 11:08pm UTC](https://www.ruby-forum.com/t/ultrasphinx-field-is-invalid-cant-get-filters-to-work/148765/7 "2009-02-10T23:08:40Z")

</div>

I was able to get a ‘filter’ to work…

basically I used the :concatenate option

is\_indexed :fields =\> [‘title’,‘description’,‘created\_at’],  
:concatenate =\> [{:fields =\> [‘topic\_id’], :as  
=\> ‘video\_topic\_id’} ],  
:delta =\> {:field =\> ‘created\_at’}

Then I was able to run this.

Ultrasphinx::Search.new(:query =\> “london video\_topic\_id:  
17”, :class\_names =\> “Video”)

This is in no way ideal…  
But I did manage to return the result set I wanted.

On Jan 22, 3:51 am, Stanislav B. \<rails-mailing-l…@andreas-
