jeudi 27 novembre 2014

in_groups_of undefined on ElasticSearch results


Vote count:

0




Recently I have switched from solr to elasticsearch and I am struggling to get the results to render out without an error.


This is the error I get:



undefined method `in_groups_of' for #<Elasticsearch::Model::Response::Response:0x4a63ad8>


Using the following Gems:



gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'bonsai-elasticsearch-rails'


Routes are already accurate from Solr as I'm using the same controller/view structure.


Home Controller:



def search
if params[:search].nil?
@result = []
else
@result = Listing.search params[:search]
end
end


Form in home/index.html.erb:



<%= form_tag home_search_path, :method => :get, class: "homesearch" do %>
<div class="large-21 medium-21 columns">
<%= text_field_tag :search, params[:search], id: "indexsearch", :placeholder => "Search by industry, franchise name or related keyword", onfocus: "this.placeholder = ''", onblur: "this.placeholder = 'Search by industry, franchise name or related keyword'" %>
</div>
<div class="large-3 medium-3 columns">
<%= submit_tag "", :name => nil %>
</div>
<% end %>


Results in home/search.html.erb:



<% @result.in_groups_of(3, false) do |row_result| %>
<div class="row padding3v content">
<% for result in row_result %>
<div class="large-8 columns content">
<a href="<%= listing_path(result) %>">
<div class="singlelisting">
<div class="text-center">
<div style="border-bottom: 2px solid <%= result.hexbg %>"><img src="<%= result.logourl %>" class="padding1v listinglogo"></div>
</div>
<p class="font08 content3 lightergreybg padding1v margin0b"><%= truncate("#{result.longdescription}", :length => 360, :separator => '', :omission => "") %></p>
<div class="row lightgreybg padding05v">
<div class="large-12 columns text-center">
<h4 class="font08 margin0b margin0t"><%= image_tag('listingicon1.png', class: "listingicon") %><span class="listingicontext"><%= result.franchisename %></span></h4>
</div>
<div class="large-12 columns text-center">
<h4 class="font08 margin0b margin0t"><%= image_tag('listingicon2.png', class: "listingicon") %><span class="listingicontext"><%= result.mininvestment %></span></h4>
</div>
</div>
<p class="text-center textup white margin0b padding05v font07 viewfranchiseprofile">VIEW FRANCHISE PROFILE</p>
</div>
</a>
</div>
<% end %>
</div>
<% end %>


Listings Model:



require 'elasticsearch/model'
class Listing < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

has_many :stories
is_impressionable

def self.search(query)
__elasticsearch__.search(
{
query: {
multi_match: {
query: query,
fields: ['franchisename^10', 'longdescription']
}
}
}
)
end

Listing.import # for auto sync model with elastic search

end


Brain is fried trying to work this out, any advice would be brilliant, thanks.



asked 49 secs ago







in_groups_of undefined on ElasticSearch results

Aucun commentaire:

Enregistrer un commentaire