我对可搜索插件有一些疑问:
我有两个域:
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")
因此,我想知道如何将搜索方法赋予Criteria Field。
def srchResults = searchableService.search(??????)
如果有人可以帮助我,我将非常感激。
最佳答案
首先,您需要在域类中定义一个可搜索的闭包。例如
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节。查询字符串语法
关于grails - 具有条件的Grails可搜索插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15108218/