Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gravsearch): When link property compared in filter, don't compare link value property, too #1699

Merged
merged 1 commit into from Sep 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -596,37 +596,13 @@ abstract class AbstractPrequeryGenerator(constructClause: ConstructClause,
* @return a [[TransformedFilterPattern]].
*/
private def handlePropertyIriQueryVar(queryVar: QueryVariable, comparisonOperator: CompareExpressionOperator.Value, iriRef: IriRef, propInfo: PropertyTypeInfo): TransformedFilterPattern = {

iriRef.iri.checkApiV2Schema(querySchema, throw GravsearchException(s"Invalid schema for IRI: ${iriRef.toSparql}"))

val internalIriRef = iriRef.toOntologySchema(InternalSchema)

// make sure that the comparison operator is a CompareExpressionOperator.EQUALS
if (comparisonOperator != CompareExpressionOperator.EQUALS)
throw GravsearchException(s"Comparison operator in a CompareExpression for a property type must be ${CompareExpressionOperator.EQUALS}, but '$comparisonOperator' given (for negations use 'FILTER NOT EXISTS')")

val userProvidedRestriction = CompareExpression(queryVar, comparisonOperator, internalIriRef)

// check if the objectTypeIri of propInfo is knora-api:Resource
// if so, it is a linking property and its link value property must be restricted too
if (propInfo.objectIsResourceType) {
// it is a linking property, restrict the link value property
val restrictionForLinkValueProp = CompareExpression(
leftArg = createLinkValuePropertyVariableFromLinkingPropertyVariable(queryVar), // the same variable was created during statement processing in WHERE clause in `convertStatementForPropertyType`
operator = comparisonOperator,
rightArg = IriRef(internalIriRef.iri.fromLinkPropToLinkValueProp)) // create link value property from linking property

TransformedFilterPattern(
Some(
AndExpression(
leftArg = userProvidedRestriction,
rightArg = restrictionForLinkValueProp)
)
)
} else {
// not a linking property, just return the provided restriction
TransformedFilterPattern(Some(userProvidedRestriction))
}
TransformedFilterPattern(Some(CompareExpression(queryVar, comparisonOperator, iriRef.toOntologySchema(InternalSchema))))
}

/**
Expand Down