2013-02-27 66 views
0

我有关于搜索插件的一些问题检索插件:的Grails与标准

我有两个域名:

class Ads { 
     static searchable = true 
     String fromCity 
     String toCity 
     User user 
    static constraints = { 
    } 
} 
class User { 
    String username 
    String password 
} 

,我已经开发了我自己的搜索页面有两个字段(fromCity,toCity)。有类似的东西:

def listResults = searchableService.search("NewYork","Miami") 

所以我想知道我可以给我的搜索方法这个标准领域。

def srchResults = searchableService.search(??????) 

如果有人能帮我做到这一点,我将非常感激。

回答

1

首先,您需要在您的域类中定义可搜索的闭包。例如

static searchable = { 
     analyzer "simple" 
     only = ['firstName','uuid'] 
     firstName boost: 5.0 
    } 

然后您可以搜索如下。

def searchResults = SomeDomain.search(textToSearch + "*" + " -(firstName: ${myName})", params) 

-(firstName: ${myName})这从搜索结果中删除我的名字,同样也可以和或根据您的逻辑等领域。

默认运算符是“和”在那里,你可以修改的操作,请参阅下面的例子

defaultOperator - Either "and" or "or". Default is to defer to the global Compass setting, which is "and" if not otherwise set by you. 

search("mango chutney", defaultOperator: "or") 
// ==> as if the query was "mango OR chutney" 
//  without the option it would be like "mango AND chutney" 

更多细节请查看文档。 Searchable Plugin Documentation

让我知道你是否需要任何帮助。

More Help On Compass 请参阅第12.5.1节。查询字符串语法