-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: search by label produces timeouts if too many resources match (D…
- Loading branch information
1 parent
c472ff7
commit 78479d3
Showing
3 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../messages/twirl/queries/sparql/v2/searchResourceByLabelWithDefinedResourceClass.scala.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
@* | ||
* Copyright © 2021 - 2023 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*@ | ||
|
||
@import org.knora.webapi.IRI | ||
@import org.knora.webapi.util.ApacheLuceneSupport.MatchStringWhileTyping | ||
|
||
@* | ||
* Performs a search for resources by their label using SPARQL. | ||
* | ||
* @param searchTerm search terms. | ||
* @param limitToResourceClass limit search to given resource class. | ||
* @param limit maximum amount of resources to be returned. | ||
* @param offset offset to be used for paging. | ||
*@ | ||
@(searchTerm: MatchStringWhileTyping, | ||
limitToResourceClass: IRI, | ||
limit: Int, | ||
offset: Int) | ||
|
||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | ||
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#> | ||
|
||
CONSTRUCT { | ||
?resource rdfs:label ?label ; | ||
a knora-base:Resource ; | ||
knora-base:isMainResource true ; | ||
knora-base:isDeleted false ; | ||
a ?resourceType ; | ||
knora-base:attachedToUser ?resourceCreator ; | ||
knora-base:hasPermissions ?resourcePermissions ; | ||
knora-base:attachedToProject ?resourceProject ; | ||
knora-base:creationDate ?creationDate ; | ||
knora-base:lastModificationDate ?lastModificationDate . | ||
|
||
?resource knora-base:hasValue ?valueObject ; | ||
?resourceValueProperty ?valueObject . | ||
?valueObject ?valueObjectProperty ?valueObjectValue . | ||
} WHERE { | ||
{ | ||
SELECT DISTINCT ?resource ?label | ||
WHERE { | ||
?resource <http://jena.apache.org/text#query> (rdfs:label "@searchTerm.generateLiteralForLuceneIndexWithoutExactSequence") . | ||
|
||
?resource a ?resourceClass ; | ||
rdfs:label ?label . | ||
?resourceClass rdfs:subClassOf* <@limitToResourceClass> . | ||
|
||
FILTER NOT EXISTS { | ||
?resource knora-base:isDeleted true . | ||
} | ||
} | ||
ORDER BY ?resource | ||
LIMIT @limit | ||
OFFSET @offset | ||
} | ||
|
||
?resource a ?resourceType ; | ||
knora-base:attachedToUser ?resourceCreator ; | ||
knora-base:hasPermissions ?resourcePermissions ; | ||
knora-base:attachedToProject ?resourceProject ; | ||
knora-base:creationDate ?creationDate ; | ||
rdfs:label ?label . | ||
|
||
OPTIONAL { | ||
?resource knora-base:lastModificationDate ?lastModificationDate . | ||
} | ||
|
||
OPTIONAL { | ||
?resource ?resourceValueProperty ?valueObject . | ||
?resourceValueProperty rdfs:subPropertyOf* knora-base:hasValue . | ||
|
||
?valueObject a ?valueObjectType ; | ||
?valueObjectProperty ?valueObjectValue . | ||
|
||
?valueObjectType rdfs:subClassOf* knora-base:Value . | ||
|
||
FILTER(?valueObjectType != knora-base:LinkValue) | ||
|
||
FILTER NOT EXISTS { | ||
?valueObject knora-base:isDeleted true . | ||
} | ||
|
||
FILTER NOT EXISTS { | ||
?valueObjectValue a knora-base:StandoffTag . | ||
} | ||
} | ||
|
||
} |