Atlas Search: Facets and Stemming

5 minute read · Nov 28, 2022
Grace Erixon
Grace Erixon
Associate Developer Advocate

Atlas Search (currently in beta) is an enhanced search solution for WordPress that improves search relevancy, supports advanced search query operators, and increases supported data types within the content data search. If you need an overview of Atlas Search and how to set it up on your headless WordPress site, get up to speed with our What is Atlas Search? blog post.

There are two exciting new features in Atlas Search: facets and stemming.

Facets

Facets are a type of search filter that is used to help website visitors narrow down their search results quickly. They change depending on the context of the search query. This functionality is most commonly seen on eCommerce sites – the website visitor performs a search, views all of the search results, and then has the option to refine these results further based on selecting different attributes.

Example website screen with filtering search options

The Atlas Search team has developed WPGraphQL Filter Query, an open-source plugin that pairs with the Atlas Search plugin to provide faceted search through the WPGraphQL API for headless WordPress.

The plugin currently supports four root filter query arguments:

  • Two taxonomies: ‘Tag’ & ‘Category’
  • Two relational operators: ‘or’ & ‘and’

The relational operators accept an array of root filter query objects. They cannot appear as siblings, so use one or neither per nested object. Nested filter query objects can be recursively nested up to 10 times. If no relation is declared, then ‘and’ is implied.

Setting up Faceted Search

To add the WPGraphQL Filter Query plugin, download the ZIP file from the GitHub repo, navigate to the Plugins tab in the WordPress admin sidebar, and upload the ZIP file as a plugin. If you do not already have the WPGraphQL and Atlas Search plugins from the previous What is Atlas Search? post, add, and enable those now.

Then, in the GraphiQL IDE, you can build out the query you want to run. You can filter the search by passing in either category names or tag names. Adding filters by category and tag would look like this:

query postFilterByCategoryAndTag {
  posts(
    filter: {
      category: { name: { in: ["CATEGORY_NAME"] } },
      and: [
        { tag: { name: { eq: "TAG_ONE"} } },
        { tag: { name: { eq: "TAG_TWO"} } },
      ]
    }
  ) {
    nodes {
      id
      status
      title
    }
  }
}

In this example query, I searched for posts that have the category ‘category two’ and the tag of ‘physical activity.’ WPGraphQL returned the only post that matched those two qualifications in my database.

Results from a faceted search query in GraphiQL IDE

Faceted Search Example

You do have to build your own front-end facets. For a full example of how faceted search would function in an eCommerce site, Richard McCormack built out this example faceted Atlas Search site.

Stemming

In addition, Atlas Search also has a new and improved default search. Previously, Atlas Search used fuzzy searching, which can be an expensive query and it only catches minor spelling mistakes.

For example, this query executed with fuzziness enabled returns only the post titled the exact form of the search term:

Results from a fuzzy search query in GraphiQL IDE

Atlas Search now uses stemming, which is the process of reducing a word to its root form or base word. For example, the words ‘running’ and ‘runs’ would be reduced to run. The operator is less expensive than fuzzy searching and it provides more relevant results.

With stemming enabled instead of fuzziness, the same search query also returns posts with the word ‘running’ in the title:

Results from a stemming search query in GraphiQL IDE

Stemming is the new default for Atlas Search, so you should not have to manually set it unless you have previously switched to Fuzziness. To check, navigate to the Search Config section within the Atlas Search tab on the WordPress Admin sidebar.

Stemming setting enabled in Search Config page of Atlas Search

Conclusion

Accurate search results are a key aspect of any website with search functionality. It ensures your site visitors can find what they need efficiently, which makes for a good user experience. Hopefully, this post has shown you how the additions of faceted search and stemming continue to level up the quality of Atlas Search!