Indextankのオートコンプリート機能をRailsアプリケーションで機能させるのに問題があります。searchifyを使用してインデックスをホストし、Tanker gemを使用してインデックスを作成しています(https://github.com/kidpollo/tanker)。ここ(http://www.searchify.com/documentation/tutorial-autocomplete)とここ(https://github.com/flaptor/indextank-jquery/)のガイドに従って動作させましたが、結果が得られません戻る。searchifyダッシュボードでパブリックAPIを有効にしました。
問題は、Tanker gemがデータにインデックスを付ける方法に関係していると思います(1つのインデックスで複数のモデルにインデックスを付けることができます)。同じ問題がここで報告されました--https://github.com/kidpollo/tanker/issues/25-しかし、私は与えられた解決策と混同しています。この場合、:indexes =>:textが何を意味するのかわかりません。誰かが私がする必要があることについてもう少し光を当てることができますか?
これは、データにインデックスを付ける私のモデルです。他のモデルはまだデータにインデックスを付けていません
class Post < ActiveRecord::Base
include Tanker
# Relationships
belongs_to :user
has_many :comments
tankit index do
indexes :title
indexes :description
indexes :post_comments do
comments.map {|comment| comment.description }
end
end
# define the callbacks to update or delete the index upon saving and deleting records
after_save :update_tank_indexes
after_destroy :delete_tank_indexes
end
これは、オートコンプリートをテストするために使用したコードです。https://github.com/flaptor/indextank-jquery/の例も使用してみました
<script src='https://raw.github.com/flaptor/indextank-jquery/master/jquery.indextank.ize.js' type='text/javascript'></script>
<script src='https://raw.github.com/flaptor/indextank-jquery/master/jquery.indextank.autocomplete.js' type='text/javascript'></script>
<script type='text/javascript'>
var publicApiUrl = "myPublicURL";
var indexName = "myIndexName";
</script>
<script type='text/javascript'>
$(document).ready(function(){
// let the form be 'indextank-aware'
$("#myform").indextank_Ize(publicApiUrl, indexName);
// let the query box have autocomplete
$("#query").indextank_Autocomplete();
});
</script>
<%= form_tag 'posts/search', :method => :get, :id => 'myForm' do %>
<%= text_field_tag :query, "", :id => 'query' %>
<button type="submit">Search</button>
<% end %>