【问题标题】:Grails Searchable plugin add to index conditionGrails Searchable 插件添加到索引条件
【发布时间】:2014-01-21 17:28:30
【问题描述】:

我有域名:

class Listing {
  String name
  Address address
  static searchable = {
    address component: true
    only: ['name']
  }
  static constraints = {
    address nullable: true
  }
}

我希望在搜索索引中只有地址为 !=null 的对象。是否可以通过配置实现?

【问题讨论】:

  • 你能详细说明这个问题吗? -- 如果地址为空,那么它是否被索引有什么关系?
  • 在数据库中只有 10% 的列表有地址。我也不喜欢在搜索过程中通过查询过滤结果

标签: grails searchable compass-lucene


【解决方案1】:

Lucene 不是这样工作的。只能按存在的字段和值进行搜索,不能直接检查该字段是否存在,这里不能做SQL的“为空”检查。 要实现您需要的内容,您必须添加类似boolean addressPresent 的内容,如果地址已填满,请将其设置为true。 然后在您的查询中,您必须添加附加子句来检查 addressPresent 字段

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多