如何访问 Compas 搜索框架中的子对象属性?

发布于 2024-10-07 01:11:20 字数 369 浏览 0 评论 0 原文

我有以下代码(在 grails 和可搜索插件又名指南针中):

class Topic {

  String name;
  static searchable = true;
}

class Question extends BaseEntity {
  String question;

  static searchable = true;
  static hasMany = [
      topics: Topic
  ]
}

如何搜索具有特定主题 id 的问题?

像 Question.search("topics#id:12") 或 Question.search("topics.id:12") 这样的东西不起作用。

I have following code (in grails and Searchable Plugin aka Compass):

class Topic {

  String name;
  static searchable = true;
}

class Question extends BaseEntity {
  String question;

  static searchable = true;
  static hasMany = [
      topics: Topic
  ]
}

How can I search Question with specific topic id?

Something like Question.search("topics#id:12") or Question.search("topics.id:12") dosnt work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-10-14 01:11:20

在“问题”中更改您的可搜索块,使其看起来像这样:

static searchable = {
    topics component: true
}

在“主题”中,如果您不希望主题作为根搜索元素返回,则

static searchable = [
    root: false
]

启动 grails 并添加一些项目,然后从 http://www.getopt.org/luke/
并打开您的问题域对象的索引,该索引位于 ~/.grails/projects/projName/searchable-index/'env'/index/question

如果您检查文档选项卡,您将看到嵌入在索引中的术语类似于 $/Question/topics

这应该为您提供放入 Question.search 的路径,例如:

Question.search('$/Question/topics/id:1')

Chage your searchable block in Question so it looks like this:

static searchable = {
    topics component: true
}

and in Topic if you dont want Topics returned as root search elements

static searchable = [
    root: false
]

Fire up grails and add a few items, then download Luke from http://www.getopt.org/luke/
and open the index for your Question domain object which will be at ~/.grails/projects/projName/searchable-index/'env'/index/question

If you check the documents tab you will see the terms embedded in the index which will be something like $/Question/topics

This should give you the path to put in your Question.search, something like:

Question.search('$/Question/topics/id:1')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文