Skip to content

Commit dc59c52

Browse files
committed
Merge pull request NLPchina#102 from ottboy4/master
Fixed a bug where not's would not evaluate properly.
2 parents 4624895 + 13a2fce commit dc59c52

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/main/java/org/nlpcn/es4sql/query/maker/FilterMaker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class FilterMaker extends Maker {
1919
*/
2020
public static BoolFilterBuilder explan(Where where) throws SqlParseException {
2121
BoolFilterBuilder boolFilter = FilterBuilders.boolFilter();
22+
while (where.getWheres().size() == 1) {
23+
where = where.getWheres().getFirst();
24+
}
2225
new FilterMaker().explanWhere(boolFilter, where);
2326
return boolFilter;
2427
}
@@ -28,9 +31,6 @@ private FilterMaker() {
2831
}
2932

3033
private void explanWhere(BoolFilterBuilder boolFilter, Where where) throws SqlParseException {
31-
while (where.getWheres().size() == 1) {
32-
where = where.getWheres().getFirst();
33-
}
3434
if (where instanceof Condition) {
3535
addSubFilter(boolFilter, where, (BaseFilterBuilder) make((Condition) where));
3636
} else {

src/test/java/org/nlpcn/es4sql/QueryTest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,25 @@ public void notLikeTest() throws IOException, SqlParseException, SQLFeatureNotSu
219219
}
220220
}
221221

222+
@Test
223+
public void doubleNotTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
224+
SearchHits response1 = query(String.format("SELECT * FROM %s/account WHERE not gender like 'm' and not gender like 'f'", TEST_INDEX));
225+
Assert.assertEquals(0, response1.getTotalHits());
226+
227+
SearchHits response2 = query(String.format("SELECT * FROM %s/account WHERE not gender like 'm' and gender not like 'f'", TEST_INDEX));
228+
Assert.assertEquals(0, response2.getTotalHits());
229+
230+
SearchHits response3 = query(String.format("SELECT * FROM %s/account WHERE gender not like 'm' and gender not like 'f'", TEST_INDEX));
231+
Assert.assertEquals(0, response3.getTotalHits());
232+
233+
SearchHits response4 = query(String.format("SELECT * FROM %s/account WHERE gender like 'm' and not gender like 'f'", TEST_INDEX));
234+
// assert there are results and they all have gender 'm'
235+
Assert.assertNotEquals(0, response4.getTotalHits());
236+
for (SearchHit hit : response4.getHits()) {
237+
Assert.assertEquals("m", hit.getSource().get("gender").toString().toLowerCase());
238+
}
239+
}
240+
222241
@Test
223242
public void limitTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
224243
SearchHits response = query(String.format("SELECT * FROM %s LIMIT 30", TEST_INDEX));
@@ -346,8 +365,8 @@ public void notInTest() throws IOException, SqlParseException, SQLFeatureNotSupp
346365
}
347366
}
348367
}
349-
350-
368+
369+
351370
@Test
352371
public void dateSearch() throws IOException, SqlParseException, SQLFeatureNotSupportedException, ParseException {
353372
DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);
@@ -429,7 +448,7 @@ public void notMissFilterSearch() throws IOException, SqlParseException, SQLFeat
429448
assertThat(hit.getSource(), hasKey("insert_time"));
430449
}
431450
}
432-
451+
433452

434453

435454
@Test

0 commit comments

Comments
 (0)