Can you use wild cards (*) or blank/null values when filtering?


#1

I need to be able to filter by a wildcard or if the field is blank. Is this possible?

$('.element').swiftypeSearch({
  ...
  filters: {
    page_type: ['*', 'resource', ''],
  }
  ...
});

#2

Great question! It’s not possible to filter via a wildcard or null value, but you can use the bang operator to request results that do not match to the stated value or array. For example, if you have 2 page_type values (resource & category) and want to return only content with no set page_type value, you’d declare the filter option like so:

filters: {
     "YOUR_DOC_TYPE": {
          "page_type": ["!resource", "!category"]
     }
}

#3

Any plans on adding support for wildcards or NULL values? I’m especially interested in NULL value support. The engine I am setting up could benefit from hiding search results that don’t have values defined for particular field(s). For example, if a page does not have a custom field defined in its meta tags, and that field does not exist in the JSON object.

Thanks!


#4

Nothing on the roadmap just yet to filter out document records that are absent a specific field or contain no values for that field. I’ll log the feedback to JIRA though. :slight_smile:


#5

Much appreciated!:smiley:

Do you publish the current development roadmap anywhere?

Thank you.