我是第一次安装 Searchkick 和 Elasticsearch。
我有基本的工作,并正在尝试包括突出显示功能。
指数:
<%= form_tag books_path, method: :get do %>
<%= text_field_tag :q, nil %>
<% end %>
<div class="row">
<div class="col-md-8">
<% @books.each do |book| %>
<div class="media">
<div class="media-body">
<h4 class="media-heading">
<%= link_to book.title, book %>
</h4>
<small>
<%= book.description %>
</small></br>
<% if policy(book).edit? %>
<%= link_to 'Edit', edit_book_path(book) %>
<% end %>
</div>
</div>
<% end %>
<%= paginate @books %>
</div>
<div class="col-md-4">
<% if policy(Book.new).create? %>
<%= link_to "New Book", new_book_path, class: 'btn btn-success' %>
<% end %>
</div>
</div>
控制器
def index
query = params[:q].presence || "*"
@books = Book.search(query, field: [:title], highlight: {tag: "<strong>"})
authorize @books
end
模型
class Book < ActiveRecord::Base
require 'elasticsearch/model'
searchkick highlight: [:title, :description]
我错过了什么?