开发者

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 sear开发者_StackOverflow中文版ch 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