简体   繁体   中英

grails Searchable plugin : How to make property only for sorting , but not for searching

I am using searchable plugin in my project. And i have a simple domain, which given below

    Class User {
        String title
        String Description
        int vote
        Date date
            }
    static searchable = {
            only: ['description','title','vote','date']
            date name: 'sortableTitle1', index: 'not_analyzed'
            vote name: 'sortableTitle2', index: 'not_analyzed'

}

My need is to make vote and date as a sortable element. and it should not regarded while searching
Also i know, it can done by using below code

date name: 'sortableTitle1', index: 'not_analyzed' store:'no'

But in this case the result list of object will not contain date property, so it can't be displayed in gsp for display.
So how i can make 'date' element for displaying, sorting and not for searching in my gsp.

I can't add new comment, so here is the next part of my answer:

how you set mapping for class:

You can declare the default sort order for a collection in the mapping ( documentation ).

I hope it is what you need !

Example found in the documentation:

To "replace", for example, this:

def airports = Airport.list(sort:'name')

You can use

class Airport {
    …
    static mapping = {
        sort name: "desc"
    }
}

And the the first part of my answer:

May be not the best thing to do, but this what I did for the the same kind of problem: I set a mapping for my class, and Searchable helped me to get Ids. With ids, I use getAll method get all objects (automatically sort with the mapping).

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