Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(ext search v1): add support for URI values (DSP-1522) (#1842)
* test(ext search v1): add support for URI values

* test(ext search v1): add support for URI values

* refactor(search responder v1): comment out println
  • Loading branch information
tobiasschweizer committed Apr 13, 2021
1 parent 10bd07b commit b119757
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/03-apis/api-v1/reading-and-searching-resources.md
Expand Up @@ -302,6 +302,7 @@ operators:
| Text Value | MATCH_BOOLEAN, MATCH, EQ, !EQ, LIKE, !LIKE, EXISTS |
| Geometry Value | EXISTS |
| Geoname Value | EQ, EXISTS |
| URI Value | EQ, EXISTS |
| Resource Pointer | EQ, EXISTS |
| Color Value | EQ, EXISTS |
| List Value | EQ, EXISTS |
Expand Down
Expand Up @@ -90,6 +90,10 @@ class SearchResponderV1(responderData: ResponderData) extends Responder(responde
SearchComparisonOperatorV1.EQ,
SearchComparisonOperatorV1.EXISTS
),
OntologyConstants.KnoraBase.UriValue -> Set(
SearchComparisonOperatorV1.EQ,
SearchComparisonOperatorV1.EXISTS
),
OntologyConstants.KnoraBase.Resource -> Set(
SearchComparisonOperatorV1.EQ,
SearchComparisonOperatorV1.EXISTS
Expand Down Expand Up @@ -526,6 +530,13 @@ class SearchResponderV1(responderData: ResponderData) extends Responder(responde

searchParamWithoutValue.copy(searchValue = Some(searchString))

case OntologyConstants.KnoraBase.UriValue =>
// validate URI
val searchString = stringFormatter.validateAndEscapeIri(
searchval,
throw BadRequestException(s"Invalid URI: $searchval"))
searchParamWithoutValue.copy(searchValue = Some(searchString))

case OntologyConstants.KnoraBase.ListValue =>
// check if string represents a node in a list
val searchString = stringFormatter.validateAndEscapeIri(
Expand Down
Expand Up @@ -289,6 +289,14 @@ WHERE {

}

case "http://www.knora.org/ontology/knora-base#UriValue" => {

?valueObject@index knora-base:valueHasUri '@searchCriterion.searchValue'^^xsd:anyURI .

BIND('@searchCriterion.searchValue' AS ?literal@index)

}

case other => {
@{throw SparqlGenerationException(s"Value type $other is not supported with comparison operator ${searchCriterion.comparisonOperator}"); ()}
}
Expand Down
Expand Up @@ -281,6 +281,14 @@ WHERE {

}

case "http://www.knora.org/ontology/knora-base#UriValue" => {

?valueObject@index knora-base:valueHasUri '@searchCriterion.searchValue'^^xsd:anyURI .

BIND('@searchCriterion.searchValue' AS ?literal@index)

}

case other => {
@{throw SparqlGenerationException(s"Value type $other is not supported with comparison operator ${searchCriterion.comparisonOperator}"); ()}
}
Expand Down
Expand Up @@ -329,6 +329,23 @@ class SearchV1R2RSpec extends R2RSpec {

}

"perform an extended search for an anything:Thing with a URI" in {

val props =
"&property_id=http%3A%2F%2Fwww.knora.org%2Fontology%2F0001%2Fanything%23hasUri&compop=EQ&searchval=http%3A%2F%2Fwww.google.ch"
val filter =
"&show_nrows=25&start_at=0&filter_by_restype=http%3A%2F%2Fwww.knora.org%2Fontology%2F0001%2Fanything%23Thing"

Get("/v1/search/?searchtype=extended" + props + filter) ~> searchPath ~> check {

assert(status == StatusCodes.OK, response.toString)

checkNumberOfHits(responseAs[String], 1)

}

}

}

}

0 comments on commit b119757

Please sign in to comment.