Searchlight does its best to use semantic versioning.
Allow callable search targets, thanks to Adam Nowak.
Two major releases in two days!? Well, I thought of another good, but breaking, change. To the major version bump, Robin!
Inputs generated using ActionView
forms are now named after your search form. Eg, the form for 'UserSearch' will submit parameters under 'user_search', not just 'search'. This makes the code more standard and namespaces the form, in case, eg, you want to have two forms on the same page.
Note that to upgrade, Rails users will need to change references to params[:search]
to something like params[:user_search]
(depending on name of the search class).
Now with fewer features! :D
ORM "adapters", which were never actually necessary, have been removed. They required lots of hackery, added test dependencies, and sometimes introduced weird bugs. All that just so that if you said your class searches :first_name, :last_name
, we could save you from typing simple search methods like:
def search_first_name
search.where(first_name: first_name)
end
You can easily save yourself this effort with something like:
%w[name address pant_size].each do |attr|
define_method("search_#{attr}") do
search.where(:"#{attr}" => attr)
end
end
...and you'll get much saner backtraces if anything goes wrong.
ActiveRecord users: note that with this change, you'll need to update your search_on
calls to return an ActiveRecord::Relation
so that, if no options are passed, you don't return the model class itself. Eg, instead of search_on User
, do search_on User.all
for Rails > 4 or search_on User.scoped
for Rails < 4.
With this change, Searchlight no longer has any ties to any ORM, but can still work with any of them that use method chaining. Hooray!
Add license to gemspec, thanks to notice from Benjamin Fleischer - see his blog post
New Mongoid adapter, thanks to iliabylich.
options
method only returns those that map to search methods (notattr_accessor
type values)- Previously,
searches :name
in a class with anActiveRecord
target would always trigger theActiveRecord
adapter to definesearches_name
assearch.where(name: name)
. Now it first checks whethername
is a column on the model, and if not, defines the method to raise an error.
Fix bug introduced in v1.2: setting defaults in initialize
did not add them to the options hash, which meant they weren't used in searches.
Gracefully handle being given explicit nil
in initialization instead of options hash or empty arguments
Bugfix for v1.2.0 - screen out from options any collections containing only blank values
- Provide
options
accessor that returns all options considered non-blank - Slightly nicer errors when passing invalid options
ActiveRecord adapter ensures that searches return a relation, even if no options are given
- If no search target is given, search class attempts to guess based on its own name
- All errors that can be raise extend
Searchlight::Error
- Better testing
- Still more documentation!
Bugfix for ActiveRecord adapter
- Clean up dynamic module inclusion
- Better
ActionView
andActiveRecord
adapters - Better error messages
- More documentation
Experimental and unstable, Searchlight totters onto the scene and takes its first wide-eyed look at the world.
It is adorable.