use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project alien4cloud by alien4cloud.
the class SuggestionController method nodeTypeSuggest.
@ApiIgnore
@RequestMapping(value = "/nodetypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String[]> nodeTypeSuggest(@RequestParam("text") String searchText, @RequestParam(value = "isAbstract", required = false) Boolean isAbstract) {
if (searchText == null || searchText.trim().isEmpty()) {
return RestResponseBuilder.<String[]>builder().data(new String[0]).build();
}
searchText = StringUtils.lowerCase(searchText);
QueryBuilder queryOnText = QueryBuilders.regexpQuery("elementId", ".*?" + searchText + ".*");
// FIXME the way of getting the highest version of a component has changed
// QueryBuilder queryOnHighest = QueryBuilders.termQuery("highestVersion", true);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().must(queryOnText);
QueryBuilder query = boolQueryBuilder;
if (isAbstract != null) {
query = boolQueryBuilder.must(QueryBuilders.termQuery("abstract", isAbstract));
}
return RestResponseBuilder.<String[]>builder().data(dao.selectPath(dao.getIndexForType(NodeType.class), new String[] { MappingBuilder.indexTypeFromClass(NodeType.class) }, query, SortOrder.ASC, "elementId", 0, 10)).build();
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleEqualsTextNull.
@Test
public void generateOneQueryRuleEqualsTextNull() {
String value = null;
Query<Entity> q = new QueryImpl<>().eq(textAttrName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(boolQuery().mustNot(existsQuery(textAttrName)));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleInInt.
@Test
public void generateOneQueryRuleInInt() {
Integer value1 = 1;
Integer value2 = 2;
Iterable<Object> values = Arrays.asList(value1, value2);
Query<Entity> q = new QueryImpl<>().in(intAttrName, values);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(termsQuery(intAttrName, new Object[] { value1, value2 }));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleEqualsDateTime.
@Test
public void generateOneQueryRuleEqualsDateTime() throws ParseException {
Instant value = Instant.parse("2015-05-22T06:12:13Z");
Query<Entity> q = new QueryImpl<>().eq(dateTimeAttrName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(termQuery(dateTimeAttrName, value.toString()));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleInCategorical_Ids.
@Test
public void generateOneQueryRuleInCategorical_Ids() {
Iterable<String> values = asList("id0", "id1", "id2");
Query<Entity> q = new QueryImpl<>().in(categoricalAttrName, values);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(nestedQuery(categoricalAttrName, termsQuery(categoricalAttrName + '.' + idAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { "id0", "id1", "id2" }), ScoreMode.Avg));
assertQueryBuilderEquals(query, expectedQuery);
}
Aggregations