/
searchResourceByLabelSubQuery.scala.txt
57 lines (48 loc) · 1.7 KB
/
searchResourceByLabelSubQuery.scala.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@*
* Copyright © 2021 - 2022 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 dsp.errors.SparqlGenerationException
@import org.knora.webapi.util.ApacheLuceneSupport.MatchStringWhileTyping
@*
* Select subquery for a search for resources by their label.
*
* @param searchTerm search terms.
* @param limitToProject limit search to the given project.
* @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.
* @param countQuery indicates whether it is a count query or the actual resources should be returned.
*@
@(searchTerm: MatchStringWhileTyping,
limitToProject: Option[IRI],
limitToResourceClass: Option[IRI],
limit: Int,
offset: Int,
countQuery: Boolean)
@if(!countQuery) {
SELECT DISTINCT ?resource ?label
} else {
SELECT (count(distinct ?resource) as ?count)
}
WHERE {
?resource <http://jena.apache.org/text#query> (rdfs:label "@searchTerm.generateLiteralForLuceneIndexWithoutExactSequence") .
?resource a ?resourceClass ;
rdfs:label ?label .
?resourceClass rdfs:subClassOf* knora-base:Resource .
@if(limitToResourceClass.nonEmpty) {
?resourceClass rdfs:subClassOf* <@limitToResourceClass.get> .
}
@if(limitToProject.nonEmpty) {
?resource knora-base:attachedToProject <@limitToProject.get>
}
FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}
}
@if(!countQuery) {
ORDER BY ?resource @* Needed for paging: order needs to be deterministic *@
}
LIMIT @limit
OFFSET @offset