Skip to content

Commit

Permalink
fix: add 'CONTAIN' support in query builder
Browse files Browse the repository at this point in the history
This fix to address the issue #114
  • Loading branch information
yangyangv2 committed Jul 14, 2021
1 parent 77df5d8 commit 6ae3731
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static QueryBuilder getQueryBuilderFromCriterion(@Nonnull Criterion crite
return QueryBuilders.rangeQuery(criterion.getField()).lt(criterion.getValue().trim());
} else if (condition == Condition.LESS_THAN_OR_EQUAL_TO) {
return QueryBuilders.rangeQuery(criterion.getField()).lte(criterion.getValue().trim());
} else if (condition == Condition.CONTAIN) {
return QueryBuilders.termQuery(criterion.getField(), criterion.getValue().trim());
}

throw new UnsupportedOperationException("Unsupported condition: " + condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void testFilteredQueryUnsupportedCondition() {
int from = 0;
int size = 10;
final Filter filter2 = new Filter().setCriteria(new CriterionArray(Arrays.asList(
new Criterion().setField("field_contain").setValue("value_contain").setCondition(Condition.CONTAIN))));
new Criterion().setField("field_contain").setValue("value_contain").setCondition(Condition.START_WITH))));
SortCriterion sortCriterion = new SortCriterion().setOrder(SortOrder.ASCENDING).setField("urn");
assertThrows(UnsupportedOperationException.class,
() -> _searchDAO.getFilteredSearchQuery(filter2, sortCriterion, from, size));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public static QueryBuilder getQueryBuilderFromCriterion(@Nonnull Criterion crite
return QueryBuilders.rangeQuery(criterion.getField()).lt(criterion.getValue().trim());
} else if (condition == Condition.LESS_THAN_OR_EQUAL_TO) {
return QueryBuilders.rangeQuery(criterion.getField()).lte(criterion.getValue().trim());
} else if (condition == Condition.CONTAIN) {
return QueryBuilders.termQuery(criterion.getField(), criterion.getValue().trim());
}

throw new UnsupportedOperationException("Unsupported condition: " + condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void testFilteredQueryUnsupportedCondition() {
int from = 0;
int size = 10;
final Filter filter2 = new Filter().setCriteria(new CriterionArray(Arrays.asList(
new Criterion().setField("field_contain").setValue("value_contain").setCondition(Condition.CONTAIN))));
new Criterion().setField("field_contain").setValue("value_contain").setCondition(Condition.START_WITH))));
SortCriterion sortCriterion = new SortCriterion().setOrder(SortOrder.ASCENDING).setField("urn");
assertThrows(UnsupportedOperationException.class,
() -> _searchDAO.getFilteredSearchQuery(filter2, sortCriterion, from, size));
Expand Down

0 comments on commit 6ae3731

Please sign in to comment.