Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TrestleAdmin/trestle-search
Search plugin for the Trestle admin framework
https://github.com/TrestleAdmin/trestle-search
Last synced: 3 months ago
JSON representation
Search plugin for the Trestle admin framework
- Host: GitHub
- URL: https://github.com/TrestleAdmin/trestle-search
- Owner: TrestleAdmin
- License: lgpl-3.0
- Created: 2016-09-11T23:36:48.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-07-03T11:49:13.000Z (4 months ago)
- Last Synced: 2024-07-22T14:46:59.048Z (4 months ago)
- Language: Ruby
- Homepage: https://trestle.io
- Size: 803 KB
- Stars: 28
- Watchers: 2
- Forks: 12
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Trestle Search (trestle-search)
[![RubyGem](https://img.shields.io/gem/v/trestle-search.svg?style=flat&colorB=4065a9)](https://rubygems.org/gems/trestle-search)
[![Build Status](https://img.shields.io/github/actions/workflow/status/TrestleAdmin/trestle-search/rspec.yml?style=flat)](https://github.com/TrestleAdmin/trestle-search/actions)
[![Coveralls](https://img.shields.io/coveralls/TrestleAdmin/trestle-search.svg?style=flat)](https://coveralls.io/github/TrestleAdmin/trestle-search)> Search plugin for the Trestle admin framework
## Getting Started
These instructions assume you have a working Trestle application. To integrate trestle-search, first add it to your application's Gemfile:
```ruby
gem 'trestle-search'
```Run `bundle install`, and then restart your Rails server.
To enable search capabilities within an admin resource, define a `search` block:
```ruby
Trestle.resource(:articles) do
search do |query|
if query
Article.where("title ILIKE ?", "%#{query}%")
else
Article.all
end
end
end
```The search block accepts one or two parameters; the first is the string value of the search query. The second, optional parameter is the full `params` hash. The block should return a chainable scope.
The search block overrides the default (or custom) `collection` block. However the original collection block can be called to avoid redefining scopes. For example:
```ruby
Trestle.resource(:articles) do
collection do
Article.order(created_at: :desc).includes(:author)
endsearch do |q|
q ? collection.where("title ILIKE ?", "%#{q}%") : collection
end
end
```## Integration Examples
1. [ActiveRecord (ILIKE)](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-ActiveRecord-(ILIKE))
2. [PgSearch](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-PgSearch)
3. [Chewy](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-Chewy)
4. [Sunspot](https://github.com/TrestleAdmin/trestle-search/wiki/Integration-with-Sunspot)## License
The gem is available as open source under the terms of the [LGPLv3 License](https://opensource.org/licenses/LGPL-3.0).