Using a Dedicated Search Server like Apache SolrConsidering that WordPress search is only an exact word/phrase match, providing even an option to filter results from a particular category or post type, can be considered as an advanced option. But Apache Solr provides far more advanced search features.
- Broad Match Search: A broad match search not only matches and finds search pages, containing the exact search phrase, but also pages which contain any one of the words in the search phrase. For example, if you were searching for “WordPress Experts”, you would find pages which contain the exact phrase ‘WordPress Experts’, and pages containing the words ‘WordPress’ or ‘Experts’. Also, since ‘Experts’ is plural, it would also search for ‘Expert’.
- Highlighted Search Terms: Matched words are highlighted in the search results. (Wait! WordPress default search does NOT do this?! Hmm.. Surprising.) Anyway, this might not appear to be a must have feature, it is important to improve user readability and enhance user experience.
- Filtering Options based on Taxonomies and Post Types: Apache Solr provides filtering options for search results. Filtering can allow a visitor to exactly find what he is looking for, in a short amount of time. Using Solr, filtering options can be provided for categories and post types (including custom post types).
- Spelling Suggestions: How many times do we type in an
incrrect sepllingincorrect spelling for a search word. Sometimes, users might not even realise that they have entered an incorrect search term, and leave your site, because they haven’t found what they were looking for. Solr provides ‘Did you mean correct spelling’?, suggestions to improve search experience.
Creating the Solr Search PluginWhen we took up the project, we knew we had to understand Apache Solr Server thoroughly. Having worked with Sphinx server before, helped us a bit. Solr provides numerous configuration options, which makes it really easy to provide all the above stated features. The plugin we created achieved the following:
- To communicate with Solr server, we made use of Solarium Client. Solarium client provides several in-built features and facilitates communication with Solr.
- There were configuration options provided, to connect to Solr Server. Solr configuration file was provided, to ease the set up.
- Indexes, which are an integral part of providing a quick search, can be hosted locally or remotely. We provided both options, with an option to host Solr indexes remotely, on gotosolr. Configuration options were also provided, to decide which taxonomies, and post types had to be indexed.
- Solr makes use of facets, to filter search results. Settings were provided to choose facet options. Facet options decide, which taxonomies and post types would be provided as filtering options, for the search results.
- There were options provided to sort the search results. Also, a default sorting could be set from the admin settings. Pagination was provided if the search results were many in number.
- Search results were fetched based on relevancy of search term, with relation to placement and occurrence.
- Finally, there was an option provided either to replace the default WordPress search, or to add the Solr search box on a different page.