Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Wed Oct 07 13:41:53 -0700 2009 | |
| |
.gitmodules | Thu May 07 12:46:17 -0700 2009 | |
| |
History.txt | Mon Nov 16 15:08:03 -0800 2009 | |
| |
LICENSE | Fri May 22 10:31:36 -0700 2009 | |
| |
README.rdoc | Thu Dec 10 13:00:27 -0800 2009 | |
| |
Rakefile | Tue Jul 14 10:20:53 -0700 2009 | |
| |
TODO | Mon Dec 14 12:52:35 -0800 2009 | |
| |
VERSION.yml | Tue Nov 24 13:12:39 -0800 2009 | |
| |
bin/ | Thu Nov 05 12:40:22 -0800 2009 | |
| |
lib/ | Mon Dec 14 12:52:35 -0800 2009 | |
| |
log/ | Mon Dec 01 16:36:17 -0800 2008 | |
| |
pages - 8ad60f3 | Thu Nov 05 15:30:22 -0800 2009 | |
| |
script/ | Tue Jul 14 10:20:53 -0700 2009 | |
| |
solr/ | Thu Nov 05 13:21:51 -0800 2009 | |
| |
spec/ | Mon Dec 14 12:52:35 -0800 2009 | |
| |
sunspot.gemspec | Sun Nov 29 11:23:03 -0800 2009 | |
| |
tasks/ | Sun Nov 29 14:27:03 -0800 2009 | |
| |
templates/ | Thu Sep 03 06:50:53 -0700 2009 |
Sunspot
Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine. Sunspot is built on top of the solr-ruby library, which provides a low-level interface for Solr interaction; Sunspot provides a simple, intuitive, expressive DSL backed by powerful features for indexing objects and searching for them.
Sunspot is designed to be easily plugged in to any ORM, or even non-database-backed objects such as the filesystem.
This README is intended as a quick primer on what Sunspot is capable of; for detailed treatment of Sunspot’s full feature range, check out the wiki: wiki.github.com/outoftime/sunspot
Features:
- Define indexing strategy for each searchable class using intuitive block-based API
- Clean separation between keyword-searchable fields and fields for scoping/ordering
- Define fields based on existing attributes or "virtual fields" for custom indexing
- Indexes each object’s entire superclass hierarchy, for easy searching for all objects inheriting from a parent class
- Intuitive DSL for scoping searches, with all the usual boolean operators available
- Intuitive interface for requesting facets on indexed fields
- Extensible adapter architecture for easy integration of other ORMs or non-model classes
- Refine search using field facets, date range facets, or ultra-powerful query facets
- Full compatibility with will_paginate
- Ordering by field value, relevance, geographical distance, or random
Installation
gem install sunspot
In order to start the packaged Solr installation, run:
sunspot-solr start -- [-d /path/to/data/directory] [-p port] [-s path/to/solr/home] [--pid-dir=path/to/pid/dir]
If you don’t specify a data directory, your Solr index will be stored in your operating system’s temporary directory.
If you specify a solr home, the directory must contain a conf directory, which should contain at least schema.xml and solrconfig.xml. Be sure to copy the schema.xml out of the Sunspot gem’s solr/solr/conf directory. Sunspot relies on the field name patterns defined in the packaged schema.xml, so those cannot be modified.
You can also run your own instance of Solr wherever you’d like; just copy the solr/config/schema.xml file out of the gem’s solr into your installation. You can change the URL at which Sunspot accesses Solr with:
Sunspot.config.solr.url = 'http://solr.my.host:9818/solr'
Rails Integration
The Sunspot::Rails plugin makes integrating Sunspot into Rails drop-in easy.
Using Sunspot
Define an index:
class Post
#...
end
Sunspot.setup(Post) do
text :title, :body
string :author_name
integer :blog_id
integer :category_ids
float :average_rating, :using => :ratings_average
time :published_at
string :sort_title do
title.downcase.sub(/^(an?|the)\W+/, ''/) if title = self.title
end
end
See Sunspot.setup for more information.
Note that in order for a class to be searchable, it must have an adapter registered for itself or one of its subclasses. Adapters allow Sunspot to load objects out of persistent storage, and to determine their primary key for indexing. Sunspot::Rails comes with an adapter for ActiveRecord objects, but for other types of models you will need to define your own. See Sunspot::Adapters for more information.
Search for objects:
search = Sunspot.search Post do
keywords 'great pizza'
with :author_name, 'Mark Twain'
with(:blog_id).any_of [2, 14]
with(:category_ids).all_of [4, 10]
with(:published_at).less_than Time.now
any_of do
with(:expired_at).greater_than(Time.now)
with(:expired_at, nil)
end
without :title, 'Bad Title'
without bad_instance # specifically exclude this instance from results
paginate :page => 3, :per_page => 15
order_by :average_rating, :desc
facet :blog_id
end
See Sunspot.search for more information.
Get data from search:
search.results search.total search.page search.per_page search.facet(:blog_id)
About the API documentation
All of the methods documented in the RDoc are considered part of Sunspot’s public API. Methods that are not part of the public API are documented in the code, but excluded from the RDoc. If you find yourself needing to access methods that are not part of the public API in order to do what you need, please contact me so I can rectify the situation!
Dependencies
- solr-ruby
- daemons
- Java 1.5+
Sunspot has been tested with MRI 1.8.6 and 1.8.7, REE 1.8.6, YARV 1.9.1, and JRuby 1.2.0
Bugs
Please submit bug reports to outoftime.lighthouseapp.com/projects/20339-sunspot
Contribution Guidelines
Contributions are very welcome - both new features, enhancements, and bug fixes. Bug reports with a failing regression test are also lovely. In order to keep the contribution process as organized and smooth as possible, please follow these guidelines:
- Contributions should be submitted via Sunspot’s Lighthouse account, with an attached git patch. See below for how to create a git patch.
- Patches should not make any changes to the gemspec task other than adding/removing dependencies (e.g., changing the name, version, email, description, etc.)
- Patches should not include any changes to the gemspec itself.
- Document any new methods, options, arguments, etc.
- Write tests.
- As much as possible, follow the coding and testing styles you see in existing code. One could accuse me of being nitpicky about this, but consistent code is easier to read, maintain, and enhance.
- Don’t make any massive changes to the structure of library or test code. If you think something needs a huge refactor or rearrangement, shoot me a message; trying to apply that kind of patch without warning opens the door to a world of conflict hurt.
Here’s how to create a Git patch - assuming you’re pulling from the canonical Sunspot repository at `upstream`:
git fetch upstream git format-patch --stdout upstream/master.. > my-awesome.patch
Further Reading
- Sunspot Discussion: groups.google.com/group/ruby-sunspot
- IRC: #sunspot-ruby @ Freenode
- Posts about Sunspot from my tumblog: outofti.me/tagged/sunspot
- Read about it on Linux Magazine: www.linux-mag.com/id/7341
Contributors
- Mat Brown (mat@patch.com)
- Peer Allan (peer.allan@gmail.com)
- Dmitriy Dzema (dima@dzema.name)
- Benjamin Krause (bk@benjaminkrause.com)
- Marcel de Graaf (marcel@slashdev.nl)
- Brandon Keepers (brandon@opensoul.org)
- Peter Berkenbosch (peterberkenbosch@me.com)
- Brian Atkinson
- Tom Coleman (tom@thesnail.org)
- Matt Mitchell (goodieboy@gmail.com)
License
Sunspot is distributed under the MIT License, copyright © 2008-2009 Mat Brown







