As today (5 March 2007) the RubyForge page says:
This project is considered dormant. Please do not use. It may be reactivated in the future.
A search engine that can be added to any Rails application. See also http://rubyforge.org/projects/searchgenerator/
gem install search_generatorscript/generate search SearchIf you still want the .tgz or .zip files, feel free to download them:
There is a problem with the generated code, the method simple_search in the
search_controller at line 57 does not check for warnings, consequently it
returns matches on all your indexed data. To fix it, go to line 57 in
search_controller.rb and replace:
if search_results.contains_matches then
with:
if search_results.contains_matches && search_results.warnings.empty? then
Note: if you pass the --inspect flag, the search system is not installed.
search – a search engine that can be added to any Rails application
search [Search name] [options]
Good names, anything that means search would be good. Search, Forage, Frisk
or Shakedown.
search has an additional option —inspect which will traverse your Model
objects and tell you which ones could be made searchable
This generator integrates the SimpleSearch search engine into a rails
application. In addition, once configured for you site, it provides an Open
Search (http://opensearch.a9.com/) compatible interface.
Included:
* a Controller to manage search request * Views to customize for your Model objects - regular html results - Open Search RSS style results * an indexer to run periodically against your data to keep the search indexes up to date. * a README on the additional hand coded tasks to integrate the search engine with your applicationThis will create a basic search engine framework for you to customize for your
site.
This will report which ones of your Model classes could be made searchable.
After the search engine has been generated, there are still tasks to fully
integrate the search engine into your site.
execute:
script/generate search Search —inspectThis will report which of your models can be made searchable. Feel free to
run it many times.
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
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.
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.
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.
A ‘very’ basic layout/search.rhtml is installed that shows the basic results.
This should be customized for your site.
Two new views have been added to your rails application.
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.
—————————————————————
Question
—————————————————————
How does a _partial.rhtml file look?
Where should the _partial file be located? In the search directory?
—————————————————————
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.
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.
Extensions:
There are a variety of open issues in the rubyforge forums:
http://rubyforge.org/forum/forum.php?forum_id=2826
including how to paginate, search by class and dealing with rss issues.
Solution to pagination problem:
http://rubyforge.org/forum/forum.php?thread_id=3550&forum_id=2826
category: Generator
Q: I keep trying to create a partial file for my different results but it doesn’t seem to find them. I have a class called user, so I make _user.rhtml and put it in the views/search/ folder but it still uses the generic one…
I would also like to have the users be able to choose which catagory to search through. Like, just new items or just people. Is there a way to specify that? Any help?
Q: I am having the same issue as Exar, where the partials are not getting “picked up”. Any advice?
A: I found out what was going on. The generic display is being shown if ANY errors are found, not just the partial not being there. If there is an error in your partial, it will display the generic one. All I had to do was go through all my partials and fix them and the problem went away.
- Gregg Hanson www.TheGregg.com
Q: Yes, the same thing happened to me…so, I’m just getting the resulting ids and displaying them in a table (different classes with habtm relationship). Now, my problem is different. I am searching thru the content of some files uploaded to the db. Some of them are not working properly (just pdf’s, not so big), I don’t know if they’re not being indexed or the searcher is not finding the search terms. Anyone has an explanation of why this happens?
Q: Now that I have this working, I am trying to make an “advanced search” feature. Is there anyway to search through specific models or is it all or nothing?
- Gregg Hanson www.TheGregg.com
Q: How do I set a specific number of matches to return? I presume I am missing something simple.
See also
As today (5 March 2007) the RubyForge page says:
This project is considered dormant. Please do not use. It may be reactivated in the future.
A search engine that can be added to any Rails application. See also http://rubyforge.org/projects/searchgenerator/
gem install search_generatorscript/generate search SearchIf you still want the .tgz or .zip files, feel free to download them:
There is a problem with the generated code, the method simple_search in the
search_controller at line 57 does not check for warnings, consequently it
returns matches on all your indexed data. To fix it, go to line 57 in
search_controller.rb and replace:
if search_results.contains_matches then
with:
if search_results.contains_matches && search_results.warnings.empty? then
Note: if you pass the --inspect flag, the search system is not installed.
search – a search engine that can be added to any Rails application
search [Search name] [options]
Good names, anything that means search would be good. Search, Forage, Frisk
or Shakedown.
search has an additional option —inspect which will traverse your Model
objects and tell you which ones could be made searchable
This generator integrates the SimpleSearch search engine into a rails
application. In addition, once configured for you site, it provides an Open
Search (http://opensearch.a9.com/) compatible interface.
Included:
* a Controller to manage search request * Views to customize for your Model objects - regular html results - Open Search RSS style results * an indexer to run periodically against your data to keep the search indexes up to date. * a README on the additional hand coded tasks to integrate the search engine with your applicationThis will create a basic search engine framework for you to customize for your
site.
This will report which ones of your Model classes could be made searchable.
After the search engine has been generated, there are still tasks to fully
integrate the search engine into your site.
execute:
script/generate search Search —inspectThis will report which of your models can be made searchable. Feel free to
run it many times.
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
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.
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.
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.
A ‘very’ basic layout/search.rhtml is installed that shows the basic results.
This should be customized for your site.
Two new views have been added to your rails application.
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.
—————————————————————
Question
—————————————————————
How does a _partial.rhtml file look?
Where should the _partial file be located? In the search directory?
—————————————————————
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.
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.
Extensions:
There are a variety of open issues in the rubyforge forums:
http://rubyforge.org/forum/forum.php?forum_id=2826
including how to paginate, search by class and dealing with rss issues.
Solution to pagination problem:
http://rubyforge.org/forum/forum.php?thread_id=3550&forum_id=2826
category: Generator
Q: I keep trying to create a partial file for my different results but it doesn’t seem to find them. I have a class called user, so I make _user.rhtml and put it in the views/search/ folder but it still uses the generic one…
I would also like to have the users be able to choose which catagory to search through. Like, just new items or just people. Is there a way to specify that? Any help?
Q: I am having the same issue as Exar, where the partials are not getting “picked up”. Any advice?
A: I found out what was going on. The generic display is being shown if ANY errors are found, not just the partial not being there. If there is an error in your partial, it will display the generic one. All I had to do was go through all my partials and fix them and the problem went away.
- Gregg Hanson www.TheGregg.com
Q: Yes, the same thing happened to me…so, I’m just getting the resulting ids and displaying them in a table (different classes with habtm relationship). Now, my problem is different. I am searching thru the content of some files uploaded to the db. Some of them are not working properly (just pdf’s, not so big), I don’t know if they’re not being indexed or the searcher is not finding the search terms. Anyone has an explanation of why this happens?
Q: Now that I have this working, I am trying to make an “advanced search” feature. Is there anyway to search through specific models or is it all or nothing?
- Gregg Hanson www.TheGregg.com
Q: How do I set a specific number of matches to return? I presume I am missing something simple.
See also