-
Notifications
You must be signed in to change notification settings - Fork 18
/
searchResourceByLabel.scala.txt
116 lines (102 loc) · 4.21 KB
/
searchResourceByLabel.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@*
* 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 dsp.errors.SparqlGenerationException
@import org.knora.webapi.util.ApacheLuceneSupport.MatchStringWhileTyping
@*
* Performs a search for resources by their label using SPARQL w/o inference.
*
* @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)
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
@if(!countQuery) {
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 .
# include this inferred information in the results, needed to identify value properties
?resource knora-base:hasValue ?valueObject ;
?resourceValueProperty ?valueObject .
?valueObject ?valueObjectProperty ?valueObjectValue .
} WHERE {
{
{
@{
org.knora.webapi.messages.twirl.queries.sparql.v2.txt.searchResourceByLabelSubQuery(
searchTerm = searchTerm,
limitToProject = limitToProject,
limitToResourceClass = limitToResourceClass,
limit = limit,
offset = offset,
countQuery = countQuery)
}
}
?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 .
}
}
# there might be resources that have neither values nor links
UNION {
{
@{
org.knora.webapi.messages.twirl.queries.sparql.v2.txt.searchResourceByLabelSubQuery(
searchTerm = searchTerm,
limitToProject = limitToProject,
limitToResourceClass = limitToResourceClass,
limit = limit,
offset = offset,
countQuery = countQuery)
}
}
?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 .
}
}
}
} else {
@{
org.knora.webapi.messages.twirl.queries.sparql.v2.txt.searchResourceByLabelSubQuery(
searchTerm = searchTerm,
limitToProject = limitToProject,
limitToResourceClass = limitToResourceClass,
limit = limit,
offset = offset,
countQuery = countQuery)
}
}