Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set up a elasticsearch facet search on a nested rails model
    primarykey
    data
    text
    <p>Is it possible to setup a facet search on a nested model? I have a user model that has a profile model. I can search the user model for terms in the profile model. Now I want to filter the search results (users) by the location attribute in the profile model.</p> <p>User Model:</p> <pre><code>class User&lt; ActiveRecord::Base has_one :profile include Tire::Model::Search include Tire::Model::Callbacks mapping do indexes :profiles do indexes :first_name indexes :last_name indexes :summary, type: 'string' indexes :location, type: 'string', boost: 50 indexes :subjects, type: 'string', boost: 100 indexes :education, type: 'string' end end def self.search(params) tire.search(load: true, page: params[:page], per_page: 10) do |s| s.query { string params[:query]} if params[:query].present? s.facet "locations" do terms :location??? end end end # Rest of class omitted end </code></pre> <p>In the search method I do not know what to put down for the "terms". <code>terms :location???</code></p> <p>View:</p> <pre><code> &lt;% @allusers.facets['locations'??]['terms'].each do |facet| %&gt; **error on this line, locations cannot be nil** &lt;li&gt; &lt;%= link_to_unless_current Profile.find(facet['term']).location, params.merge(id: facet['term']) %&gt; &lt;% if params[:location??] == facet['term'].to_s %&gt; (&lt;%= link_to "remove", location: nil %&gt;) &lt;% else %&gt; (&lt;%= facet['count'] %&gt;) &lt;% end %&gt; &lt;/li&gt; &lt;% end %&gt; </code></pre> <p>In the view I do not know what to put down for the params in place of <code>[:location]</code></p>
    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