Filters in User Input

Is it possible to allow a user to add filters or select facets via the query input?

As an example, if there was a facet on the field “author”, could the user type a query along the lines of:

The Green Mile author:Stephen King

(implying to search for books titled “The Green Mile” filtered by a specific author.

Ideally I’m looking for a way to accomplish this (if possible) with the InstantSearch library.

Hey Evan,

This is completely possible using query rules. You’d write a filter for "contains": "author\\: {facet:author}". Then you’d have to remove those words from the query and apply the filter. The complete query rule would look like this:

{
  "condition": {
    "pattern": "author\\: {facet:owner.name}",
    "anchoring": "contains"
  },
  "consequence": {
    "params": {
      "automaticFacetFilters": [
        "owner.name"
      ],
      "query": {
        "remove": [
          "author\\:",
          "{facet:owner.name}"
        ]
      }
    }
  },
  "description": "facet",
  "objectID": "1528789354662"
}

In the dashboard that would look like:

haroen,

thanks so much for the example! I’m having some trouble with saving the query rule from the dashboard:

Sorry for missing this, but maybe you need an extra backslash to make it completely work :slight_smile: