Weighting an indexed boolean field makes no difference in searches?

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. 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. Thanks a lot Pat, I’ll try this.

    —
    Sent from my iPad, please excuse hypos.

Reply to this discussion Internal reply only staff will see it

Markdown

Attaching KB article:

» »

Read more…

Attach files

Up to 10MB each.

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

Recent Discussions