Search code examples
ruby-on-railssolrsunspotsunspot-railssunspot-solr

Remove Sunspot's fq parameter from Solr query


I am using Sunspot for Rails, and I would like to remove the filter query from the Sunspot-generated Solr parameter (seen as fq: ["type:Job"]):

Current:

SOLR Request [ path=select parameters={fq: ["type:Job"], q: "programmer", fl: "* score", qf: "Title", defType: "edismax", start: 0, rows: 30} ]

Desired:

SOLR Request [ path=select parameters={q: "programmer", fl: "* score", qf: "Title", defType: "edismax", start: 0, rows: 30} ]

My model:

class Job < ActiveRecord::Base
  searchable do
    text :Title, :as => :Title
  end

I've read the "manually adjusting Solr parameters" from the docs, but couldn't find any reference to actually removing the fq parameter. Thanks!


Solution

  • Can't you just use

    Job.search do
     adjust_solr_params do |params|
       params.except! :fq
     end
    end
    

    Or something similiar in order to remove the :fq key from the params hash