简体   繁体   中英

I want to use searchable plugin in serializable domain

I want to use searchable plugin in serializable domain.

Now the problem is that it doesnt compile if I add this code:

class Product implements Serializable {

static transients=['searchable']

static searchable = true

I dont know how this searchable plugin works.. Moreover I also have hasMany and belongsTo relationships in the domain Product. Others are also serializable domain

So pls cud anybody tell me the proper way of making this domain searchable

First of all you don't need the transients definition there. This is all you need to get started:

    static searchable = true

You can test by going to "http://localhost:8080/YOUR-APP-NAME-HERE/searchable". If you actually have any Products added you can search one of the simple fields in your domain (like say a String productName field) just using that URL.

Once you are sure it is working you can put search fields on your forms and add some custom methods to your Product controller to use the search functionality:

    //search form
    <form controller="product" action="searchForProducts" >
       <g:textField name="query" />
       <input type="submit" value="search" />
    </form>

    //ProductController
    def searchForProducts = {
      if(params.query) {
        def products = Product.search(params.query).results
        return [productInstanceList: products]
      }
    }

As far as your hasMany references as long as they are searchable as well you should be able to include those in the search. I haven't had to do this yet so I'm not positive on the details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM