-
Notifications
You must be signed in to change notification settings - Fork 81
Using Storytime's Post Search
You can search Storytime post types through search adapters available through Storytime. By default, Storytime.search_adapter will use the Postgres search adapter.
# config/initializers/storytime.rb
Storytime.configure do |config|
# Search adapter to use for searching through Storytime Posts or
# Post subclasses. Options for the search adapter include:
# Storytime::PostgresSearchAdapter, Storytime::MysqlSearchAdapter,
# Storytime::MysqlFulltextSearchAdapter, Storytime::Sqlite3SearchAdapter
config.search_adapter = Storytime::PostgresSearchAdapter
end
If you are using a database other than Postgres be sure to change the search_adapter type in your Storytime initializer. Available search adapters include support for Postgres, MySql, MySql Fulltext (MySql v5.6.4+), and Sqlite3.
To search all Storytime post types pass the search string to the adapter's search function:
Storytime.search_adapter.search("search terms")
To search a specific Storytime post type pass the search string along with the post type to the adapter's search function:
Storytime.search_adapter.search("search terms", Storytime::BlogPost)
The ability to search through post types is also available in Storytime::Posts#Index.
http://localhost:3000/posts?search=search_terms
To limit the search results to a particular post type, pass the specific post type as the parameter type
.
http://localhost:3000/posts?search=search_terms&type=blog_post