Google

Client Login.



Justin Long // ExpressionEngine Expert

Adding Search to my Tumblr Styled Blog

Written by: Justin Long | On: March 13, 2011

The Problem

When I created my Tumblr styled blog I was looking for 1 thing and 1 thing only and that was to simplify my Publish and Edit pages in the Control Panel. I have a lot of content going on behind the scenes for managing my clients and business and having 5 or 6 new channels for my blog was something that I did not desire. So using one of ExpressionEngine's new feature I created 1 channel with 1 field group that contained all of the custom fields that I needed for all the different outlets of content that I might want to release and used a Publish Layout to create tabs for each outlet. This has been working great, I absolutely love it and don't think I will change it anytime soon. With my blog contained in one channel I am able to bridge the gaps of the outlets so I can publish a blog post and attach a file without having to add a relationship or an extra field that would rarely be used.

As the amount of content that I add to my blog increases I was realizing that I needed to allow a way for my site visitors to search for content instead of having to sift through pages and pages of paginated content. So I turned to EE built in Search Module for better or worse, it is not my favorite EE module by any means but for a simple search it should work great. So I open up Coda and quickly add a search form and results page. Do a couple of test for known keywords on my site and everything looks great except for all of the entries that do not fall into the blog outlet of my site have no excerpt content. My problem is that ExpressionEngine only allows you to dedicate 1 field as an excerpt for search results, and I had dedicated the blog summary as my field in the Channel Preferances.

Picking a Solution

After a little bit of looking around I came up with a few solutions that I could use:

  • Low Google Search

    The only problem with this approach is that there is at least a $100 yearly fee (from Google), which isn' that bad but not exactly what I am looking for.
  • Solspace Super Search

    This add-on is a power house for search results and to be honest is more then I need for my blog.
  • Planet-EE Search Results

    Allows for me to use custom fields in my search results along with a few other great features like search term highlighting and grouping by channel.
  • Custom Queries and PHP

    This option wouldn't cost anything but it is not portable across multiple EE installs without rewriting the queries for each site.
I ended up using Planet-EE's Search Results module on my site because it offered the ability to use custom fields and also allowed me to easily add search term hilighting and at $39 it cost me less time then writing custom queries to achieve the same result.

The Template Code

Here is the template code that I have for my search results template

<h1>Search Results</h1>
<
a href="{exp:key_search:referring_page}">Return to Previous Page</a><br />
Searched results for: <span class="terms">{exp:search:keywords}</span>

<
ul>
{exp:key_search:results 
    custom
="yes" 
    
switch="search_odd|search_even" 
    
orderby="entry_date" 
    
sort="desc" 
    
highlight="yes" 
    
disable="categories"
}
<li class="{switch}"><strong><a href="{auto_path}">{title}</a></strong><br />
{if blog_journal_summary != ""}    
  {blog_journal_summary size
="40"}
{
/if}
{if blog_link_description 
!= ""}
  {blog_link_description size
="40"}
{
/if}
{if blog_photo_description 
!= ""}
  {blog_photo_description size
="40"}
{
/if}
{if blog_quote_description 
!= ""}
  {blog_quote_description size
="40"}
{
/if}
{if blog_video_description 
!= ""}
  {blog_video_description size
="40"}
{
/if}
{if blog_file_description 
!= ""}
  {blog_file_description size
="40"}
{
/if}
{read_more}
</li>
{/exp:key_search:results}
</ul

As you can see from the code it is very simple with search results to use custom fields. It also allows you to do conditionals within the search results which is great if you need/want to do some custom formatting options to the content being displayed. For the example above I did not actually need to use any conditionals but in regards to future proofing I added the conditionals. Eventually I might add a Pictos or apply specialized styling based on post type but for now the conditionals wont do any harm. Another great feature that Search Results provide is a simple tag to get the referring pages URL. I use this on my site to allow users to return to the previous page if they do not find the results that they are looking for.

Wrap Up

If you followed along with my Building a Tumblr Style Blog in ExpressionEngine and want to add search features to your site I would highly recommend Search Results from Planet-EE. It easily allows you to extend EE built in search functionality and the developers offer great support.

If you have any thoughts or comments feel free to post them in the comments below.

Next entry >>> <<< Previous entry

Comments

<<< Go back to entry list