Skip to content

Commit 7306a12

Browse files
committed
feat: cql2 filter extension for GET
1 parent 94f6278 commit 7306a12

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

src/lib/api.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ const extractCql2Filter = function (params) {
268268
let cql2Filter
269269
const { filter } = params
270270
if (filter) {
271-
if (typeof filter !== 'object') {
272-
throw new ValidationError('Invalid filter value, must be a JSON object')
271+
if (typeof filter === 'string') {
272+
const parsed = JSON.parse(filter)
273+
cql2Filter = parsed
273274
} else {
274275
cql2Filter = { ...filter }
275276
}

tests/system/test-api-search-get.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,37 @@ test('/search preserve bbox and datetime in next links', async (t) => {
108108
t.deepEqual(nextUrl.searchParams.get('bbox'), bbox)
109109
t.deepEqual(nextUrl.searchParams.get('datetime'), datetime)
110110
})
111+
112+
test('/search filter, query, and item search in single request', async (t) => {
113+
const fixtureFiles = [
114+
'collection.json',
115+
'collection2.json',
116+
'LC80100102015050LGN00.json',
117+
'LC80100102015082LGN00.json',
118+
'collection2_item.json'
119+
]
120+
const items = await Promise.all(fixtureFiles.map((x) => loadJson(x)))
121+
await ingestItems(items)
122+
await refreshIndices()
123+
124+
const response = await t.context.api.client.get('search', {
125+
searchParams: new URLSearchParams({
126+
collections: ['landsat-8-l1'],
127+
query: JSON.stringify({
128+
'view:sun_elevation': {
129+
gt: 20
130+
}
131+
}),
132+
filter: JSON.stringify({
133+
op: '>',
134+
args: [
135+
{
136+
property: 'eo:cloud_cover'
137+
},
138+
0.54
139+
]
140+
})
141+
})
142+
})
143+
t.is(response.features.length, 1)
144+
})

tests/system/test-api-search-post.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,9 @@ test('/search preserve bbox in prev and next links', async (t) => {
537537
t.deepEqual(linkRel(response, 'next').body.bbox, bbox)
538538
})
539539

540-
test('/search Query Extension', async (t) => {
540+
test('/search query extension', async (t) => {
541541
let response = null
542542

543-
// 3 items, 2 with platform landsat-8, 1 with platform2
544-
545543
response = await t.context.api.client.post('search', {
546544
json: {}
547545
})
@@ -644,20 +642,14 @@ test('/search Query Extension', async (t) => {
644642
t.is(response.features.length, 0)
645643
})
646644

647-
test('/search Filter Extension - Null filter', async (t) => {
648-
// 3 items, 2 with platform landsat-8, 1 with platform2
649-
650-
let response = null
651-
652-
response = await t.context.api.client.post('search', {
645+
test('/search filter extension - empty filter', async (t) => {
646+
const response = await t.context.api.client.post('search', {
653647
json: {}
654648
})
655649
t.is(response.features.length, 3)
656650
})
657651

658-
test('/search Filter Extension - Comparison Operators', async (t) => {
659-
// 3 items, 2 with platform landsat-8, 1 with platform2
660-
652+
test('/search filter extension - comparison operators', async (t) => {
661653
let response = null
662654

663655
// equal
@@ -786,9 +778,7 @@ test('/search Filter Extension - Comparison Operators', async (t) => {
786778
t.is(response.features.length, 3)
787779
})
788780

789-
test('/search Filter Extension - Logical Operators', async (t) => {
790-
// 3 items, 2 with platform landsat-8, 1 with platform2
791-
781+
test('/search filter extension - logical operators', async (t) => {
792782
let response = null
793783

794784
// and
@@ -931,12 +921,8 @@ test('/search Filter Extension - Logical Operators', async (t) => {
931921
t.is(response.features.length, 0)
932922
})
933923

934-
test('/search Filter Extension - Timestamps', async (t) => {
935-
// 3 items, 2 with platform landsat-8, 1 with platform2
936-
937-
let response = null
938-
939-
response = await t.context.api.client.post('search', {
924+
test('/search filter extension - handles timestamps', async (t) => {
925+
const response = await t.context.api.client.post('search', {
940926
json: {
941927
filter: {
942928
op: '>',
@@ -952,10 +938,8 @@ test('/search Filter Extension - Timestamps', async (t) => {
952938
t.is(response.features.length, 1)
953939
})
954940

955-
test('/search Combined Item Search and Filter and Query Extensions', async (t) => {
956-
let response = null
957-
958-
response = await t.context.api.client.post('search', {
941+
test('/search filter, query, and item search in single request', async (t) => {
942+
const response = await t.context.api.client.post('search', {
959943
json: {
960944
collections: ['landsat-8-l1'],
961945
query: {

0 commit comments

Comments
 (0)