You Searched For User Control in BlogEngine.NET

I received an interesting comment today about my blog.  It was really appreciative of a feature that is included within the blogging engine. Which is the “You Searched For” user control.  This takes the search query that is sent along from the search engine and matches it to a search within the local site when the referrer comes from a search engine.

What especially made me take notice is that the comment came from a member of the DotNetNuke Blog Module team. With a request to understand how this was achieved within my site.  Well I figured I could have just sent back a quick and dumb answer of it is just part of the blogging engine I use.  Which in my case is BlogEngine.NET.  Or I could do what I am doing now and go into to detail about how the blogging engine accomplishes this, which is what was really being looked for.

With that in mind I will walk through how it is accomplished as I think this would be a great control to be a part of the DotNetNuke core Blog Module as well as a module that could be used to allow people to get more search results when they land on a DNN site.  May have to build that.

There are two parts to this to make it work successfully.  The first part is the addition of the user control to skin theme for my blog site.

  1: <blog:SearchOnSearch ID="SearchOnSearch1" 
  2:     runat="server" MaxResults="5" 
  3:     Headline="You searched for"
  4:     Text="Here are some results for the 
  5:     search term on this website" />

The second part is the code that is behind this user control.  First of we have a few properties that can be configured on the control

Properties:

  1. MaxResults: This is the maximum number of results to return to the page if there are any found.
  2. Headline: This is the headline to display for the control when it returns search items found.
  3. Text: This is the text to be displayed below the headline and above the search results.

