简体   繁体   中英

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.

Here is an example query: 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.

Lately I'm trying .expression() but not sure how it works or if that's even a viable solution.

Any ideas? Thanks /w

我用表达式解决它:

new Criteria("myfield").expression("\"siamese cat\"")

这对我有用...因为空间是一种特殊的字符,请逃脱它:

new Criteria("myfield").expression("siamese\ cat")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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