Skip to content

Commit 05b5a54

Browse files
authored
Merge pull request #2460 from meyerbaptiste/add_elasticsearch_match_filter
Add a match filter to Elasticsearch reading support
2 parents f7c19fa + 502cbf8 commit 05b5a54

File tree

10 files changed

+779
-162
lines changed

10 files changed

+779
-162
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
@elasticsearch
2+
Feature: Match filter on collections from Elasticsearch
3+
In order to get specific results from a large collections of resources from Elasticsearch
4+
As a client software developer
5+
I need to search for resources matching the text specified
6+
7+
Scenario: Match filter on a text property
8+
When I send a "GET" request to "/tweets?message=Good%20job"
9+
Then the response status code should be 200
10+
And the response should be in JSON
11+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
12+
And the JSON should be valid according to this schema:
13+
"""
14+
{
15+
"type": "object",
16+
"properties": {
17+
"@context": {"pattern": "^/contexts/Tweet$"},
18+
"@id": {"pattern": "^/tweets$"},
19+
"@type": {"pattern": "^hydra:Collection$"},
20+
"hydra:member": {
21+
"type": "array",
22+
"additionalItems": false,
23+
"maxItems": 2,
24+
"minItems": 2,
25+
"items": [
26+
{
27+
"type": "object",
28+
"properties": {
29+
"@id": {
30+
"type": "string",
31+
"pattern": "^/tweets/7cdadcda-3fb5-4312-9e32-72acba323cc0$"
32+
}
33+
}
34+
},
35+
{
36+
"type": "object",
37+
"properties": {
38+
"@id": {
39+
"type": "string",
40+
"pattern": "^/tweets/f91bca21-b5f8-405b-9b08-d5a5dc476a92$"
41+
}
42+
}
43+
}
44+
]
45+
},
46+
"hydra:view": {
47+
"type": "object",
48+
"properties": {
49+
"@id": {"pattern": "^/tweets\\?message=Good%20job$"},
50+
"@type": {"pattern": "^hydra:PartialCollectionView$"}
51+
}
52+
}
53+
}
54+
}
55+
"""
56+
57+
Scenario: Match filter on a text property
58+
When I send a "GET" request to "/tweets?message%5B%5D=Good%20job&message%5B%5D=run"
59+
Then the response status code should be 200
60+
And the response should be in JSON
61+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
62+
And the JSON should be valid according to this schema:
63+
"""
64+
{
65+
"type": "object",
66+
"properties": {
67+
"@context": {"pattern": "^/contexts/Tweet$"},
68+
"@id": {"pattern": "^/tweets$"},
69+
"@type": {"pattern": "^hydra:Collection$"},
70+
"hydra:member": {
71+
"type": "array",
72+
"additionalItems": false,
73+
"maxItems": 3,
74+
"minItems": 3,
75+
"items": [
76+
{
77+
"type": "object",
78+
"properties": {
79+
"@id": {
80+
"type": "string",
81+
"pattern": "^/tweets/6d82a76c-8ba2-4e78-9ab3-6a456e4470c3$"
82+
}
83+
}
84+
},
85+
{
86+
"type": "object",
87+
"properties": {
88+
"@id": {
89+
"type": "string",
90+
"pattern": "^/tweets/7cdadcda-3fb5-4312-9e32-72acba323cc0$"
91+
}
92+
}
93+
},
94+
{
95+
"type": "object",
96+
"properties": {
97+
"@id": {
98+
"type": "string",
99+
"pattern": "^/tweets/9de3308c-6f82-4a57-a33c-4e3cd5d5a3f6$"
100+
}
101+
}
102+
}
103+
]
104+
},
105+
"hydra:totalItem": {
106+
"type": "string",
107+
"pattern": "^4$"
108+
},
109+
"hydra:view": {
110+
"type": "object",
111+
"properties": {
112+
"@id": {"pattern": "^/tweets\\?message%5B%5D=Good%20job&message%5B%5D=run&page=1$"},
113+
"@type": {"pattern": "^hydra:PartialCollectionView$"}
114+
}
115+
}
116+
}
117+
}
118+
"""
119+
120+
Scenario: Match filter on a nested property of text type
121+
When I send a "GET" request to "/tweets?author.firstName=Caroline"
122+
Then the response status code should be 200
123+
And the response should be in JSON
124+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
125+
And the JSON should be valid according to this schema:
126+
"""
127+
{
128+
"type": "object",
129+
"properties": {
130+
"@context": {"pattern": "^/contexts/Tweet$"},
131+
"@id": {"pattern": "^/tweets$"},
132+
"@type": {"pattern": "^hydra:Collection$"},
133+
"hydra:member": {
134+
"type": "array",
135+
"additionalItems": false,
136+
"maxItems": 2,
137+
"minItems": 2,
138+
"items": [
139+
{
140+
"type": "object",
141+
"properties": {
142+
"@id": {
143+
"type": "string",
144+
"pattern": "^/tweets/6d82a76c-8ba2-4e78-9ab3-6a456e4470c3$"
145+
}
146+
}
147+
},
148+
{
149+
"type": "object",
150+
"properties": {
151+
"@id": {
152+
"type": "string",
153+
"pattern": "^/tweets/f91bca21-b5f8-405b-9b08-d5a5dc476a92$"
154+
}
155+
}
156+
}
157+
]
158+
},
159+
"hydra:view": {
160+
"type": "object",
161+
"properties": {
162+
"@id": {"pattern": "^/tweets\\?author.firstName=Caroline$"},
163+
"@type": {"pattern": "^hydra:PartialCollectionView$"}
164+
}
165+
}
166+
}
167+
}
168+
"""
169+
170+
Scenario: Combining match filters on properties of text type and a nested property of text type
171+
When I send a "GET" request to "/tweets?message%5B%5D=Good%20job&message%5B%5D=run&author.firstName=Caroline"
172+
Then the response status code should be 200
173+
And the response should be in JSON
174+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
175+
And the JSON should be valid according to this schema:
176+
"""
177+
{
178+
"type": "object",
179+
"properties": {
180+
"@context": {"pattern": "^/contexts/Tweet$"},
181+
"@id": {"pattern": "^/tweets$"},
182+
"@type": {"pattern": "^hydra:Collection$"},
183+
"hydra:member": {
184+
"type": "array",
185+
"additionalItems": false,
186+
"maxItems": 2,
187+
"minItems": 2,
188+
"items": [
189+
{
190+
"type": "object",
191+
"properties": {
192+
"@id": {
193+
"type": "string",
194+
"pattern": "^/tweets/6d82a76c-8ba2-4e78-9ab3-6a456e4470c3$"
195+
}
196+
}
197+
},
198+
{
199+
"type": "object",
200+
"properties": {
201+
"@id": {
202+
"type": "string",
203+
"pattern": "^/tweets/f91bca21-b5f8-405b-9b08-d5a5dc476a92$"
204+
}
205+
}
206+
}
207+
]
208+
},
209+
"hydra:view": {
210+
"type": "object",
211+
"properties": {
212+
"@id": {"pattern": "^/tweets\\?message%5B%5D=Good%20job&message%5B%5D=run&author.firstName=Caroline$"},
213+
"@type": {"pattern": "^hydra:PartialCollectionView$"}
214+
}
215+
}
216+
}
217+
}
218+
"""

