Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criteria.and() throwing exception [DATASOLR-71] #139

Closed
spring-projects-issues opened this issue May 3, 2013 · 5 comments
Closed

Criteria.and() throwing exception [DATASOLR-71] #139

spring-projects-issues opened this issue May 3, 2013 · 5 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 3, 2013

constantin mitocaru opened DATASOLR-71 and commented

import static org.springframework.data.solr.core.query.Criteria.*;
...

Criteria cr = new Criteria().and(
          where("text").is("nose"),

where("text").is("heart").or("text").is("core")
);

throws

java.lang.IllegalArgumentException: Cannot add criteria for null field.
at org.springframework.util.Assert.notNull(Assert.java:112)
....


Affects: 1.0 RC1

Issue Links:

  • DATASOLR-105 Chaining Criteria does not produce the expected parenthesization
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 3, 2013

Christoph Strobl commented

Hi,
please try as follows

Criteria criteria = Criteria.where("text").is("nose").is("heart").or("text").is("core");

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 3, 2013

constantin mitocaru commented

I do not think I get the same results due to the precedence of the operators. I ran the query in solr web ui:

text: nose AND (text:heart OR text:core) //this is what I want to obtain using Criteria .and operator

and your suggestion

text: nose AND text:heart OR text:core

and I get different results

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 3, 2013

Christoph Strobl commented

I see.
The query you're trying to create can at this time not be build using Critieria. I'll have a deeper look into that.

For now you can try setting default operator

SimpleQuery query = new SimpleQuery(Criteria.where("text").is("nose").and("text").is("heart").is("core"));
query.setDefaultOperator(Operator.OR);

or use SimpleStringCriteria

Criteria criteria = new SimpleStringCriteria("text:nose AND (text:heart OR text:core)");

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 3, 2013

constantin mitocaru commented

Ok. I'll use the text criteria with SimpleStringCriteria.
However the initial exception thrown by [1] should remain as a bug.

[1]
Criteria cr = new Criteria().and(
where("text").is("nose"),
where("text").is("heart").or("text").is("core")
);

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 14, 2014

Christoph Strobl commented

Chaining criteria is possible due to resolution of DATASOLR-105.

// text:nose AND (text:heart OR text:core)
where("text").is("nose").and(where("text").is("heart").or("text").is("core));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants