Grails 可搜索:搜索成员对象中的特定字段?
使用 Grails Searchable 插件,我获得了以下类:
class Person {
static searchable = {
address component: true
}
}
并且:
class Address {
static searchable = {
root false
}
String country
}
我想对来自特定国家/地区的人员进行特定搜索。 “国家:NL”不起作用。 “地址:国家:NL”也不起作用。我找不到任何有关此语法的信息。有什么想法吗?
我想我必须在可搜索闭包中做一些聪明的索引或其他一些技巧,但我就是找不到它。
Using the Grails Searchable plugin, I've got these classes:
class Person {
static searchable = {
address component: true
}
}
and:
class Address {
static searchable = {
root false
}
String country
}
I want to do a specific search for persons from a specific country. "country:NL" doesn't work. "address:country:NL" doesn't work either. I can't find anything about the syntax for this. Any ideas?
I think I'll have to do some clever indexing or some other trick in the searchable closure, but I just can't find it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用您的两个类创建了一个基本应用程序(Grails 1.3.5,Searchable 0.5.5.1),并且搜索“country:NL”对我有用。您是否记得在尝试搜索之前调用index()?
人员:
地址:
Bootstrap:
然后我浏览到 /searchable 并搜索国家:NL 并返回了人员 1。
如果您想了解 Searchable 在字段/索引等方面的幕后功能 - Luke 是一个非常方便的工具(只需下载可执行 JAR):http://code.google.com/p/luke/
索引文件
欢呼
李
I created a basic app (Grails 1.3.5, Searchable 0.5.5.1) with your two classes and searching for 'country:NL' works for me. Did you remember to call index() before trying to search?
Person:
Address:
Bootstrap:
Then I browsed to to /searchable and searched for country:NL and got person 1 returned.
If you want to see what Searchable is doing under the covers with regards to fields/indexes etc - Luke is a very handy tool (just download the executable JAR): http://code.google.com/p/luke/
The index files are in
cheers
Lee
有效的丑陋解决方案:不要依赖 Searchable。目前,我首先执行
Person.search(params.query, [max:99999]).results
,然后执行简单的 .findAll 按国家/地区查找,然后执行 .sublist() 以使分页正常工作再次。遗憾的是,很难让如此明显的东西与 Searchable 一起使用。
我还没有开始工作的另一个解决方案是使country成为返回address.country的Person上的临时属性。开箱即用,我不知道如何修复它。
如果有人对我有任何更好的解决方案,我很想听听。
The ugly solution that works: don't rely on Searchable. At the moment I first do a
Person.search(params.query, [max:99999]).results
, then do simple .findAll to find by country and .sublist() to get paging to work again.It's a shame it's so hard to get something so obvious to work with Searchable.
Another solution I haven't gotten to work is making country a transient property on Person that returns address.country. Didn't work out of the box, and I have no idea on how to fix it.
If anyone has any prettier solutions for me, I'd love to hear them.
我是 grails 新手,但为什么必须使用可搜索插件?
简单的 1:1 或 1:n 关系有什么问题?
I am new to grails but why do you have to use the searchable plugin ?
what is wrong with a simple 1:1 or 1:n relationship ?