Weighting an indexed boolean field makes no difference in searches?

alex's Avatar

alex

23 Sep, 2014 11:16 AM

Hello, I've got a field that I am indexing as a boolean, mainly it's the episodes field in our table. The idea is that if an entry has > 0 episodes it be listed further down the search results. As such I've added this to the index:

has 'episode > 0',  as: :episode, type: :boolean

And this to our searches results:

 common_search_attributes[:field_weights] = {title: 40, director: 30, starring: 20, episode: 3}

common_search_attributes gets called for all searches.

We figured that by adding a very smal weight to the episode boolean field we'd see the results with episodes listed together further down. However, after reindexing and searching with and without the episode: 3 change the results are exactly the same.

What are we doing wrong?

Thanks.

  1. Support Staff 1 Posted by Pat Allan on 23 Sep, 2014 04:56 PM

    Pat Allan's Avatar

    Hi Alex

    Unfortunately, field weights only work with fields, not attributes.

    There's two other ways to approach this I can think of: order by weight and then by episode:

    common_search_attributes[:select] = "*, weight() as score"
    common_search_attributes[:order] = "score DESC, episode ASC"
    

    The second approach is similar, but allows for more complexity: create your own weighting formula

    common_search_attributes[:select] = "*, IF(episode = 1, weight(), weight() * 3) as score"
    common_search_attributes[:order] = "score DESC"
    

    http://sphinxsearch.com/docs/manual-2.1.9.html#expressions has more details on functions and such you can use.

    Cheers

    Pat

  2. 2 Posted by alex on 24 Sep, 2014 09:44 AM

    alex's Avatar

    Thanks a lot Pat, I’ll try this.


    Sent from my iPad, please excuse hypos.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac