我无法让 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 索引数据的方式有关(它可以在一个索引中索引多个模型)。这里报告了同样的问题 - 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 %>