Jetpack Search: Document Fields ⚠️

I’ve been using Jetpack Search for a while now and I recently stumbled upon this awesome feature – document fields.

It’s been a real game-changer for me and I thought I’d share it with you.

Diving Deeper into the Search: Document Fields




Let’s talk about the core of Jetpack Search the Elasticsearch documents.

You see each search result is treated as a distinct document and there’s just one document type used by default.

If you want to get really technical you can check out the open-source code for the index building process but I’ll give you a breakdown here.

Understanding the Fields

Now the real magic happens with the document fields.

These fields are the building blocks of each search result.

Think of them as information containers each holding specific data about your posts.

I’m going to go over some of the most important ones but keep in mind some details might change with Gutenberg indexing.

Language Matters: The ‘Lang’ Fields

The ‘lang’ fields are crucial because they handle language analysis.

By default there’s a general analysis process for text fields but there are also custom analysis options for 29 different languages – everything from Arabic to Chinese.

You can find the code for these language analyzers online.

The way Jetpack figures out the post language is pretty clever.

It looks at the title content and excerpt to detect the language.

If it can’t figure it out it defaults to the blog’s configured language.

The ‘Author’ Field

The ‘author’ field is straightforward.

It points to the WordPress.com user who wrote the post.

Now if you’re using Jetpack on a self-hosted site there might be times when the corresponding WordPress.com user can’t be identified and in those cases the ‘author_id’ will be set to 0.

Analyzing Content: The ‘Content’ Fields

Jetpack processes post content meticulously.

HTML and shortcodes are stripped and it analyzes the language to index it correctly into the relevant ‘lang’ field.

But it doesn’t stop there – the content is also added to the default fields.

Taxonomy Flexibility: The ” Fields

Now this is where things get interesting.

Taxonomy fields are dynamic meaning the name of the field changes based on the name of the post taxonomy.

So if you have a taxonomy called “Categories” you’d have a ‘categories’ field and if you have a taxonomy called “Tags” you’d have a ‘tags’ field.

Jetpack uses a hardcoded list of taxonomies that are indexed but I wouldn’t be surprised if this list changes in the future.

Dates: Granularity is Key

To make granular date-based searches a breeze dates are stored in two ways: as a date data type and broken down into individual tokens.

This lets you search for posts published on a specific day of the week modified within a specific time frame and much more.

For example you could find all posts published on Tuesdays (date_token.day_of_week) or modified in the second half of each hour (modified_token.seconds_from_hour).

Post Meta: Dynamic Fields

The ‘post_meta’ fields are also dynamic and the ” part of the field name depends on the name of the post meta being indexed.

To accommodate advanced queries all post meta values are cast and indexed as numbers booleans and strings.

This flexibility gives you the power to search using a variety of conditions.

Beyond the Basics: Jetpack Search API

For developers Jetpack Search has a powerful API that lets you customize search behavior.

It’s a great way to enhance your website’s search functionality.

I’ll go over some key aspects of the API:

Customizing Search Results

The Jetpack Search API allows you to modify the way search results are displayed.

You can:

  • Re-order results: If you want certain types of content to appear higher in search results you can use the API to adjust the ranking algorithm. This can be helpful for promoting important pages or posts.
  • Filter results: Need to restrict search results to specific categories or taxonomies? The API lets you filter results based on different criteria ensuring users only see relevant information.
  • Highlight search terms: This is a great way to make search results more readable and visually appealing. The API allows you to highlight the search terms within the results making it easier for users to scan the content.

Leveraging Custom Fields

One of the most powerful features of the API is the ability to work with custom fields.

This opens up a whole new world of search possibilities:

  • Indexing custom data: You can use the API to index your custom data allowing users to search based on unique attributes. This could be anything from product categories or pricing to location information or event dates.
  • Creating custom search filters: You can build custom search filters based on your custom fields giving users more refined control over their searches. Imagine creating a filter for a specific product category or a location-based filter for events.

Understanding the Power of Jetpack Search

When you dive into the inner workings of Jetpack Search you realize it’s not just a simple search engine.

It’s a sophisticated system that leverages Elasticsearch to deliver accurate and relevant results.

By understanding the document fields and the API you can unlock its true potential and create truly custom search experiences for your website.

Remember Jetpack Search is constantly evolving so stay up-to-date on the latest features and updates.

This will help you get the most out of this fantastic tool and provide your users with the best possible search experience.




Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top