[英]How to search on phrases in Spring Data Solr 1.0
I have a search query that contains quoted phrases and other words and would like to use spring-data-solr 1.0. 我有一个搜索查询,其中包含带引号的短语和其他单词,并且想使用spring-data-solr 1.0。
Here is an example query: dog "siamese cat" penguin
这是一个示例查询:
dog "siamese cat" penguin
I've been trying something like, 我一直在尝试类似
new Criteria("myfield").contains("dog")
.and(new Criteria("myfield").contains("siamese cat"))
.and(new Criteria("myfield").contains("penguin"));
That was what I was trying until I saw that contains()
throws an exception when it contains spaces. 那就是我一直在尝试的方法,直到看到
contains()
包含空格时引发异常。
Lately I'm trying .expression()
but not sure how it works or if that's even a viable solution. 最近,我正在尝试
.expression()
但不确定它是如何工作的或者这是否是可行的解决方案。
Any ideas? 有任何想法吗? Thanks /w
谢谢/ w
我用表达式解决它:
new Criteria("myfield").expression("\"siamese cat\"")
这对我有用...因为空间是一种特殊的字符,请逃脱它:
new Criteria("myfield").expression("siamese\ cat")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.