Skip to content

Commit 646b7a5

Browse files
ben-kalmusClaraMullermillotp
authored
feat(specs): add external injection source definition and runtime parameter (#5283)
Co-authored-by: Clara Muller <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent a07ab93 commit 646b7a5

File tree

6 files changed

+218
-21
lines changed

6 files changed

+218
-21
lines changed

specs/composition-full/common/params/Composition.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,42 @@ ruleContexts:
2626
default: []
2727
example: [mobile]
2828
x-categories:
29-
- Rules
29+
- Rules
30+
31+
injectedItems:
32+
type: object
33+
additionalProperties:
34+
$ref: '#/externalInjectedItem'
35+
description: |
36+
A list of extenrally injected objectID groups into from an external source.
37+
default: {}
38+
x-categories:
39+
- Advanced
40+
41+
externalInjectedItem:
42+
type: object
43+
properties:
44+
items:
45+
type: array
46+
items:
47+
title: externalInjection
48+
type: object
49+
additionalProperties: false
50+
properties:
51+
objectID:
52+
type: string
53+
description: An objectID injected into an external source.
54+
metadata:
55+
type: object
56+
additionalProperties: true
57+
description: |
58+
User-defined key-values that will be added to the injected item in the response.
59+
This is identical to Hits metadata defined in Composition or Composition Rule,
60+
with the benefit of being set at runtime.
61+
example: {'my-field': 'my-value'}
62+
required:
63+
- objectID
64+
example:
65+
{'objectID': 'my-object-1', 'metadata': {'my-field': 'my-value'}}
66+
required:
67+
- items

specs/composition-full/common/schemas/components/CompositionBehavior.yml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,8 @@ injectedItem:
5454
type: string
5555
description: injected Item unique identifier.
5656
source:
57-
title: injectedItemSource
58-
type: object
59-
additionalProperties: false
60-
properties:
61-
search:
62-
title: injectedItemSourceSearch
63-
type: object
64-
additionalProperties: false
65-
properties:
66-
index:
67-
type: string
68-
description: Composition Main Index name.
69-
example: Products
70-
params:
71-
$ref: './Injection.yml#/injectedItemsQueryParameters'
72-
required:
73-
- index
74-
required:
75-
- search
57+
description: Search source to be used to inject items into result set.
58+
$ref: '#/injectedItemSource'
7659
position:
7760
type: integer
7861
minimum: 0
@@ -103,3 +86,8 @@ injectedItem:
10386
- source
10487
- position
10588
- length
89+
90+
injectedItemSource:
91+
oneOf:
92+
- $ref: './InjectionSource.yml#/SearchSource'
93+
- $ref: './InjectionSource.yml#/ExternalSource'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SearchSource:
2+
title: searchSource
3+
description: Injected items will originate from a search request performed on the specified index.
4+
type: object
5+
additionalProperties: false
6+
properties:
7+
search:
8+
title: search
9+
type: object
10+
additionalProperties: false
11+
properties:
12+
index:
13+
type: string
14+
description: Composition Index name.
15+
example: Products
16+
params:
17+
$ref: './Injection.yml#/injectedItemsQueryParameters'
18+
required:
19+
- index
20+
required:
21+
- search
22+
23+
ExternalSource:
24+
title: externalSource
25+
description: Injected items will originate from externally provided objectIDs (that must exist in the index) given at runtime in the run request payload.
26+
type: object
27+
additionalProperties: false
28+
properties:
29+
external:
30+
title: external
31+
type: object
32+
additionalProperties: false
33+
properties:
34+
index:
35+
type: string
36+
description: Composition Index name.
37+
example: Products
38+
params:
39+
$ref: './Injection.yml#/injectedItemsQueryParameters'
40+
ordering:
41+
$ref: '#/externalOrdering'
42+
required:
43+
- index
44+
required:
45+
- external
46+
47+
externalOrdering:
48+
enum: ['default', 'userDefined']
49+
default: 'default'

specs/composition-full/common/schemas/requestBodies/RunParams.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ params:
5454
enableABTest:
5555
$ref: '../../params/Composition.yml#/enableABTest'
5656
enableReRanking:
57-
$ref: '../../params/Search.yml#/enableReRanking'
57+
$ref: '../../params/Search.yml#/enableReRanking'
58+
injectedItems:
59+
$ref: '../../params/Composition.yml#/injectedItems'

tests/CTS/requests/composition-full/putComposition.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,76 @@
6161
}
6262
}
6363
}
64+
},
65+
{
66+
"parameters": {
67+
"compositionID": "my-external-injection-compo",
68+
"composition": {
69+
"objectID": "my-external-injection-compo",
70+
"name": "my first composition",
71+
"behavior": {
72+
"injection": {
73+
"main": {
74+
"source": {
75+
"search": {
76+
"index": "foo"
77+
}
78+
}
79+
},
80+
"injectedItems": [
81+
{
82+
"key": "injectedItem1",
83+
"source": {
84+
"external": {
85+
"index": "foo",
86+
"ordering": "userDefined",
87+
"params": {
88+
"filters": "brand:adidas"
89+
}
90+
}
91+
},
92+
"position": 2,
93+
"length": 1
94+
}
95+
]
96+
}
97+
}
98+
}
99+
},
100+
"request": {
101+
"path": "/1/compositions/my-external-injection-compo",
102+
"method": "PUT",
103+
"body": {
104+
"objectID": "my-external-injection-compo",
105+
"name": "my first composition",
106+
"behavior": {
107+
"injection": {
108+
"main": {
109+
"source": {
110+
"search": {
111+
"index": "foo"
112+
}
113+
}
114+
},
115+
"injectedItems": [
116+
{
117+
"key": "injectedItem1",
118+
"source": {
119+
"external": {
120+
"index": "foo",
121+
"ordering": "userDefined",
122+
"params": {
123+
"filters": "brand:adidas"
124+
}
125+
}
126+
},
127+
"position": 2,
128+
"length": 1
129+
}
130+
]
131+
}
132+
}
133+
}
134+
}
64135
}
65136
]

tests/CTS/requests/composition-full/search.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,54 @@
1313
"params": { "query": "batman" }
1414
}
1515
}
16+
},
17+
{
18+
"parameters": {
19+
"compositionID": "foo",
20+
"requestBody": {
21+
"params": {
22+
"query": "batman",
23+
"injectedItems": {
24+
"injectedItem1": {
25+
"items": [
26+
{
27+
"objectID": "my-object-1"
28+
},
29+
{
30+
"objectID": "my-object-2",
31+
"metadata": {
32+
"my-key": "my-value"
33+
}
34+
}
35+
]
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"request": {
42+
"path": "/1/compositions/foo/run",
43+
"method": "POST",
44+
"body": {
45+
"params": {
46+
"query": "batman",
47+
"injectedItems": {
48+
"injectedItem1": {
49+
"items": [
50+
{
51+
"objectID": "my-object-1"
52+
},
53+
{
54+
"objectID": "my-object-2",
55+
"metadata": {
56+
"my-key": "my-value"
57+
}
58+
}
59+
]
60+
}
61+
}
62+
}
63+
}
64+
}
1665
}
1766
]

0 commit comments

Comments
 (0)