-
Notifications
You must be signed in to change notification settings - Fork 0
/
README_SEARCH
107 lines (73 loc) · 3.91 KB
/
README_SEARCH
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
== Installation
After the search engine has been generated, there are still tasks to
fully integrate the search engine into your site.
=== Inspect
execute:
script/generate search Search --inspect
This will report which of your models can be made searchable. Feel
free to run it many times.
=== Models
In each of your Models in which you want to have the content
searched, and are ActiveRecord descendants, you need to add a
require_dependency "search_system". Then you are able to invoke the
class method 'make_searchable' with an Array of field symbols.
For example:
require_dependency "search_system"
class Article < ActiveRecord::Base
make_searchable [ :title, :author, :content ]
end
=== Configuration
A default configuration file 'search.yml' in installed in your
application config directory. It should work as-is, but if you want
to move the simple search index file to a different location or
rename it, feel free to do so. Just be aware that the index file
must be relative to RAILS_ROOT.
Yes, if you look at the index file it does appear that other
backends could be available, but for now, there are no other search
backends besides SimpleSearch.
=== Index the data
Once your Models class are updated with make_searchable you'll need
to run script/indexer to crawl through your data and create the
index that is used to search the data.
Currently, this index is not automatically created and any new
content that is added to the database will not get indexed. You
should have cron, or a scheduled task run the indexer periodically
to keep your index in sync with your data.
=== Routes
Add the following lines to your config/routes.rb to hook in search
# allow for searching view the route
map.connect 'search/:search_terms/:count', :controller => 'search', :action => 'index', :count => '-1'
# allow for Open Search RSS feeds searching
map.connect 'rss/opensearch/description.xml', :controller => 'search', :action => 'description'
map.connect 'rss/opensearch/:search_terms/:count', :controller => 'search', :action => 'rss', :count => '-1'
Remember to put these routes before the default route or you will
get errors.
=== Layouts
A 'very' basic layout/search.rhtml is installed that shows the basic
results. This should be customized for your site.
=== Views
Two new views have been added to your rails application.
1. Search
This view should be customized for your site so that the search
results fit in well with your site. The default _partial
template that exists will render out a generic table showing all
the fields and their values for the search results. You should
customize the index.rhtml file to integrate with your site, and
you should create a _partial.rhtml for each Model that you could
have search results for.
That is, if you have an application with an Article Model, you
should create a _article.rhtml file in this view to render out
the results of your search that are of Article class.
The generic index.rhtml that is present will automatically use
the appropriate _partial.rhtml file based upon the class name if
it is present.
2. Open Search
This view is to return results in the format of OpenSearch RSS
(http://opensearch.a9.com/spec/opensearchrss/1.0/). This
combined with the rss/opensearch Routes above and the
description.rxml file found in this view should provide you with
an OpenSearch-able site.
Again, you should create a _partial.rhtml file in this directory
for each Model you have that can return search results.
Also, the description.xml file should be configure with your
sites information.