-
Notifications
You must be signed in to change notification settings - Fork 15
/
README
88 lines (61 loc) · 3.53 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
= Sunspot Autocomplete
Sunspot Autocomplete is a Rails plugin that lets you use Solr and Sunspot for handy autocompletion of your html text inputs.
=== Features:
* Autocomplete: Typing "clo" will yield results that start with "clo", like "cloudy with a chance of meatballs".
* Autosuggest: Typing "clo" will yield results that contain (or start with) "clo", like "cloudy with a chance of meatballs" and "Jumping like Clowns".
* Both features are case insenitive.
* A CSS based view. You can override some style rules to force your look and feel.
== Prerequisites
You should have solr, sunspot and sunspot_rails ON and running.
http://outoftime.github.com/sunspot
== Installation
gem "sunspot_autocomplete", ">= 0.0.3", :git => "[email protected]:xponrails/sunspot_autocomplete.git"
Copy the gem's assets to your assets directory.
== Usage
In your solr schema.xml, add the following field types inside the <types> tag:
<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="autosuggest" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.LetterTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.LetterTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
Also in your solr schema.xml, add the following fields inside thw <fields> tag.
<dynamicField name="*_ac" type="autocomplete" indexed="true" stored="true"/>
<dynamicField name="*_as" type="autosuggest" indexed="true" stored="true"/>
To be able to autocomplete/autosuggest a model's attribute, call 'autocomplete'/'autosuggest' on it in its 'searchable' block. the field_name used (post_title and post_author in the following example) must be unique across all your autocomplete fields of the application.
class Post < ActiveRecord::Base
searchable do
autocomplete :post_title, :using => :title
autosuggest :post_author, :using => :author
end
end
In your application.js, Add the following lines.
//= require solr-autocomplete/ajax-solr/core/Core
//= require solr-autocomplete/ajax-solr/core/AbstractManager
//= require solr-autocomplete/ajax-solr/managers/Manager.jquery
//= require solr-autocomplete/ajax-solr/core/Parameter
//= require solr-autocomplete/ajax-solr/core/ParameterStore
//= require solr-autocomplete/jquery-autocomplete/jquery.autocomplete
Also, add the following line in your application.css to use the basic style included. Alternatively, you can override those style rules to force your design's look and feel.
*= require solr-autocomplete/jquery.autocomplete
In your view, to create a text field with autocomplete:
<%= autocomplete_text_field "post", "title", "http://127.0.0.1:8983/solr/", "post_title"%>
And to create a text field with autosuggest:
<%= autosuggest_text_field "post", "author", "http://127.0.0.1:8983/solr/", "post_author"%>
You can view documentation for more advanced features of the helpers.