Class Implementation:

  1: 
  2:  public class SearchOnSearch : Control
  3:  {
  4:      private static Regex _rxSearchTerm = null;
  5:  
  6:      static SearchOnSearch()
  7:      {
  8:  	// Matches the query string parameter "q" and 
  9:         // its value.  Does not match if "q" is blank.
 10:  	_rxSearchTerm = new Regex("[?&]q=([^&#]+)", 
 11:              RegexOptions.Compiled | 
 12:              RegexOptions.IgnoreCase | 
 13:              RegexOptions.CultureInvariant);
 14:      }
 15:  
 16:      public override void RenderControl(
 17:           HtmlTextWriter writer)
 18:      {
 19:   	string html = Html();
 20:   	if (html != null)
 21:   	    writer.Write(html);
 22:      }
 23: 
 24:     /// <summary>
 25:     /// Checks the referrer to see if it qualifies as a search.
 26:     /// </summary>
 27:     private string Html()
 28:     {
 29:         if (Context.Request.UrlReferrer != null 
 30:             && !Context.Request.UrlReferrer.ToString().Contains(
 31:             Utils.AbsoluteWebRoot.ToString()) && IsSearch)
 32:         {
 33: 	    string referrer = HttpContext.Current.Request.UrlReferrer.ToString().ToLowerInvariant();
 34: 	    string searchTerm = GetSearchTerm(referrer);
 35: 	    List<IPublishable> items = Search.Hits(searchTerm, false);
 36:             if (items.Count == 0)
 37:                 return null;
 38:             return WriteHtml(items, searchTerm);
 39: 	}
 40: 
 41: 	return null;
 42:     }
 43: 
 44:     /// <summary>
 45:     /// Writes the search results as HTML.
 46:     /// </summary>
 47:     private string WriteHtml(List<IPublishable> items, 
 48:         string searchTerm)
 49:     {
 50: 	int results = MaxResults < items.Count ? MaxResults : items.Count;
 51: 	StringBuilder sb = new StringBuilder();
 52: 	sb.Append("<div id=\"searchonsearch\">");
 53: 	sb.AppendFormat("<h3>{0} '{1}'</h3>", Headline, HttpUtility.HtmlEncode(HttpUtility.UrlDecode(searchTerm)));
 54: 	sb.AppendFormat("<p>{0}</p>", Text);
 55: 	sb.Append("<ol>");
 56: 
 57: 	for (int i = 0; i < results; i++)
 58: 	{
 59: 		sb.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", items[i].RelativeLink, items[i].Title);
 60: 	}
 61: 
 62: 	sb.Append("</ol>");
 63: 	sb.Append("</div>");
 64: 
 65: 	return sb.ToString();
 66:     }
 67: 
 68:     /// <summary>
 69:     /// Retrieves the search term from the specified referrer string.
 70:     /// </summary>
 71:     private string GetSearchTerm(string referrer)
 72:     {
 73: 	string term = string.Empty;
 74: 	Match match = _rxSearchTerm.Match(referrer);
 75: 	if (match.Success)
 76: 	{
 77: 		term = match.Groups[1].Value;
 78: 	}
 79: 
 80: 	return term.Replace("+", " ");
 81:     }
 82: 
 83:     /// <summary>
 84:     /// Checks the referrer to see if it is from a search engine.
 85:     /// </summary>
 86:     private bool IsSearch
 87:     {
 88: 	get
 89: 	{
 90: 		string referrer = HttpContext.Current.Request.UrlReferrer.ToString().ToLowerInvariant();
 91: 		return _rxSearchTerm.IsMatch(referrer);
 93:     }
 94:  }

As we can see from the class it checks to see if there is a query “q” attached to the referring url to see if this comes from a search engine. If it does then we want to search the site and see if we have any posts that we can display to the user.

This is really neat and helpful for users.

kick it on DotNetKicks.com

Posted on 3/22/2009 1:48:26 AM by omacdon

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: DotNetNuke | BlogEngine.NET | ASP.NET | Programming

Tags: , , ,

DotNet Blog Engine Version 1.4.5 has been released

Mads Kristensen has just announced the release of Version 1.4.5 of the DotNet Blog Engine.  Guess I really have to start getting this blog site up to the latest version.  I’m a bit behind in updating my site and it has suffered for it, but back to the announcement.

The changes that have been implemented in this update:

  • File upload improvement – Files and images uploaded will be placed in folders based the year and month. IE /files/2008/07/test.jpg
  • Database Support out of the box – With this release the setup folder has support and instructions to get started with Sql Server, MySql, SQLite and VistaDB Express.
  • HTML Editor Defaults – There is now a switch to remember to use the TinyMCE editor or to enter your own HTML and now the engine remembers your choice.
  • Enhanced Metaweblog API – You can now publish for any user from within Windows Live Writer as well as support for SSL now as well
  • Filter by APML – You can now filter your posts of a blog by your own APML file. An APML file is a prioritized list of your own interests in XML.

The latest can be downloaded here.


del.icio.us Tags: ,,

kick it on DotNetKicks.com

Posted on 8/1/2008 5:24:07 PM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: BlogEngine.NET | ASP.NET | Software

Tags: , ,

Introducing Waegis : Keyvan Nayyeri

Interesting note for Blogengine.net developers who are looking for some alternate extension ideas. There is a new spam filtering service that is currently being placed out there in the wild in alpha format. This is written entirely in .NET and should be something worth looking at in the next couple of months to see if he can carry through with his ambitious plans for this new service.

Introducing Waegis

del.icio.us Tags: ,,

kick it on DotNetKicks.com

Posted on 5/13/2008 6:01:00 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: ASP.NET | BlogEngine.NET | Programming

Tags: , ,

Get News and Alerts about BlogEngine.net

For anyone who uses the blogengine.net blog for their site and would like to be kept up to date.  Check out the following link to get information about vulnerabilites and news about what is happening with our beloved blog engine.

BlogEngine Alerts Subscription

del.icio.us Tags: ,

Technorati Tags: ,

kick it on DotNetKicks.com

Posted on 4/24/2008 6:29:14 PM by admin

Permalink | Comments (2) | Post RSSRSS comment feed |

Categories: ASP.NET | BlogEngine.NET

Tags: ,

New Blogengine.net extensions available

I'm going to be creating a page of extensions that are available for BE very soon.  But until then I thought it would be beneficial for me and also for all my readers that are using BlogEngine.net to have an archive of the extensions as I find them on the Internet.  Here will be the first round of posting for everyone to enjoy.

  1. Simple BlogEngine.net Download Counter Extension - Al Nyvelt has released his simple counter into the wild. This counter is designed to simply count the downloads of files that are handled by the file handler and not simply by downloading them from the site itself.  This is just a basic one and does not display the counter to the public only once you login do you see the results with the file link.
  2. Download Counter Extension - This download counter provides more detailed information in the admin section about the files that were downloaded and by what host.
  3. Google Tracker Extension - Chris Blankenship has released a basic Google Analytics tracker extension that simply allows you to insert the tracking id for your account. 
  4. Track file downloads - BlogEngine Extension and Control - And not to be outdone Chris Blankenship has also created a file download counter that not only does the file downloads but stores the information into an xml file with the ip address, date and number of times the file was downloaded.  So this brings the count up to 3 so far on the download counter extensions.
  5. Updated DotNetKicks button - Chris has also released an updated DotNetKicks extension for us.  It has a couple of improvements over the original one written at Flawless code's website
  6. Page Load Time - BlogEngine.Net Control - This one is not an extension per se, but is a control for displaying the time that it takes for a page to load within the BlogEngine framework.
  7. CommentRelish - BlogEngine.Net Extension - Chris has created an extension based on the Wordpress plugin of the same name.  This extension is developed to increase the readership of your blog by sending out an email to first time commentors on your blog.
  8. New BlogEngine.NET Extension - Toolbox - This extension by Danny Douglass allows you to save links and manage them through an admin page on your BE site.

del.icio.us Tags:

Technorati Tags:

kick it on DotNetKicks.com

Posted on 2/7/2008 6:01:07 AM by admin

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: BlogEngine.NET

Tags:

Free BlogEngine.net Themes

benlogo80Well seeing at how this is a new blogging platform that is starting to catch steam and move forward I decided to start putting my effort into getting some resources centralized that would allow new comers to the platform to get a quick start on moving forward with it.

I have been using the software now for about a month and a half now.  In the beginning I found very few extensions as that was just being developed as well as very few themes other then what was included in the original download. I want to provide as many themes for people to have available so for any that are out there that I do not have included please leave a link in the comments and I will make sure that I get this added to the list.  As it grows I will try to make the pages as searchable as possible and see how many we can get.

Technorati Tags: ,

del.icio.us Tags: ,

kick it on DotNetKicks.com

Posted on 1/23/2008 8:15:11 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: BlogEngine.NET | Themes

Tags: ,

BlogEngine.net blog claiming at Technorati

benlogo80After attempting many different ideas and reading many different support posts.  I did even send a support request that I never heard back from at Technorati's support site. I never heard back from them or managed to claim my blog.

This was sort of a disappointment.  We could get as far as the second step when it would as for us to choose our claim method and no claim methods were enabled.  As it turns out it is an issue with the blogging platform that hopefully shall be resolved shortly in the next release of the software.  Until then there is a solution for anyone looking to claim their blog.

Chris Blankenship made a post on his blog about claiming your blog. Claim your BlogEngine.Net Blog at Technorati described exactly what was needed to accomplish this.  I see that the issue he raises with the format of the xml document created by rsd.axd has been fixed within the latest source release up on CodePlex.

So I followed Chris's instructions and went through the simple issue of commenting out the following line in the web.config file.

<!--add verb="*" path="rsd.axd" type="BlogEngine.Core.Web.HttpHandlers.RsdHandler, BlogEngine.Core" validate="false"/-->

I then went back to claim my blog and received the claim code to be placed within a post and proceeded to follow the rest of the procedure.  I also had to turn full posts back on within the home page of this blog so that Technorati could read the posts properly.  Once the claim was done then I removed the post as well as turned the home page back to just the short display.

Hope this manages to help anyone using BlogEngine.Net.  I'm very happy with this as a blog engine so far.  I like the simplicity and have been working on writing a few different things I plan on doing a little more writing of a couple of extensions if they don't get written by someone else.

Any questions please feel free to leave them in the comments and I will try to get back to you as quickly as possible.

del.icio.us Tags: ,

Technorati Tags: ,

kick it on DotNetKicks.com

Posted on 1/23/2008 6:52:37 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: BlogEngine.NET | LearnMSNET | Programming

Tags: ,

IE Spell and Internet Explorer 7

While working on updating some pages on this site and using the built in HTML editor, I ran across an issue which I don't think can be taken care of within the framework of BlogEngine.net but is worth noting to remember for later use.  I decided to run the spell checker as I have IE Spell installed.  I had previously saved my page within  the editor then had went in and written some text about a paragraph.  It was neither a long post to the page or anything else but it was the beginning. 

I then decided I would do a spell check just to see how the integration worked with the browser.  I normally do all my editing in Windows Live Writer for all my posting to the blog.  But as I was working on a page to post about DotNetNuke I figured I would try the page editor.  When I pressed the Spell Checker button iespell  I then received the bar at the top of Internet Explorer asking me if I wanted to allow the ActiveX control to run. I gave the control permission to execute which then did a refresh of my page. And lo and behold the text that I hadn't saved to the page on the site was gone.

So for future reference I guess I should save the document to the server before I run Spell Check.  It will save me a lot of retyping later on.  Hope this helps someone in the future to think about.

del.icio.us Tags: ,

Technorati Tags: ,

kick it on DotNetKicks.com

Posted on 1/20/2008 6:33:35 PM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: BlogEngine.NET | Software

Tags: ,

Lightbox Extension for BlogEngine.net

benlogo80Jesse Foster of GravityCube has released a new extension for BlogEngine.net. This extension is designed to overlay images on the current page. The emphasis for this extension is to allow continuous flowing of content without sending the user to a blank page. 

By displaying the image on top of the existing content by simply clicking the image to display and then clicking it again it eliminates the need to click the back button and distract the user from leaving your site or closing out the window expecting to be back at the page.

Jesse based his work for the extension on the following JS script which can be found at http://huddletogether.com/

This extension will definitely be used in my version of BlogEngine.net.

Technorati Tags: , , ,

del.icio.us Tags: , , ,

kick it on DotNetKicks.com

Posted on 1/16/2008 3:20:29 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: ASP.NET | BlogEngine.NET | C# | Software

Tags: , , ,

BlogEngine.net DotNetKicks Extension

benlogo80 For everyone that has started to work with Blogengine.net and wants to implement the DotNetKicks extension that would be comparable to the DiggIt extension.  There is a new extension that is available at the Flawless Code blog.

This extension places the kick it button on the post with the number of times that the article has been kicked.

The extension can be downloaded here.

Technorati Tags: ,

del.icio.us Tags: ,

Posted on 1/10/2008 6:05:20 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: BlogEngine.NET | Software

Tags: ,