开发者

How can I access child object property in Compas Search framework?

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")开发者_如何学Go or Question.search("topics.id:12") dosnt work.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