1

我有以下代码(在 grails 和 Searchable Plugin aka Compass 中):

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") 这样的东西不起作用。

4

1 回答 1

0

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')

于 2011-08-18T13:59:34.917 回答