Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Score boost does not work with join fields #1014

Open
ddddddddddddddesolate opened this issue Apr 25, 2022 · 0 comments
Open

Score boost does not work with join fields #1014

ddddddddddddddesolate opened this issue Apr 25, 2022 · 0 comments

Comments

@ddddddddddddddesolate
Copy link

ddddddddddddddesolate commented Apr 25, 2022

I have two models:

Company

class Company < ApplicationRecord
  searchable auto_index: false do
    id_prefix do
      "COMPANY#{id}!"
    end

    string :topics, multiple: true, stored: false do
      topics
    end
  end 
end

and Contact

class Contact < ApplicationRecord
  searchable auto_index: false do
    id_prefix do
      "COMPANY#{company_id}"
    end
    
    join :topics, target: Company, type: :string, multiple: true, join: { from: :id, to: :company_id }
  end
end

and when I try to make a boost by the number of topics in Contacts it does not work

topics = %w[sales marketing development]

Contact.search do
  fulltext "*:*" do
    boost(10.0) { with(:topics).all_of(topics) }
    boost(5.0) { with(:topics).any_of(topics) }
  end
  
  order_by :score, :desc
end

but with Companies all works fine.

I solved this problem locally by adding one hardcoded thing, which is score=max:

sunspot/lib/sunspot/field.rb:226

"{!join from=#{from} to=#{to} v='#{query.join(' AND ')}' score=max}"

But it would be nice if they implemented it in searchable for join with a separate parameter :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant