select multiple values in solr via the query array

Viewed 89

I have Rails app with Solr field multivalues:

 <field name='industry_id' type='pint' indexed="true" stored="true" required="true" docValues="true" multiValued="true" />

i want to search field multivalues ​​with an array like: fq: industry_id: [1, 2, 3]. After researching, I knew that if I wanted to do that, it had to be like fq: industry_id: (1 2 3) but in solr_service i define method:

#ids is an array
def suggest_jobs(ids)
    q = "industry_id: #{ids}"
    send_request(q)
end

def send_request(q_param)
    @solr.get 'select', params: {
      'q': q_param
    }
end

this is not a Syntax. How do I edit the method to match the format fq: industry_id: (1 2 3)?

1 Answers

I think you want to expand the ids in your suggest_jobs to be a comma delimited list and wrap that value in parenthesis as shown below:

#ids is an array
def suggest_jobs(ids)
    ids_list = ids.join(",")
    q = "industry_id:(#{ids_list})" # industry_id:(1,2,3)
    send_request(q)
end

Your send_request method is setting the q parameter but in your question you mention the fq field. Either one should work, just make sure to adjust if needed.

Related