wsams
wsams

Reputation: 2637

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

Upvotes: 3

Views: 1248

Answers (2)

inor
inor

Reputation: 2846

This works for me... since space is a special char just escape it:

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

Upvotes: 1

Itai Peleg
Itai Peleg

Reputation: 39

i solve it with expression:

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

Upvotes: 3

Related Questions