notch8_sunspot_autocomplete 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/LICENSE +7 -0
  2. data/README.rdoc +95 -0
  3. data/Rakefile +37 -0
  4. data/VERSION +1 -0
  5. data/lib/autocomplete_view_helpers.rb +126 -0
  6. data/lib/notch8_sunspot_autocomplete.rb +3 -0
  7. data/lib/sunspot_autocomplete.rb +38 -0
  8. data/notch8_sunspot_autocomplete.gemspec +78 -0
  9. data/rdoc/classes/AutocompleteViewHelpers.html +322 -0
  10. data/rdoc/classes/Sunspot.html +111 -0
  11. data/rdoc/classes/Sunspot/Type.html +112 -0
  12. data/rdoc/classes/Sunspot/Type/AutocompleteType.html +117 -0
  13. data/rdoc/classes/Sunspot/Type/AutosuggestType.html +117 -0
  14. data/rdoc/created.rid +1 -0
  15. data/rdoc/files/README.html +238 -0
  16. data/rdoc/files/README_rdoc.html +238 -0
  17. data/rdoc/files/lib/autocomplete_view_helpers_rb.html +236 -0
  18. data/rdoc/files/lib/sunspot_autocomplete_rb.html +101 -0
  19. data/rdoc/fr_class_index.html +31 -0
  20. data/rdoc/fr_file_index.html +29 -0
  21. data/rdoc/fr_method_index.html +28 -0
  22. data/rdoc/index.html +24 -0
  23. data/rdoc/rdoc-style.css +208 -0
  24. data/tasks/tasks.rake +10 -0
  25. data/test/sunspot_autocomplete_test.rb +21 -0
  26. data/test/test_helper.rb +3 -0
  27. data/vendor/assets/javascripts/jquery.js +6240 -0
  28. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/AbstractManager.js +182 -0
  29. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/Core.js +226 -0
  30. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/Parameter.js +161 -0
  31. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/ParameterStore.js +354 -0
  32. data/vendor/assets/javascripts/solr-autocomplete/ajax-solr/managers/Manager.jquery.js +20 -0
  33. data/vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/indicator.gif +0 -0
  34. data/vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.css +49 -0
  35. data/vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.js +867 -0
  36. metadata +114 -0
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Sunspot Autocomplete - A Ruby on Rails plugin
2
+
3
+ Copyright (c) 2010 Haitham Mohammad
4
+
5
+ Dual licensed under the MIT and GPL licenses:
6
+ http://www.opensource.org/licenses/mit-license.php
7
+ http://www.gnu.org/licenses/gpl.html
data/README.rdoc ADDED
@@ -0,0 +1,95 @@
1
+ = Fork reason
2
+
3
+ Updated to work with the asset pipeline
4
+
5
+ = Sunspot Autocomplete
6
+
7
+ Sunspot Autocomplete is a Rails plugin that lets you use Solr and Sunspot for handy autocompletion of your html text inputs.
8
+
9
+ === Features:
10
+
11
+ * Autocomplete: Typing "clo" will yield results that start with "clo", like "cloudy with a chance of meatballs".
12
+ * Autosuggest: Typing "clo" will yield results that contain (or start with) "clo", like "cloudy with a chance of meatballs" and "Jumping like Clowns".
13
+ * Both features are case insenitive.
14
+ * A CSS based view. You can override some style rules to force your look and feel.
15
+
16
+ == Prerequisites
17
+
18
+ You should have solr, sunspot and sunspot_rails ON and running.
19
+
20
+ http://outoftime.github.com/sunspot
21
+
22
+ == Installation
23
+
24
+ Download the plugin and place it under vendor/plugins.
25
+
26
+ Run the following rake task to copy the plugin's assets to your public directory. This will copy jquery.js and solr-autocompleter to your public/javascripts.
27
+
28
+ rake sunspot_autocomplete:copy_assets
29
+
30
+ == Usage
31
+
32
+ In your solr schema.xml, in addition to field types added by sunspot, add the following field types inside the <types> tag:
33
+
34
+ <fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
35
+ <analyzer type="index">
36
+ <tokenizer class="solr.KeywordTokenizerFactory"/>
37
+ <filter class="solr.LowerCaseFilterFactory"/>
38
+ <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
39
+ </analyzer>
40
+ <analyzer type="query">
41
+ <tokenizer class="solr.KeywordTokenizerFactory"/>
42
+ <filter class="solr.LowerCaseFilterFactory"/>
43
+ </analyzer>
44
+ </fieldType>
45
+ <fieldType name="autosuggest" class="solr.TextField" positionIncrementGap="100">
46
+ <analyzer type="index">
47
+ <tokenizer class="solr.LetterTokenizerFactory"/>
48
+ <filter class="solr.LowerCaseFilterFactory"/>
49
+ <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
50
+ </analyzer>
51
+ <analyzer type="query">
52
+ <tokenizer class="solr.LetterTokenizerFactory"/>
53
+ <filter class="solr.LowerCaseFilterFactory"/>
54
+ </analyzer>
55
+ </fieldType>
56
+
57
+ Also in your solr schema.xml, in addition to fields added by sunspot, add the following fields inside thw <fields> tag.
58
+
59
+ <dynamicField name="*_ac" type="autocomplete" indexed="true" stored="true"/>
60
+ <dynamicField name="*_as" type="autosuggest" indexed="true" stored="true"/>
61
+
62
+ 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.
63
+
64
+ class Post < ActiveRecord::Base
65
+ searchable do
66
+ autocomplete :post_title, :using => :title
67
+ autosuggest :post_author, :using => :author
68
+ end
69
+ end
70
+
71
+ In your view, Add the following script tags (in the given order) to be able to use the view helpers.
72
+
73
+ <script type="text/javascript" src="/javascripts/jquery.js"></script>
74
+ <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/Core.js"></script>
75
+ <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/AbstractManager.js"></script>
76
+ <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/managers/Manager.jquery.js"></script>
77
+ <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/Parameter.js"></script>
78
+ <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/ParameterStore.js"></script>
79
+ <script type="text/javascript" src="/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.js"></script>
80
+
81
+ Also, add the following stylesheet to use the basic style included. Alternatively, you can override those style rules to force your design's look and feel.
82
+
83
+ <link type="text/css" rel="stylesheet" href="/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.css" />
84
+
85
+ In your view, to create a text field with autocomplete:
86
+
87
+ <%=autocomplete_text_field "post", "title", "http://127.0.0.1:8983/solr/", "post_title"%>
88
+
89
+ And to create a text field with autosuggest:
90
+
91
+ <%=autosuggest_text_field "post", "author", "http://127.0.0.1:8983/solr/", "post_author"%>
92
+
93
+ You can view documentation for more advanced features of the helpers.
94
+
95
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "vinova_sunspot_autocomplete"
9
+ s.summary = ""
10
+ s.description = "A Rails plugin encapsulating autocompletion of HTML text input using Solr and Sunspot"
11
+ s.homepage = "http://github.com/vinova/sunspot_autocomplete"
12
+ s.authors = ["Haitham Mohammad"]
13
+ s.add_dependency("sunspot_rails")
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ desc 'Default: run unit tests.'
20
+ task :default => :test
21
+
22
+ desc 'Test the sunspot_autocomplete plugin.'
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.libs << 'lib'
25
+ t.libs << 'test'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = true
28
+ end
29
+
30
+ desc 'Generate documentation for the sunspot_autocomplete plugin.'
31
+ Rake::RDocTask.new(:rdoc) do |rdoc|
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = 'Sunspot Autocomplete'
34
+ rdoc.options << '--line-numbers' << '--inline-source'
35
+ rdoc.rdoc_files.include('README.rdoc')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.1
@@ -0,0 +1,126 @@
1
+ #= Sunspot Autocomplete
2
+ #
3
+ #Sunspot Autocomplete is a Rails plugin that lets you use Solr and Sunspot for handy autocompletion of your html text inputs.
4
+ #
5
+ #=== Features:
6
+ #
7
+ #* Autocomplete: Typing "clo" will yield results that start with "clo", like "cloudy with a chance of meatballs".
8
+ #* Autosuggest: Typing "clo" will yield results that contain (or start with) "clo", like "cloudy with a chance of meatballs" and "Jumping like Clowns".
9
+ #* Both features are case insenitive.
10
+ #* A CSS based view. You can override some style rules to force your look and feel.
11
+ #
12
+ #== Prerequisites
13
+ #
14
+ #You should have solr, sunspot and sunspot_rails ON and running.
15
+ #
16
+ #http://outoftime.github.com/sunspot
17
+ #
18
+ #== Installation
19
+ #
20
+ #Download the plugin and place it under vendor/plugins.
21
+ #
22
+ #Run the following rake task to copy the plugin's assets to your public directory. This will copy jquery.js and solr-autocompleter to your public/javascripts.
23
+ #
24
+ # rake sunspot_autocomplete:copy_assets
25
+ #
26
+ #== Usage
27
+ #
28
+ # In your solr schema.xml, in addition to field types added by sunspot, add the following field types inside the <types> tag:
29
+ #
30
+ # <fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
31
+ # <analyzer type="index">
32
+ # <tokenizer class="solr.KeywordTokenizerFactory"/>
33
+ # <filter class="solr.LowerCaseFilterFactory"/>
34
+ # <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
35
+ # </analyzer>
36
+ # <analyzer type="query">
37
+ # <tokenizer class="solr.KeywordTokenizerFactory"/>
38
+ # <filter class="solr.LowerCaseFilterFactory"/>
39
+ # </analyzer>
40
+ # </fieldType>
41
+ # <fieldType name="autosuggest" class="solr.TextField" positionIncrementGap="100">
42
+ # <analyzer type="index">
43
+ # <tokenizer class="solr.LetterTokenizerFactory"/>
44
+ # <filter class="solr.LowerCaseFilterFactory"/>
45
+ # <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
46
+ # </analyzer>
47
+ # <analyzer type="query">
48
+ # <tokenizer class="solr.LetterTokenizerFactory"/>
49
+ # <filter class="solr.LowerCaseFilterFactory"/>
50
+ # </analyzer>
51
+ # </fieldType>
52
+ #
53
+ #Also in your solr schema.xml, in addition to fields added by sunspot, add the following fields inside thw <fields> tag.
54
+ #
55
+ # <dynamicField name="*_ac" type="autocomplete" indexed="true" stored="true"/>
56
+ # <dynamicField name="*_as" type="autosuggest" indexed="true" stored="true"/>
57
+ #
58
+ #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.
59
+ #
60
+ # class Post < ActiveRecord::Base
61
+ # searchable do
62
+ # autocomplete :post_title, :using => :title
63
+ # autosuggest :post_author, :using => :author
64
+ # end
65
+ # end
66
+ #
67
+ #In your view, Add the following script tags (in the given order) to be able to use the view helpers.
68
+ #
69
+ # <script type="text/javascript" src="/javascripts/jquery.js"></script>
70
+ # <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/Core.js"></script>
71
+ # <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/AbstractManager.js"></script>
72
+ # <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/managers/Manager.jquery.js"></script>
73
+ # <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/Parameter.js"></script>
74
+ # <script type="text/javascript" src="/javascripts/solr-autocomplete/ajax-solr/core/ParameterStore.js"></script>
75
+ # <script type="text/javascript" src="/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.js"></script>
76
+ #
77
+ #Also, add the following stylesheet to use the basic style included. Alternatively, you can override those style rules to force your design's look and feel.
78
+ #
79
+ # <link type="text/css" rel="stylesheet" href="/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.css" />
80
+ #
81
+ #In your view, to create a text field with autocomplete:
82
+ #
83
+ # <%=autocomplete_text_field "post", "title", "http://127.0.0.1:8983/solr/", "post_title"%>
84
+ #
85
+ #And to create a text field with autosuggest:
86
+ #
87
+ # <%=autosuggest_text_field "post", "author", "http://127.0.0.1:8983/solr/", "post_author"%>
88
+ #
89
+ #You can view documentation for more advanced features of the helpers.
90
+ #
91
+ #
92
+ module AutocompleteViewHelpers
93
+
94
+ # Generates a text input using the given <code>object_name</code> and <code>method</code>.
95
+ # The generated text field autocompletes given <code>solr_url</code>: the url to your solr instance (e.g. http://127.0.0.1:8983/solr/)
96
+ # Autocompletion is fetching results that only begins with the given part of word.
97
+ # <code>autocomplete_field_name</code> is the unique field_name assigned in your model's searchable block
98
+ # <code>html_options</code> are regular HTML options like :class and :id
99
+ # <code>autocomplete_options</code> are advanced options for autocompletion http://docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions
100
+ def autocomplete_text_field(object_name, method, solr_url, autocomplete_field_name, html_options={}, autocomplete_options={})
101
+ autocomplete_stub object_name, method, solr_url, autocomplete_field_name, false, html_options, autocomplete_options
102
+ end
103
+
104
+ # Generates a text input using the given <code>object_name</code> and <code>method</code>.
105
+ # The generated text field autosuggests given <code>solr_url</code>: the url to your solr instance (e.g. http://127.0.0.1:8983/solr/)
106
+ # Autosuggestion is fetching results that begins with/ends with/contains the given part of word.
107
+ # <code>autocomplete_field_name</code> is the unique field_name assigned in your model's searchable block
108
+ # <code>html_options</code> are regular HTML options like :class and :id
109
+ # <code>autocomplete_options</code> are advanced options for autocompletion http://docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions
110
+ def autosuggest_text_field(object_name, method, solr_url, autocomplete_field_name, html_options={}, autocomplete_options={})
111
+ autocomplete_stub object_name, method, solr_url, autocomplete_field_name, true, html_options, autocomplete_options
112
+ end
113
+
114
+ private
115
+
116
+ def autocomplete_stub(object_name, method, url, field_name, suggest=false, html_options={}, autocomplete_options={})
117
+ ac_js_options = "{" + autocomplete_options.collect{|k,v| "#{k.to_s}: #{ v.kind_of?(Numeric) ? v : "'" + v + "'" }"}.join(" , ") + "}"
118
+ result = []
119
+ result << text_field(object_name, method, html_options)
120
+ result << "<script>$('##{object_name}_#{method}').#{suggest ? 'autosuggest' : 'autocomplete'}('#{url.ends_with?('/') ? url : url + '/'}', '#{field_name}', #{ac_js_options});</script>"
121
+ result.join " "
122
+ end
123
+
124
+ end
125
+
126
+ ActiveSupport.on_load(:action_view) { include AutocompleteViewHelpers }
@@ -0,0 +1,3 @@
1
+ require "sunspot"
2
+ require File.join(File.dirname(__FILE__), *%w{sunspot_autocomplete})
3
+ require File.join(File.dirname(__FILE__), *%w{autocomplete_view_helpers})
@@ -0,0 +1,38 @@
1
+ require "sunspot"
2
+
3
+ module Sunspot
4
+ module Type
5
+
6
+ #Auto Completion
7
+ class AutocompleteType < AbstractType
8
+ def indexed_name(name) #:nodoc:
9
+ "#{name}_ac"
10
+ end
11
+
12
+ def to_indexed(value) #:nodoc:
13
+ value.to_s if value
14
+ end
15
+
16
+ def cast(string) #:nodoc:
17
+ string
18
+ end
19
+ end
20
+
21
+ #Auto Suggestion
22
+ class AutosuggestType < AbstractType
23
+ def indexed_name(name) #:nodoc:
24
+ "#{name}_as"
25
+ end
26
+
27
+ def to_indexed(value) #:nodoc:
28
+ value.to_s if value
29
+ end
30
+
31
+ def cast(string) #:nodoc:
32
+ string
33
+ end
34
+ end
35
+
36
+
37
+ end
38
+ end
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{notch8_sunspot_autocomplete}
8
+ s.version = "2.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Haitham Mohammad"]
12
+ s.date = %q{2010-08-17}
13
+ s.description = %q{A Rails plugin encapsulating autocompletion of HTML text input using Solr and Sunspot}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "vendor/assets/javascripts/jquery.js",
24
+ "vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/AbstractManager.js",
25
+ "vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/Core.js",
26
+ "vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/Parameter.js",
27
+ "vendor/assets/javascripts/solr-autocomplete/ajax-solr/core/ParameterStore.js",
28
+ "vendor/assets/javascripts/solr-autocomplete/ajax-solr/managers/Manager.jquery.js",
29
+ "vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/indicator.gif",
30
+ "vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.css",
31
+ "vendor/assets/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.js",
32
+ "lib/autocomplete_view_helpers.rb",
33
+ "lib/sunspot_autocomplete.rb",
34
+ "lib/notch8_sunspot_autocomplete.rb",
35
+ "rdoc/classes/AutocompleteViewHelpers.html",
36
+ "rdoc/classes/Sunspot.html",
37
+ "rdoc/classes/Sunspot/Type.html",
38
+ "rdoc/classes/Sunspot/Type/AutocompleteType.html",
39
+ "rdoc/classes/Sunspot/Type/AutosuggestType.html",
40
+ "rdoc/created.rid",
41
+ "rdoc/files/README.html",
42
+ "rdoc/files/README_rdoc.html",
43
+ "rdoc/files/lib/autocomplete_view_helpers_rb.html",
44
+ "rdoc/files/lib/sunspot_autocomplete_rb.html",
45
+ "rdoc/fr_class_index.html",
46
+ "rdoc/fr_file_index.html",
47
+ "rdoc/fr_method_index.html",
48
+ "rdoc/index.html",
49
+ "rdoc/rdoc-style.css",
50
+ "tasks/tasks.rake",
51
+ "test/sunspot_autocomplete_test.rb",
52
+ "test/test_helper.rb",
53
+ "notch8_sunspot_autocomplete.gemspec"
54
+ ]
55
+ s.homepage = %q{http://github.com/notch8/sunspot_autocomplete}
56
+ s.rdoc_options = ["--charset=UTF-8"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.3.7}
59
+ s.summary = %q{}
60
+ s.test_files = [
61
+ "test/sunspot_autocomplete_test.rb",
62
+ "test/test_helper.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
+ s.add_runtime_dependency(%q<sunspot_rails>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<sunspot_rails>, [">= 0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<sunspot_rails>, [">= 0"])
76
+ end
77
+ end
78
+
@@ -0,0 +1,322 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: AutocompleteViewHelpers</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">AutocompleteViewHelpers</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/autocomplete_view_helpers_rb.html">
59
+ lib/autocomplete_view_helpers.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+ <div id="description">
76
+ <h1><a href="Sunspot.html">Sunspot</a> Autocomplete</h1>
77
+ <p>
78
+ <a href="Sunspot.html">Sunspot</a> Autocomplete is a Rails plugin that lets
79
+ you use Solr and <a href="Sunspot.html">Sunspot</a> for handy
80
+ autocompletion of your html text inputs.
81
+ </p>
82
+ <h3>Features:</h3>
83
+ <ul>
84
+ <li>Autocomplete: Typing &quot;clo&quot; will yield results that start with
85
+ &quot;clo&quot;, like &quot;cloudy with a chance of meatballs&quot;.
86
+
87
+ </li>
88
+ <li>Autosuggest: Typing &quot;clo&quot; will yield results that contain (or
89
+ start with) &quot;clo&quot;, like &quot;cloudy with a chance of
90
+ meatballs&quot; and &quot;Jumping like Clowns&quot;.
91
+
92
+ </li>
93
+ <li>Both features are case insenitive.
94
+
95
+ </li>
96
+ <li>A CSS based view. You can override some style rules to force your look and
97
+ feel.
98
+
99
+ </li>
100
+ </ul>
101
+ <h2>Prerequisites</h2>
102
+ <p>
103
+ You should have solr, sunspot and sunspot_rails ON and running.
104
+ </p>
105
+ <p>
106
+ <a
107
+ href="http://outoftime.github.com/sunspot">outoftime.github.com/sunspot</a>
108
+ </p>
109
+ <h2>Installation</h2>
110
+ <p>
111
+ Download the plugin and place it under vendor/plugins.
112
+ </p>
113
+ <p>
114
+ Run the following rake task to copy the plugin&#8216;s assets to your
115
+ public directory. This will copy jquery.js and solr-autocompleter to your
116
+ public/javascripts.
117
+ </p>
118
+ <pre>
119
+ rake sunspot_autocomplete:copy_assets
120
+ </pre>
121
+ <h2>Usage</h2>
122
+ <pre>
123
+ In your solr schema.xml, in addition to field types added by sunspot, add the following field types inside the &lt;types&gt; tag:
124
+
125
+ &lt;fieldType name=&quot;autocomplete&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;&gt;
126
+ &lt;analyzer type=&quot;index&quot;&gt;
127
+ &lt;tokenizer class=&quot;solr.KeywordTokenizerFactory&quot;/&gt;
128
+ &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
129
+ &lt;filter class=&quot;solr.EdgeNGramFilterFactory&quot; minGramSize=&quot;1&quot; maxGramSize=&quot;25&quot; /&gt;
130
+ &lt;/analyzer&gt;
131
+ &lt;analyzer type=&quot;query&quot;&gt;
132
+ &lt;tokenizer class=&quot;solr.KeywordTokenizerFactory&quot;/&gt;
133
+ &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
134
+ &lt;/analyzer&gt;
135
+ &lt;/fieldType&gt;
136
+ &lt;fieldType name=&quot;autosuggest&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;&gt;
137
+ &lt;analyzer type=&quot;index&quot;&gt;
138
+ &lt;tokenizer class=&quot;solr.LetterTokenizerFactory&quot;/&gt;
139
+ &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
140
+ &lt;filter class=&quot;solr.EdgeNGramFilterFactory&quot; minGramSize=&quot;1&quot; maxGramSize=&quot;25&quot; /&gt;
141
+ &lt;/analyzer&gt;
142
+ &lt;analyzer type=&quot;query&quot;&gt;
143
+ &lt;tokenizer class=&quot;solr.LetterTokenizerFactory&quot;/&gt;
144
+ &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
145
+ &lt;/analyzer&gt;
146
+ &lt;/fieldType&gt;
147
+ </pre>
148
+ <p>
149
+ Also in your solr schema.xml, in addition to fields added by sunspot, add
150
+ the following fields inside thw &lt;fields&gt; tag.
151
+ </p>
152
+ <pre>
153
+ &lt;dynamicField name=&quot;*_ac&quot; type=&quot;autocomplete&quot; indexed=&quot;true&quot; stored=&quot;true&quot;/&gt;
154
+ &lt;dynamicField name=&quot;*_as&quot; type=&quot;autosuggest&quot; indexed=&quot;true&quot; stored=&quot;true&quot;/&gt;
155
+ </pre>
156
+ <p>
157
+ To be able to autocomplete/autosuggest a model&#8216;s attribute, call
158
+ &#8216;autocomplete&#8217;/&#8217;autosuggest&#8217; on it in its
159
+ &#8216;searchable&#8217; block. the field_name used (post_title and
160
+ post_author in the following example) must be unique across all your
161
+ autocomplete fields of the application.
162
+ </p>
163
+ <pre>
164
+ class Post &lt; ActiveRecord::Base
165
+ searchable do
166
+ autocomplete :post_title, :using =&gt; :title
167
+ autosuggest :post_author, :using =&gt; :author
168
+ end
169
+ end
170
+ </pre>
171
+ <p>
172
+ In your view, Add the following script tags (in the given order) to be able
173
+ to use the view helpers.
174
+ </p>
175
+ <pre>
176
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/jquery.js&quot;&gt;&lt;/script&gt;
177
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/solr-autocomplete/ajax-solr/core/Core.js&quot;&gt;&lt;/script&gt;
178
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/solr-autocomplete/ajax-solr/core/AbstractManager.js&quot;&gt;&lt;/script&gt;
179
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/solr-autocomplete/ajax-solr/managers/Manager.jquery.js&quot;&gt;&lt;/script&gt;
180
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/solr-autocomplete/ajax-solr/core/Parameter.js&quot;&gt;&lt;/script&gt;
181
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/solr-autocomplete/ajax-solr/core/ParameterStore.js&quot;&gt;&lt;/script&gt;
182
+ &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.js&quot;&gt;&lt;/script&gt;
183
+ </pre>
184
+ <p>
185
+ Also, add the following stylesheet to use the basic style included.
186
+ Alternatively, you can override those style rules to force your
187
+ design&#8216;s look and feel.
188
+ </p>
189
+ <pre>
190
+ &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;/javascripts/solr-autocomplete/jquery-autocomplete/jquery.autocomplete.css&quot; /&gt;
191
+ </pre>
192
+ <p>
193
+ In your view, to create a text field with autocomplete:
194
+ </p>
195
+ <pre>
196
+ &lt;%=autocomplete_text_field &quot;post&quot;, &quot;title&quot;, &quot;http://127.0.0.1:8983/solr/&quot;, &quot;post_title&quot;%&gt;
197
+ </pre>
198
+ <p>
199
+ And to create a text field with autosuggest:
200
+ </p>
201
+ <pre>
202
+ &lt;%=autosuggest_text_field &quot;post&quot;, &quot;author&quot;, &quot;http://127.0.0.1:8983/solr/&quot;, &quot;post_author&quot;%&gt;
203
+ </pre>
204
+ <p>
205
+ You can view documentation for more advanced features of the helpers.
206
+ </p>
207
+
208
+ </div>
209
+
210
+
211
+ </div>
212
+
213
+ <div id="method-list">
214
+ <h3 class="section-bar">Methods</h3>
215
+
216
+ <div class="name-list">
217
+ <a href="#M000001">autocomplete_text_field</a>&nbsp;&nbsp;
218
+ <a href="#M000002">autosuggest_text_field</a>&nbsp;&nbsp;
219
+ </div>
220
+ </div>
221
+
222
+ </div>
223
+
224
+
225
+ <!-- if includes -->
226
+
227
+ <div id="section">
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+ <!-- if method_list -->
237
+ <div id="methods">
238
+ <h3 class="section-bar">Public Instance methods</h3>
239
+
240
+ <div id="method-M000001" class="method-detail">
241
+ <a name="M000001"></a>
242
+
243
+ <div class="method-heading">
244
+ <a href="#M000001" class="method-signature">
245
+ <span class="method-name">autocomplete_text_field</span><span class="method-args">(object_name, method, solr_url, autocomplete_field_name, html_options={}, autocomplete_options={})</span>
246
+ </a>
247
+ </div>
248
+
249
+ <div class="method-description">
250
+ <p>
251
+ Generates a text input using the given <tt>object_name</tt> and
252
+ <tt>method</tt>. The generated text field autocompletes given
253
+ <tt>solr_url</tt>: the url to your solr instance (e.g. <a
254
+ href="http://127.0.0.1:8983/solr">127.0.0.1:8983/solr</a>/) Autocompletion
255
+ is fetching results that only begins with the given part of word.
256
+ <tt>autocomplete_field_name</tt> is the unique field_name assigned in your
257
+ model&#8216;s searchable block <tt>html_options</tt> are regular HTML
258
+ options like :class and :id <tt>autocomplete_options</tt> are advanced
259
+ options for autocompletion <a
260
+ href="http://docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions">docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions</a>
261
+ </p>
262
+ <p><a class="source-toggle" href="#"
263
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
264
+ <div class="method-source-code" id="M000001-source">
265
+ <pre>
266
+ <span class="ruby-comment cmt"># File lib/autocomplete_view_helpers.rb, line 100</span>
267
+ 100: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">autocomplete_text_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">solr_url</span>, <span class="ruby-identifier">autocomplete_field_name</span>, <span class="ruby-identifier">html_options</span>={}, <span class="ruby-identifier">autocomplete_options</span>={})
268
+ 101: <span class="ruby-identifier">autocomplete_stub</span> <span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">solr_url</span>, <span class="ruby-identifier">autocomplete_field_name</span>, <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">html_options</span>, <span class="ruby-identifier">autocomplete_options</span>
269
+ 102: <span class="ruby-keyword kw">end</span>
270
+ </pre>
271
+ </div>
272
+ </div>
273
+ </div>
274
+
275
+ <div id="method-M000002" class="method-detail">
276
+ <a name="M000002"></a>
277
+
278
+ <div class="method-heading">
279
+ <a href="#M000002" class="method-signature">
280
+ <span class="method-name">autosuggest_text_field</span><span class="method-args">(object_name, method, solr_url, autocomplete_field_name, html_options={}, autocomplete_options={})</span>
281
+ </a>
282
+ </div>
283
+
284
+ <div class="method-description">
285
+ <p>
286
+ Generates a text input using the given <tt>object_name</tt> and
287
+ <tt>method</tt>. The generated text field autosuggests given
288
+ <tt>solr_url</tt>: the url to your solr instance (e.g. <a
289
+ href="http://127.0.0.1:8983/solr">127.0.0.1:8983/solr</a>/) Autosuggestion
290
+ is fetching results that begins with/ends with/contains the given part of
291
+ word. <tt>autocomplete_field_name</tt> is the unique field_name assigned in
292
+ your model&#8216;s searchable block <tt>html_options</tt> are regular HTML
293
+ options like :class and :id <tt>autocomplete_options</tt> are advanced
294
+ options for autocompletion <a
295
+ href="http://docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions">docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions</a>
296
+ </p>
297
+ <p><a class="source-toggle" href="#"
298
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
299
+ <div class="method-source-code" id="M000002-source">
300
+ <pre>
301
+ <span class="ruby-comment cmt"># File lib/autocomplete_view_helpers.rb, line 110</span>
302
+ 110: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">autosuggest_text_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">solr_url</span>, <span class="ruby-identifier">autocomplete_field_name</span>, <span class="ruby-identifier">html_options</span>={}, <span class="ruby-identifier">autocomplete_options</span>={})
303
+ 111: <span class="ruby-identifier">autocomplete_stub</span> <span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">solr_url</span>, <span class="ruby-identifier">autocomplete_field_name</span>, <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">html_options</span>, <span class="ruby-identifier">autocomplete_options</span>
304
+ 112: <span class="ruby-keyword kw">end</span>
305
+ </pre>
306
+ </div>
307
+ </div>
308
+ </div>
309
+
310
+
311
+ </div>
312
+
313
+
314
+ </div>
315
+
316
+
317
+ <div id="validator-badges">
318
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
319
+ </div>
320
+
321
+ </body>
322
+ </html>