features/elasticsearch/read.feature

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Feature: Retrieve from Elasticsearch
121121
},
122122
"hydra:search": {
123123
"@type": "hydra:IriTemplate",
124-
"hydra:template": "\/tweets{?order[id],order[author.id]}",
124+
"hydra:template": "/tweets{?order[id],order[author.id],message,message[],author.firstName,author.firstName[]}",
125125
"hydra:variableRepresentation": "BasicRepresentation",
126126
"hydra:mapping": [
127127
{
@@ -135,6 +135,30 @@ Feature: Retrieve from Elasticsearch
135135
"variable": "order[author.id]",
136136
"property": "author.id",
137137
"required": false
138+
},
139+
{
140+
"@type": "IriTemplateMapping",
141+
"variable": "message",
142+
"property": "message",
143+
"required": false
144+
},
145+
{
146+
"@type": "IriTemplateMapping",
147+
"variable": "message[]",
148+
"property": "message",
149+
"required": false
150+
},
151+
{
152+
"@type": "IriTemplateMapping",
153+
"variable": "author.firstName",
154+
"property": "author.firstName",
155+
"required": false
156+
},
157+
{
158+
"@type": "IriTemplateMapping",
159+
"variable": "author.firstName[]",
160+
"property": "author.firstName",
161+
"required": false
138162
}
139163
]
140164
}
@@ -213,7 +237,7 @@ Feature: Retrieve from Elasticsearch
213237
},
214238
"hydra:search": {
215239
"@type": "hydra:IriTemplate",
216-
"hydra:template": "\/tweets{?order[id],order[author.id]}",
240+
"hydra:template": "/tweets{?order[id],order[author.id],message,message[],author.firstName,author.firstName[]}",
217241
"hydra:variableRepresentation": "BasicRepresentation",
218242
"hydra:mapping": [
219243
{
@@ -227,6 +251,30 @@ Feature: Retrieve from Elasticsearch
227251
"variable": "order[author.id]",
228252
"property": "author.id",
229253
"required": false
254+
},
255+
{
256+
"@type": "IriTemplateMapping",
257+
"variable": "message",
258+
"property": "message",
259+
"required": false
260+
},
261+
{
262+
"@type": "IriTemplateMapping",
263+
"variable": "message[]",
264+
"property": "message",
265+
"required": false
266+
},
267+
{
268+
"@type": "IriTemplateMapping",
269+
"variable": "author.firstName",
270+
"property": "author.firstName",
271+
"required": false
272+
},
273+
{
274+
"@type": "IriTemplateMapping",
275+
"variable": "author.firstName[]",
276+
"property": "author.firstName",
277+
"required": false
230278
}
231279
]
232280
}
@@ -288,7 +336,7 @@ Feature: Retrieve from Elasticsearch
288336
},
289337
"hydra:search": {
290338
"@type": "hydra:IriTemplate",
291-
"hydra:template": "\/tweets{?order[id],order[author.id]}",
339+
"hydra:template": "/tweets{?order[id],order[author.id],message,message[],author.firstName,author.firstName[]}",
292340
"hydra:variableRepresentation": "BasicRepresentation",
293341
"hydra:mapping": [
294342
{
@@ -302,6 +350,30 @@ Feature: Retrieve from Elasticsearch
302350
"variable": "order[author.id]",
303351
"property": "author.id",
304352
"required": false
353+
},
354+
{
355+
"@type": "IriTemplateMapping",
356+
"variable": "message",
357+
"property": "message",
358+
"required": false
359+
},
360+
{
361+
"@type": "IriTemplateMapping",
362+
"variable": "message[]",
363+
"property": "message",
364+
"required": false
365+
},
366+
{
367+
"@type": "IriTemplateMapping",
368+
"variable": "author.firstName",
369+
"property": "author.firstName",
370+
"required": false
371+
},
372+
{
373+
"@type": "IriTemplateMapping",
374+
"variable": "author.firstName[]",
375+
"property": "author.firstName",
376+
"required": false
305377
}
306378
]
307379
}

features/elasticsearch/term_filter.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Feature: Term filter on collections from Elasticsearch
66

77
Scenario: Term filter on an identifier property
88
When I send a "GET" request to "/users?id=%2Fusers%2Fcf875c95-41ab-48df-af66-38c74db18f72"
9-
Then the response should be in JSON
109
Then the response status code should be 200
1110
And the response should be in JSON
1211
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"

0 commit comments

Comments
 (0)