Revision 54661
Added by Alessia Bardi over 5 years ago
modules/cnr-cql-utils/trunk/src/test/java/eu/dnetlib/functionality/cql/mongo/MongoCqlTranslatorTest.java | ||
---|---|---|
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
@Test |
99 |
public void testParseStarAnd2() throws IOException, CQLParseException { |
|
100 |
BasicDBObject expected = new BasicDBObject("$and", Lists.newArrayList(new BasicDBObject("resulttypeid", "publication"), new BasicDBObject("funder", new BasicDBObject("$exists", true)))); |
|
101 |
Bson o = tr.toMongo("(resulttypeid exact \"publication\" and funder =*)"); |
|
102 |
assertEquals(expected, o); |
|
103 |
} |
|
104 |
|
|
105 |
@Test |
|
99 | 106 |
public void testParseIdQuery() throws IOException, CQLParseException { |
100 | 107 |
BasicDBObject expected = new BasicDBObject("_id", new BasicDBObject("$gt", new ObjectId("5225e093aabf055637bf2c65"))); |
101 | 108 |
Bson o = tr.toMongo("_id > 5225e093aabf055637bf2c65"); |
modules/cnr-cql-utils/trunk/src/main/java/eu/dnetlib/functionality/cql/mongo/MongoCqlTranslator.java | ||
---|---|---|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
private Bson doTranslate(final CQLTermNode termNode) throws CQLParseException { |
62 |
if (termNode.getTerm().equals("*")) return new BasicDBObject(); |
|
62 |
if (termNode.getTerm().equals("*") && (termNode.getIndex().equals("*") || termNode.getIndex().equals("cql.serverChoice"))) return new BasicDBObject();
|
|
63 | 63 |
String relation = termNode.getRelation().getBase(); |
64 | 64 |
Relation rel = Relations.get(relation); |
65 | 65 |
return this.handleRelationNode(rel, termNode); |
... | ... | |
80 | 80 |
switch (rel) { |
81 | 81 |
case EQUAL: |
82 | 82 |
case EXACT: |
83 |
mongoQueryObject.put(indexName, termObj); |
|
83 |
if(!term.equals("*")) { |
|
84 |
mongoQueryObject.put(indexName, termObj); |
|
85 |
} |
|
86 |
else{ |
|
87 |
//special case to handle exist queries such as fieldname = * --> qty: { $exists: true} |
|
88 |
mongoQueryObject.put(indexName, new BasicDBObject("$exists", true)); |
|
89 |
} |
|
84 | 90 |
break; |
85 | 91 |
case NOT: |
86 | 92 |
mongoQueryObject.put(indexName, new BasicDBObject("$ne", termObj)); |
Also available in: Unified diff
Fixed bug in CQL translation to mongo queries when dealing with exist queries like fieldname = *