@Test void mapQueryRule() { QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn("attr"); when(queryRule.getValue()).thenReturn("val"); Attribute attribute = mock(Attribute.class); when(attribute.getDataType()).thenReturn(AttributeType.STRING); when(documentIdGenerator.generateId(attribute)).thenReturn("attr"); EntityType entityType = mock(EntityType.class); when(entityType.getAttributeByName("attr")).thenReturn(attribute); QueryBuilder queryBuilder = queryClauseFuzzyMatchGenerator.mapQueryRule(queryRule, entityType); QueryBuilder expectedQueryBuilder = QueryBuilders.queryStringQuery("attr:(val)"); assertQueryBuilderEquals(expectedQueryBuilder, queryBuilder); }
QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType, true); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return nestedQueryBuilder( entityType, attributePath, QueryBuilders.queryStringQuery(fieldName + ":(" + queryValue + ")")); case BOOL: case COMPOUND: throw new MolgenisQueryException( format( "Illegal data type [%s] for operator [%s]", attrType, QueryRule.Operator.FUZZY_MATCH)); default: throw new UnexpectedEnumException(attrType); } }
QueryClauseFuzzyMatchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType, true); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return nestedQueryBuilder( entityType, attributePath, QueryBuilders.queryStringQuery(fieldName + ":(" + queryValue + ")")); case BOOL: case COMPOUND: throw new MolgenisQueryException( format( "Illegal data type [%s] for operator [%s]", attrType, QueryRule.Operator.FUZZY_MATCH)); default: throw new UnexpectedEnumException(attrType); } } }
QueryClauseFuzzyMatchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType, true); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return nestedQueryBuilder( entityType, attributePath, QueryBuilders.queryStringQuery(fieldName + ":(" + queryValue + ")")); case BOOL: case COMPOUND: throw new MolgenisQueryException( format( "Illegal data type [%s] for operator [%s]", attrType, QueryRule.Operator.FUZZY_MATCH)); default: throw new UnexpectedEnumException(attrType); } } QueryClauseFuzzyMatchGenerator(DocumentIdGenerator documentIdGenerator); }
QueryClauseFuzzyMatchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType, true); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return nestedQueryBuilder( entityType, attributePath, QueryBuilders.queryStringQuery(fieldName + ":(" + queryValue + ")")); case BOOL: case COMPOUND: throw new MolgenisQueryException( format( "Illegal data type [%s] for operator [%s]", attrType, QueryRule.Operator.FUZZY_MATCH)); default: throw new UnexpectedEnumException(attrType); } } QueryClauseFuzzyMatchGenerator(DocumentIdGenerator documentIdGenerator);  }
QueryClauseFuzzyMatchGenerator extends BaseQueryClauseGenerator { QueryBuilder mapQueryRule(QueryRule queryRule, EntityType entityType) { List<Attribute> attributePath = getAttributePathExpanded(queryRule.getField(), entityType, true); Attribute attr = attributePath.get(attributePath.size() - 1); Object queryValue = getQueryValue(attr, queryRule.getValue()); String fieldName = getQueryFieldName(attributePath); AttributeType attrType = attr.getDataType(); switch (attrType) { case DATE: case DATE_TIME: case DECIMAL: case EMAIL: case ENUM: case HTML: case HYPERLINK: case INT: case LONG: case SCRIPT: case STRING: case TEXT: return nestedQueryBuilder( entityType, attributePath, QueryBuilders.queryStringQuery(fieldName + ":(" + queryValue + ")")); case BOOL: case COMPOUND: throw new MolgenisQueryException( format( "Illegal data type [%s] for operator [%s]", attrType, QueryRule.Operator.FUZZY_MATCH)); default: throw new UnexpectedEnumException(attrType); } } QueryClauseFuzzyMatchGenerator(DocumentIdGenerator documentIdGenerator);   }