Filter for specific multiple attributes

Hello,

im trying to do a search to find storys with specific attributes like “name” and “description”.

What im actually doing is:

async searchItems() {
const data = await this.$storyapi.getAll(‘cdn/stories’, {
starts_with: ‘items/’,
filter_query: {
description: {
ike: ‘’ + this.searchInput + '’,
},
name: {
ike: ‘’ + this.searchInput + '’,
},
},
})

But trying so, i only get the items if my searchterm matches the description AND the name. But i want to get the item if any of the attributes matches. Is there any possibility to do this with one storyblok request?

Thank you!

Hello @aaaleeex7,

for cases like yours, we introduced the parameter filter_query_v2 Add OR / AND / XOR to the filter_query for condition connections · Issue #94 · storyblok/storyblok · GitHub.

The following example represents an AND query:

Storyblok.get('cdn/stories', {
    filter_query_v2: {
        "option1": {
            "in": "value1"
        },
        "option2": {
            "in": "value2"
        }
    }
}).then((response) => {
    console.log(response.data);
})

Here are further examples :

Example with “or”:

Storyblok.get('cdn/stories',
  {
    "filter_query_v2":{
        "__or":[
          {
              "headline":{
                "in":"tom"
              }
          },
          {
              "component":{
                "in":"news"
              }
          }
        ]
    }
}).then((response) => {
  console.log(response.data);
})

Example with “is empty”:

Storyblok.get('cdn/stories',
  {
    "filter_query_v2":{
        "asset.filename":{
          "is":"empty"
        }
    }
  }
).then((response) => {
  console.log(response.data);
})

Example with is “not empty”:

Storyblok.get('cdn/stories',
  {
    "filter_query_v2":{
        "asset.filename":{
          "is":"not_empty"
        }
    }
  }
).then((response) => {
  console.log(response.data);
})
Storyblok.get('cdn/stories',
  {
    "filter_query_v2":{
        "asset.filename":{
          "is":"null"
        }
    }
  }
).then((response) => {
  console.log(response.data);
})
Storyblok.get('cdn/stories',
  {
    "filter_query_v2":{
        "asset.filename":{
          "is":"not_null"
        }
    }
  }
).then((response) => {
  console.log(response.data);
})
Storyblok.get('cdn/stories',
  {
    "filter_query_v2":{
        "asset.filename":{
          "is":"not_empty"
        },
        "__and":{
          "is":"not_null"
        }
    }
  }
).then((response) => {
  console.log(response.data);
})

Best regards
Hannes

Hello @Hannes,

thank you very much! This is exactly what i was looking for! :slight_smile:

1 Like