Note that there are some explanatory texts on larger screens.

plurals
  1. POSunspot Solr Rails - hidden fields scoping and associated models
    primarykey
    data
    text
    <p>I would like to use hidden field parameters(colour_id) to refine my search to fabrics associated with particular Colours.</p> <p>Fabrics have many Colours, Suppliers and Categories</p> <p>However I would like the paramers from hidden fields in my search form (colour_ids) to filter the fabrics, so that only fabrics associated with those colours are searched against.</p> <p>From what I gather the best way of doing this would be to add scopes to my search, and pass the parameters of these hidden fields to the scope to narrow the search results to only fabrics that are associated with those colours.</p> <p>My fabric model looks like this</p> <pre><code>class Fabric &lt; ActiveRecord::Base has_many :fabric_categories has_many :categories, :through =&gt; :fabric_categories has_many :suppliers, :through =&gt; :fabric_suppliers has_many :fabric_suppliers has_many :colours, :through =&gt; :fabric_colours has_many :fabric_colours # solr search method searchable do text :name, :boost =&gt; 5 text :description text :categories do categories.map(&amp;:name) end text :suppliers, :boost =&gt; 2 do suppliers.map(&amp;:name) end end </code></pre> <p>my controller</p> <pre><code> class FabricsController &lt; ApplicationController def index @search = Fabric.search do fulltext params[:search] #scoped assets @fabrics = @search.results </code></pre> <p>and my view</p> <pre><code> &lt;%= form_tag fabrics_path, :method =&gt; :get, :class =&gt; 'form-search' do %&gt; &lt;%= text_field_tag :search, params[:search], :class =&gt; 'query', id: "auto_complete", :placeholder =&gt; '', :autocomplete =&gt; "off" %&gt; &lt;div id="colour_ids"&gt; &lt;%= hidden_field_tag :colour_1 %&gt; &lt;/div&gt; &lt;%= submit_tag "Search", :name =&gt; nil, :class =&gt; 'btn', :id =&gt; 'search_button' %&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload