Searchable Plugin

Searchable Plugin

The Searchable Plugin aims to provide rich search features to Grails applications with minimum effort, and still give you power and flexibility when you need it.

It is built on the fantastic Compass Search Engine Framework and Lucene and has the same license as Grails (Apache 2).

The roadmap and issues are tracked in JIRA.

Intially the plugin will focus on exposing Groovy domain models.

Support for Java domain classes is on the roadmap but until then, if your Grails application uses Java domain classes, using Compass's native annotations or XML mapping config and setting up Compass yourself may be a better fit at this stage.

Features

The plugin:

  • Detects searchable classes and maps them to the search index
  • Performs a bulk index of all searchable class instances in the database
  • Automatically synchronises any changes made through GORM/hibernate with the index
  • Adds domain class methods for easy class-based searching and index management
  • Provides a SearchableService for easy application-wide searching and index management
  • Provides a SearchableController for testing queries and demonstrating the Searchable Plugin API
  • Provides a configuration mechanism to enable/disable features and override default behavoir if necessary

Quick start

Install the plugin

grails install-plugin searchable

Define Searchable classes

Add a static searchable property in the domain classes you need to be searchable, for example:

/**
 * A blog post
 */
class Post {
    static searchable = true             // maps and indexes Post instances with default rules
    static hasMany = [comments: Comment] // Comment could also be "searchable"
    User author                          // User could also be "searchable"
    String category, title, post
    Date postDate
}

(There are more ways to map your classes to the search index, but this is enough for now.)

Try it!

Fire up your app... during startup the plugin will build the search index all for searchable class instances in your database.

Navigate to http://localhost:8080/YOUR-APP-NAME-HERE/searchable, and try a few queries. Here's a screenshot from my own app:

You just made your domain searchable!

So far so good, what now?

Hack the controller and view to your own tastes.

Find what you're looking for with the simple and powerful search API methods.

Take the mapping between your classes and the search index into your own hands.

See how to manage the index yourself if you need to; normally you do not, since changes made through Hibernate/GORM are mirrored to the index automatically.

Override defaults and more with configuration: for example, you could increase the search result page size from 10 to 20.

Trouble-shoot problems with the debugging tips and FAQ.



Happy searching!

Labels