5

我需要帮助让自动完成功能在我的 Solr 搜索栏上工作。我,使用这个https://github.com/xponrails/sunspot_autocomplete

按照步骤操作,它不起作用。

我卡在我的搜索栏上-如何将其添加到其中,同时保留参数 [:search]

其他人也有同样的问题,但删除了他们的代码,使其正常工作。

*它是否纯粹与 jquery-ui 自动完成有关?或者是否必须以某种方式安装插件 - 我不确定我是否正确安装了它。

谢谢你=)

4

2 回答 2

0

请找到自动完成的步骤。我将举一个自动完成项目的例子。

第 1 步:创建一个自动完成文本字段,例如 <%= text_field_with_auto_complete 'item', 'name' %>

第 2 步:然后调用名为 auto_complete_for_item_name 的方法。

setp 3:在该方法中,从表中获取所有行并将其保存在名为@items 的变量中。

第 4 步:然后使用此 @items 变量调用新方法。像渲染 :inline => "<%= auto_complete_result @items, 'name','med_item'%>"

第 5 步:在那个方法中放入这样的 content_tag("ul", items.uniq.join)

它将根据输入的密钥列出所有项目。

如果我错了请纠正我..

感谢和问候,

维吉·库马尔

于 2012-10-10T07:06:12.220 回答
0

i just tried it for my project and it worked fine with this steps

  1. all necessary sunspot gems were included and installed (https://github.com/sunspot/sunspot/blob/master/README.md)
  2. autocomplete gem was installed, of course, too (i used little different git path gem 'sunspot_autocomplete', ">= 0.0.3", :git => 'git://github.com/xponrails/sunspot_autocomplete.git' than proposed in manual)
  3. app was restarted after gems added
  4. sunspot generated solr schema.xml was modified (all necessary nodes were added inside blocks <schema name="sunspot" version="1.0"> <types> *here* </types> </fields> *and here* <fields> </schema>)
  5. solr was restarted after schema.xml modified
  6. checked if it started fine with correct! xml (what i mean pointed here)
  7. necessary rows in searchable do; ...; end block for the model were included (it has to be text field and autocompelte field with unique name addressed to text field with :using=>:[text field name] syntax)
  8. model was reindexed after searchable block changes
  9. necessary javascript libraries were included into application.js (i had to copy all js files from gem to app asset folder)
  10. basic styles were included into application.css (same situation as with js files)
  11. assets need to be precompiled (if you try to get it to work in your production environment)
  12. correct autocomplete_text_field was added to view (i had to .html_safe it because it was rendered as raw text)
  13. app was restarted again

and it worked!

but i guess in one or more of this steps you missed something

if the all question is how to add the search field to template - you just need to add this row

<%= autocomplete_text_field("uniq", "field", "http://localhost:8982/solr/", "uniq_field") %> - assuming you have indexed autocomplete :uniq_field, :using => :field and pointed it to the live version of solr (http://localhost:8982/solr/)

if you share with me some code i can point you to something you missed

cheers!

于 2012-10-07T14:19:28.350 回答