This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

File content search in WordPress with Ajax Search Pro

By Ernest Marcinko
April 17, 2024

Did you know that one of the core features of Ajax Search Pro is the ability to search PDFs, Word documents, Excel spreadsheets, and other well-known file contents? Now you do!

Not only that, but it can display the context of the search phrase from the file contents in the live search results list – which is pretty cool and extremely helpful.

How to set it up

There is extensive documentation for indexing file contents, but in this tutorial, I’m going to streamline it to its core and make it super easy. In this tutorial I’m going going to:

  • Create a new search bar and put it on a test page
  • Upload a test PDF document
  • Getting a media service key for most accurate indexing – for free
  • Configure the plugin to index the PDF files
  • Configure the search bar to search the PDF files+

Do you have a license yet?

Search bar on a page

For this example, I am creating a new search instance and placing it on a page via a block editor block. You can also use the shortcode to place the search bar anywhere – that will work as well.

To create a search instance, open the Ajax Search Pro menu, choose a search name, and click the “Add” button.

Grab the shortcode if you like, or use the Block editor to insert it onto a page.

Uploading a test document

You can skip this test, as I assume you already have some files you want to index.

Media Service key

This step is also optional but highly recommended – it’s free for files up to 10MB, which is sufficient for most users.

The media service feature is running on an external server, which is specifically configured to fetch contents of the uploaded files. It is far superior to any built-in content parser available.

To get a media service key for free, open the media service page and click the “Get” button on the free tier.

Please enter your email, and you will be sent a link where your license key is generated. Take note of this key, as we will need it in just a moment.

Indexing the File Contents

This is the most important step. Under the Index Table submenu, select the “Attachment – Media” post type, and a few new options will appear.

Select to index PDF documents and also choose to index their contents.

There is also an input field to activate the media service key – remember, the one we obtained in the previous step.

After saving the options, click on the “Create New Index” button. The process will start and index all the PDF (or the MIME types you have chosen) files.

Upading the Search Configuration

Once the indexing is completed, return to the search bar configuration. Under the “Media Files Search” panel, select the “Index Table” engine.

To enable keyword highlights, go to the “Layout Options -> Highlighter” panel.

As an additional step I have also enabled auto thumbnail generation for PDF documents. On most servers it’s enabled, but you can check out the steps for it here.

As you can see, it is possible to conveniently search the contents of the media files in your Media Library, and it’s super easy to set up.

Try these: examplesfeatures