简体   繁体   中英

Grails Searchable Plugin for multiple domain classes and multiple search fields with a single submit button

I have multiple domain objects and having one to many, many to many relationships and search data comes from couple of tables and it is always same. I implemented Searchable plugin in my app and able to retrieve results when I have single search field like this:

<g:form url='[controller: "searchable", action: "searchContact"]' id="searchableForm" name="searchableForm" method="get">
    <g:textField name="query" value="${params.query}" size="40"/>
    <input type="submit" value="Search Contact" />
</g:form>. 

But I have multiple text fields, check boxes and g:select boxes to get searchTerm. Based on any one of fields or multiple search selections I have to get search results. How to include all search fields in between and having a single submit button for all the params. Here is my search action code:

def searchContact = { 
    if (!params.query) {
        return [:]
    }
    try {
        String searchTerm = params.query
        println searchTerm
        return [searchResult: searchableService.search(searchTerm, params)]
    } catch (SearchEngineQueryParseException ex) {
        return [parseException: true]
    }
}

Quick suggestions are appreciated.

You can pass all the terms in one String query separating each token/word by a space, so for example if you have two Domain classes one called Person and another one called Job and you search for "John" and "Engineer", your String query should be "John Engineer" and that should get you both domain objects.

Is that kind of what you are looking for?

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