This is the first of what I intend to be a series of notes on WordPress and general installation, customization, development issues. I’ll mainly try to note what I’m doing as I do it, though in future entries I may also seek to catch up on and review what I’ve learned over the course of years working with WordPress and other Open Source applications, from my first efforts hacking PHP, CSS, and JAVA code that I only just barely understood, to writing my first functions and plug-ins the “right way” or as right as I can figure out how to do it.
On both The YIR site and this site I was dissatisfied with built-in WordPress search capabilities – a common complaint. For me, the main limitations included inability to customize search operations and results easily. A further problem over on The YIR was that searches were giving results for pages not normally visible to non-members.
After a morning’s research into available options, I briefly considered purchasing one or another commercial plug-in (something I try to avoid in honor of my Scottish heritage, also because I’m poor, also because I learn a lot from hacking imperfect or incomplete or just for my purposes inadequate open source code) and settled on the “Relevanssi” plug-in, which, in addition to featuring a quaint name (from the Finnish, apparently), I know has been around for a few years. . There are other capabilities I’ll want to explore for the YIR and elsewhere, but my first goals – of tailored and relevant search results were achieved.
There were, however, some problems worth noting, including one relatively major one that’s still open.
1. When indexing a relatively large WordPress database, Relevanssi will seem to hang, and produce a blank page. Not really a problem, since, if you re-load the plug-in settings page, it will show you the progress you’ve made, and let you “Continue” building where you left off, and you can also adjust it to try to index a larger number of “documents” (posts, pages, author profiles, whatever else you’ve set it to gather) than the default 500. The instructions even at the Relevanssi site are not clear on this fact. It’s also not immediately clear that indexing will in normal use not need to be repeated – that new or changed posts will automatically be added to the index when published or saved. (It is not clear to me at this point whether comments, if included in initial indexing, will also automatically be added. I’ll want to look into this question after I’ve solved the broken-format problem below.)
2. Some, perhaps most, WordPress themes will default to navigation headings that read “Older Posts” and/or “Newer Posts” when results are paginated (as according to WordPress Settings). If, as strongly recommended by Relevanssi’s developer Mikko Saari right there on the settings page, you’re instead ordering results by relevance, you will need to modify search.php. The file will vary from theme to theme. In the “Responsive” theme that I’m working with, search.php embeds a second file loop.nav, also used by other files for pagination purposes, meaning that I either wouldn’t want to alter it, or, if I altered it, I’d have to introduce context-sensitive conditionals (i.e., identify referrer, identify type of post/page, etc.). I’m sure that’s possible, and would arguably be more elegant. But it was easier just to copy the code from loop.nav, insert it in search.php, and replace the text “Older Posts” with “Less Relevant Results.”
3. Unexpected formatting results may occur if you try to utilize Relevanssi’s very useful custom snippets features, which allow for highlighting of search terms in results, and for producing relevant statistics (number of hits, where located, etc.).
Using the Relevanssi default snippet setting to “characters,” I got results that completely disrupted the layout in one case – suggesting an unclosed “div” tag – and in another case seemed to open a boldface tag without closing it. When I tried switching over to “words” instead of “characters,” the layout disruption disappeared, but a new character formatting problem appeared involving an italics tag. I’ve temporarily removed comments from search results, though this functionality is highly desirable to me at least for this blog (and though removing them required a re-build of the index).
It will take some more research and testing to resolve this problem – first to ascertain whether it’s a common problem for Relevanssi installations (with an easy common solution), second whether it occurs often enough to justify working it out at this time.
0 comments on “Customizing WordPress Search with Relevanssi”
We are determined to encourage thoughtful discussion, so please be respectful to others. We also provide a set of Commenting Options - comment/commenter highlighting and ignoring, and commenter archives that you can access by clicking the commenter options button (). Go to our Commenting Guidelines page for more details, including how to report offensive and spam commenting.
1 Pings/Trackbacks for "Customizing WordPress Search with Relevanssi"
[…] to note, the disrupted formatting issue on Relevanssi search seems to have been solved, but the solution led to new complications and new open issues currently […]