• Get In Touch
May 31, 2017

WordPress – How to add a Powerful Search Capability

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

From the Dogpiles to the AltaVistas, search engines have come a long way indeed. Some are now defunct, some are struggling while others continue thriving. The current big guys are Google, Bing and Yahoo. We humans, since time immemorial, have always had this strong inner desire to know. This curiosity and courage to go beyond our limits. It’s true we have plenty of problems here on earth, but that won’t stop us from exploring the moon or outer space. We scan the heavens for celestial bodies that are millions of light years away. We try to determine the edge of the Universe. We are obsessed with trying to understand black holes. Or quantum physics. Why? Why all these? Well, because we want answers. It’s why we try every day to search for answers. We are hard-wired to search for answers. Where did we come from? Why are we here? How did the Universe begin? When and how will it end?

We humans are curious by nature. Some people think that’s why our brains have developed so well compared to other creatures. We push ourselves to the limit. It’s why we search. Not only do we search for heavenly answers, we also search for answers right within our backyard here on earth? Answers to common day to day questions. Like who scored for Manchester United versus Ajax? Or how can we format a HTML document? Or who created WordPress? It’s why we have search engines, to help us answer questions like these.

The most popular search engine is Google. It was created by Larry Page and Sergey Brin. Initially it was called Backrub. From the moment of its creation, it stood out from the rest. It was different. While other search engines focused on the obvious keyword relevance, Backrub used the number of backlinks to a page to determine the search engine ranking. It’s now obviously much more complex than that. However, it has demonstrated how important it is to have a good search engine. A search engine that gives you intelligent answers. Google is now one of the most valuable companies in the world. It is the search engine that’s contributed to that more than any of their wide range of products.

We are not going to develop another search engine to compete with Google today. However, before we think that big, we need to look inwards first: our website’s search engine.

WordPress has an inbuilt search engine and it’s nice, it works. However, for a large site, you may want to be more ambitious. In relation to the search functionality we can get from some free plugins, wordpress’ default search is just too basic. The only way to customize it is to get your hands greasy with code.

# Objective of this Lesson

The main of objective of this lesson is to:

  • Build a powerful search engine that’s not only accurate but also gives us control of the logic used to generate the results. This means we can experiment with several customizations to see which one is accurate for our users.

Pre-requisites

We assume that you:

  • Already have a working wordpress installation, hosted either remotely or locally. You may also need internet connectivity to install our plugin, which is actually a few Kilobytes.

Why we are using Relevansi?

The plugin we are using is called Relevansi. It’s the most popular search plugin as of now. I’m not surprised by that as I have used it in my personal projects. Here’s why we are using it:

  1. It’s free and easy to use.
  2. You build the search index manually. This then gives us control over the content we would like to be searchable. We can for instance leave some custom post types or taxonomies out of our index.
  3. It can expand shortcodes. I love this. I really do. It’s probably the number one reason I discovered relevansi last year. What we mean here is that when searching, Relevansi will execute the content of shortcode and index the result as well. For instance, say you are fetching some data from a third party site via an API, and you need this data searchable to users. In the default search or many other plugins, that data won’t be available. It’s not in your database, so users won’t be able to get any results. However, with Relevansi, that data will be factored in the search results as well. Not only that but you can also disable this feature as we shall see later.
  4. It automatically scans and lists stopwords for you. Moreover, you can also add the stopwords yourself. But what are stopwords? Mmm! They are useless words. These are words that appear in any every document and don’t really influence search results. Examples: a, the, me, again, all, can etc. Furthermore, removing them makes the index much smaller hence improving search performance.
  5. It also provides something seemingly simple but extremely powerful: default operator for search, that is ‘OR’ and ‘AND’ for your queries. ‘OR’ is used when any term is present while in ‘AND’ all terms are present. A simple switch of either of these two causes massive differences in your results. Try it out.
  6. And hey, its default order for results is another reason we are using it. Relevansi defaults to relevance first, not date, however you can switch to what you like.
  7. You can also limit search results. If you do so relevansi limits to the first 500 results.
  8. And one of the best features right here: weights. Relevansi allows you to assign weights to various post types and taxonomies. You do this simply by entering integers. Say you want to give more priority to some custom post types, then assign more weight to that custom post type. This is great, I have seen some search plugins which don’t even include custom post types in their results, let alone assigning weights.
  9. You can choose whether to index post authors, post excerpts and comments as well.
  10. Look, the advantages are many. Let’s proceed to installation.

Installation

To install relevansi:

  • Head over to the plugins directory. Type ‘relevansi’. Search.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/17773205.png” alt=”Search Relevansi” />

  • Install it by clicking ‘Install Now’ button.
  • Activate it.

Settings/Configurations

The best thing about Relevansi is that it has plenty of really useful and powerful features that can enhance our search functionality. We have listed majority of these features in the ‘Advantages’ section above. Now settings page is just a matter of enabling or disabling a given option.

  • First let’s build our index. Relevansi search doesn’t work without you building the index. It needs to index your content according to your settings. Just click the ‘Build Index’ button as shown below we proceed.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/1338095527.png” alt=”Build Index” />

  • Well, my content here has just been indexed.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/1078974546.png” alt=”Index Complete” />

  • Here’s our basic options page. You can change the default operator, limit search results, define search results order etc.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/280795059.png” alt=”Basic Options Settings” />

  • We also have log settings. We have exclusions as well. We can exclude certain post types, pages, categories or tags.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/1510119404.png” alt=”Logs and Restrictions” />

  • We can highlight search results. We can define search highlight CSS.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/1948359018.png” alt=”Search Highlighting” />

  • We also have indexing options. Choose the post types or taxonomies you want indexed.
    HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/1265352745.png” alt=”Indexing Options” />

  • We can also choose to include whether to expand shortcode contents during indexing. Moreover we can choose whether to index comments, authors and post excerpts.

HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/2118638845.png” alt=”More Indexing Options” />

Note that:

Relevancy will use the default search form as long as you have activated it and built the index.

Let’s see a simple example with highlighting below:
HP_NO_IMG/data/uploads/users/a4c0adcd-8650-4b65-9b01-9dd628e70757/237023850.png” alt=”Search Results” />

Conclusion

Just like airports are the gateway to any country or city, search engines are gateway to the web. One of the reasons Google has been able to dominate the search market is because of its clean and concise interface. The age of people browsing through multiple pages just looking for some piece of content is over. The answer should always be just a search away.

It’s therefore important you get your personal website’s search engine accurate and relevant. It’s very simple, if it’s not accurate then definitely the user won’t find your content. He’ll go elsewhere of course. A good search engine should be customizable. Different inputs should lead to different results.

We’ve looked at some of the features that make relevansi powerful. Features like assigning weights, manual indexing, stopwords, shortcode expansion etc. You should always build your index as you add more and more data. You don’t have to start from the beginning, you can continue the build from where you left.

The reality is we humans will always continue asking questions, searching for answers. Be it when we look to the heavens, or even when I visit your site. I won’t be browsing through hundreds of pages, I promise. I will search. If you have a good search system, I will find what I want and I will stay and be coming back. If you don’t have it I will go. And God knows what may bring me back. Let’s therefore use plugins like relevansi for better search.

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]