Skip to content

Commit

Permalink
feat: cql2 filter extension for GET
Browse files Browse the repository at this point in the history
  • Loading branch information
pjhartzell committed Jan 11, 2025
1 parent 94f6278 commit 7306a12
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ const extractCql2Filter = function (params) {
let cql2Filter
const { filter } = params
if (filter) {
if (typeof filter !== 'object') {
throw new ValidationError('Invalid filter value, must be a JSON object')
if (typeof filter === 'string') {
const parsed = JSON.parse(filter)
cql2Filter = parsed
} else {
cql2Filter = { ...filter }
}
Expand Down
34 changes: 34 additions & 0 deletions tests/system/test-api-search-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,37 @@ test('/search preserve bbox and datetime in next links', async (t) => {
t.deepEqual(nextUrl.searchParams.get('bbox'), bbox)
t.deepEqual(nextUrl.searchParams.get('datetime'), datetime)
})

test('/search filter, query, and item search in single request', async (t) => {
const fixtureFiles = [
'collection.json',
'collection2.json',
'LC80100102015050LGN00.json',
'LC80100102015082LGN00.json',
'collection2_item.json'
]
const items = await Promise.all(fixtureFiles.map((x) => loadJson(x)))
await ingestItems(items)
await refreshIndices()

const response = await t.context.api.client.get('search', {
searchParams: new URLSearchParams({
collections: ['landsat-8-l1'],
query: JSON.stringify({
'view:sun_elevation': {
gt: 20
}
}),
filter: JSON.stringify({
op: '>',
args: [
{
property: 'eo:cloud_cover'
},
0.54
]
})
})
})
t.is(response.features.length, 1)
})
34 changes: 9 additions & 25 deletions tests/system/test-api-search-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,9 @@ test('/search preserve bbox in prev and next links', async (t) => {
t.deepEqual(linkRel(response, 'next').body.bbox, bbox)
})

test('/search Query Extension', async (t) => {
test('/search query extension', async (t) => {
let response = null

// 3 items, 2 with platform landsat-8, 1 with platform2

response = await t.context.api.client.post('search', {
json: {}
})
Expand Down Expand Up @@ -644,20 +642,14 @@ test('/search Query Extension', async (t) => {
t.is(response.features.length, 0)
})

test('/search Filter Extension - Null filter', async (t) => {
// 3 items, 2 with platform landsat-8, 1 with platform2

let response = null

response = await t.context.api.client.post('search', {
test('/search filter extension - empty filter', async (t) => {
const response = await t.context.api.client.post('search', {
json: {}
})
t.is(response.features.length, 3)
})

test('/search Filter Extension - Comparison Operators', async (t) => {
// 3 items, 2 with platform landsat-8, 1 with platform2

test('/search filter extension - comparison operators', async (t) => {
let response = null

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

test('/search Filter Extension - Logical Operators', async (t) => {
// 3 items, 2 with platform landsat-8, 1 with platform2

test('/search filter extension - logical operators', async (t) => {
let response = null

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

test('/search Filter Extension - Timestamps', async (t) => {
// 3 items, 2 with platform landsat-8, 1 with platform2

let response = null

response = await t.context.api.client.post('search', {
test('/search filter extension - handles timestamps', async (t) => {
const response = await t.context.api.client.post('search', {
json: {
filter: {
op: '>',
Expand All @@ -952,10 +938,8 @@ test('/search Filter Extension - Timestamps', async (t) => {
t.is(response.features.length, 1)
})

test('/search Combined Item Search and Filter and Query Extensions', async (t) => {
let response = null

response = await t.context.api.client.post('search', {
test('/search filter, query, and item search in single request', async (t) => {
const response = await t.context.api.client.post('search', {
json: {
collections: ['landsat-8-l1'],
query: {
Expand Down

0 comments on commit 7306a12

Please sign in to comment.