简体   繁体   English

Grails可搜索插件查询

[英]Grails searchable plugin query

I'm using the searchable plug-in in my grails project, 我在grails项目中使用了可搜索的插件,

I have a domain class like this: 我有一个像这样的领域类:

class Item {
...
String dominantColor
String palette
...

static searchable = {
     ....
    only: ['title', 'description' ,'palette' , 'dominantColor']
}

dominantColor is a String containing a color name like : dominantColor是一个包含颜色名称的字符串,例如:

Green 绿色

palette is a String containing a list of colors name like this : 调色板是一个包含以下颜色名称列表的字符串:

["Desert sand","Dark jungle green","Outer Space","Dim gray","Slate gray","Army green","Dark electric blue","Cadet grey","Dark chestnut"] [“沙漠沙”,“深色丛林绿色”,“外太空”,“暗灰色”,“板岩灰色”,“军绿色”,“深色电蓝色”,“军校学生灰色”,“深色栗子”]

and I'm trying to search only items with selected color, I tried like this: 并且我尝试仅搜索具有选定颜色的项目,我尝试这样做:

def searchResult = Item.search({
    must(term("Item.publication", true))
    must(term("Item.Itemlist.isPublished", true))
    must{queryString(query)}
    if(params.color){
        String selectedColor = params.selectedColorName
        must{
            term('Item.dominantColor', selectedColor)
            term('Item.palette', selectedColor)
            }
        }
}).results

But doesn't work, can anyone help me figuring out what is wrong with my query? 但是不起作用,有人可以帮我弄清楚查询中的问题吗?

Edit I noticed that 编辑我注意到

 must{term('proprityName ', value)

doesn't work with String value, 不适用于String值,

when i tried with only this , it work 当我尝试仅此,它工作

  must(term("Item.publication", true))

but with this it didn't 但这并没有

  term('Item.dominantColor', "Green")

My best guess is that your values input into the index are being analyzed, and are all lowercased. 我最好的猜测是,您输入到索引中的值正在被分析,并且全部为小写。

When you construct your queries though, there is no analysis happening, so they won't be automatically lowercased. 但是,当您构造查询时,不会进行任何分析,因此不会自动将它们转换为小写字母。 Try: 尝试:

term('Item.dominantColor', "green")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM