Last updated by diptirmaya 3 years ago

Quick start

Install the plugin

JDK 1.5+ users:

grails install-plugin searchable

JDK 1.4 users:

grails install-plugin searchable14

Define Searchable classes

Add a static searchable property to the domain classes you want to be stored in the search index, for example:

class Post {
    static searchable = true              // <-- Make Posts searchable
    static hasMany = [comments: Comment]
    String category, title, post
    User author
    Date createdAt

class Comment {
    static searchable = true              // <-- Make Comments searchable
    static belongsTo = [post: Post]
    String comment
    Post post
    User user
    Date createdAt

class User {
    static searchable = true              // <-- Make Users searchable
    static hasMany = [posts: Post]
    String username, password

Declaring static searchable = true is the simplest way to define your searchable class mappings.

In some cases during implementation with Grails 2.3, Searchable Plugin 0.6.6, i had end up with Issue unable tp locate org.compass-project:compass:2.2.1. Refer to this tutorial for the set up in case you are facing such issues with 2.3 Grails version.

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.

You just made your domain searchable !

Next steps

Hack the controller and view to your own tastes.

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

Customize the mappings between your classes and the search index.

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 !