如何使用可搜索的属性组件进行过滤?

时间:2013-09-06 12:55:41

标签: grails lucene searchable

我有两个这样的域类:

class ExhibitionPrint {
  Exhibition exhibition
  Print print

  String title
  String description
  ....


  static searchable = {
      printSizes    component: true
      exhibition    component: true
}
}

并且

class Exhibition {

String title
boolean isPublished
    ....
static hasMany = [exhibitionPrints: ExhibitionPrint]

static searchable = {  
    exhibitionPrints component: true
}
}

我在搜索中使用了一个闭包但它似乎不起作用,即使在exhibition.isPublished等于false时我也得到了结果。  我有这样的事情:

def searchResult = ExhibitionPrint.search{
must{
         queryString(query)
         term("ExhibitionPrint.exhibition.isPublished", true)
}
}.results

知道如何实现这个吗?

1 个答案:

答案 0 :(得分:1)

您创建的查询主要解释为:MUST match (query OR isPublished = true),或者使用lucene的语法+(query isPublished:true)

如果我理解正确,你想要的是它必须匹配两个子句(即:+query +ispublished:true),如下所示:

search {
    must(queryString(query))
    must(term("ExhibitionPrint.exhibition.isPublished", true))
}