Skip to content

Commit

Permalink
feature(ext search v1): add support for Geoname values (DSP-1493) (#1840
Browse files Browse the repository at this point in the history
)

* feature(ext search v1): add support for Geoname values

* test(ext search v1): add support for Geoname values
  • Loading branch information
tobiasschweizer committed Apr 8, 2021
1 parent 9d0e93e commit 10bd07b
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 @@ -301,6 +301,7 @@ operators:
| Float Value | EQ, !EQ, GT, GT_EQ, LT, LT_EQ, EXISTS |
| Text Value | MATCH_BOOLEAN, MATCH, EQ, !EQ, LIKE, !LIKE, EXISTS |
| Geometry Value | EXISTS |
| Geoname Value | EQ, EXISTS |
| Resource Pointer | EQ, EXISTS |
| Color Value | EQ, EXISTS |
| List Value | EQ, EXISTS |
Expand Down
Expand Up @@ -86,6 +86,10 @@ class SearchResponderV1(responderData: ResponderData) extends Responder(responde
OntologyConstants.KnoraBase.GeomValue -> Set(
SearchComparisonOperatorV1.EXISTS
),
OntologyConstants.KnoraBase.GeonameValue -> Set(
SearchComparisonOperatorV1.EQ,
SearchComparisonOperatorV1.EXISTS
),
OntologyConstants.KnoraBase.Resource -> Set(
SearchComparisonOperatorV1.EQ,
SearchComparisonOperatorV1.EXISTS
Expand Down Expand Up @@ -515,6 +519,13 @@ class SearchResponderV1(responderData: ResponderData) extends Responder(responde
// this only will be used with compop EXISTS
searchParamWithoutValue.copy(searchValue = Some(""))

case OntologyConstants.KnoraBase.GeonameValue =>
// sanitize Geoname search string
val searchString = stringFormatter
.toSparqlEncodedString(searchval, throw BadRequestException(s"Invalid Geoname search string: '$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 @@ -281,6 +281,14 @@ WHERE {

}

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

?valueObject@index knora-base:valueHasGeonameCode '@searchCriterion.searchValue' .

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 @@ -273,6 +273,14 @@ WHERE {

}

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

?valueObject@index knora-base:valueHasGeonameCode '@searchCriterion.searchValue' .

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 @@ -312,6 +312,23 @@ class SearchV1R2RSpec extends R2RSpec {

}

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

val props =
"&property_id=http%3A%2F%2Fwww.knora.org%2Fontology%2F0001%2Fanything%23hasGeoname&compop=EQ&searchval=2661604"
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 10bd07b

Please sign in to comment.