Magento Search: Getting Better Results In Product Searches

Magento is a whopping big platform – even the community edition is something of a beast. That gives it a nasty learning curve, and while, in most cases, it simply works, there are some places where it tries to be clever, with mixed results.

The product search is a case in point. A friend was recently trying to get it to cooperate, but the way the results were being returned made it quite unusable. By default, the search uses an OR comparison to find what you’re after, so if you look for “web development books”, it will give you any product whose description contains “web”, “development”, or “books”. Since the order or relation of the words is not considered, you might end up with Twilight as a top result, which I’m sure you’ll agree, is not conductive to your users not gutting you with a rusty fork.

The easiest way I found to fix this, is to change the search query, defined by the fulltext.php file (/app/code/core/Mage/CatalogSearch/Model/Mysql4/fulltext.php). Continue reading “Magento Search: Getting Better Results In Product Searches”

Visualizing data with Google Maps

map-screenshot A few weeks ago, a club I’m a member of was updating its membership information. Since the data was being collected in a Google spread sheet, I thought it would be interesting to create a map visualization to show where the members come from. In this post, we’ll write a map overlay which will generate a display like the one in the following image using data drawn from a Google spread sheet. Basically, we’re going to give a map a nasty rash.

You can also see the map here, or download the files here. Note that the size of each location has been fudged and bears no relation to the values originally collected in the membership survey.

Continue reading “Visualizing data with Google Maps”

Because we can

A few days ago, my next desk neighbour, Joe, put together a neat little Chrome extension which adds keyboard shortcuts for use in NeoGAF. It looked like fun, so I wanted to make one too, and, over the course of a smoking break, decided that it should tell me how many days are left until next St. Patrick’s day. Because hey, beer.

so_far

Version 0.1 of the plugin can be installed from its own page in the Chrome extensions repository. Enjoy!
The icons used in the plugin are from the Windows Beer Set from iconka.com.

Build even less (or incredibly more) useful stuff. Check out The Little Book of JavaScript!

RESTful Web Applications with Jersey and Spring

A couple of months ago, we were tasked with creating an API to expose some functions in our system to third party developers. We chose to expose these functions as a series of REST web services. I got to play with Jersey, the reference implementation of JSR 311 (Java API for Restful Services); this turned out to be a nice surprise, as it proved to be extremely powerful and elegant. In this post, we’ll create a very simple REST web service using Jersey.

Continue reading “RESTful Web Applications with Jersey and Spring”

Message formatting in Java

Whatever kind application you’re working on, you will probably need to create some sort of message more complex than “Hello World!” at some point. Whether it’s a log message, or some text to plonk into your nice UI, you will probably also need to format it in some way to include some variable values, and maybe some embellishments like using the correct words for plural and singular values.

Java provides a number of ways to do this. In this post, we’ll look at a few of them.

Continue reading “Message formatting in Java”

Scheduling tasks with Quartz

It’s been some time since I started off in the world of software development, but I have found myself looking for a good way to schedule tasks more than once, and I’m sure you have too. You know the sort. Run this report every third Friday of the month, clean out this table at the end of every day, sacrifice a goat every summer and winter solstice, and so on.

Some tasks can happily run in Cron, provided that your operating system has Cron. However, some tasks require a bit more flexibility than this old workhorse can provide. You may need to run the task in the context of your application, for instance, or your requirements might dictate that the scheduling of certain tasks must be controlled by the users. In the case of a Java application, you might not want to start and stop the JVM every time a small task needs to execute.

Enter Quartz, OpenSymphony’s enterprise job scheduler. This API allows you to schedule tasks within your own application, which means that you’re more or less free to control the scheduling your way. In this post, we’ll look at some of the most basic tools which this API brings to the table.

Continue reading “Scheduling tasks with Quartz”

Revisiting the JavaScript Calendar Control – Part 3

Be the JavaScript. Check out The Little Book of JavaScript!

It’s been some time since I started writing this three part series, and it certainly took a while longer to get done than I expected. A busy work schedule does tend to do that, but if it makes anyone feel better, having left the third part hanging did give my conscience a field trip. So let’s do a quick recap and get on with it 🙂

  • In part 1, we created a jQuery plugin which displays a simple static calendar.
  • In part 2, we added the facility to pick a date, and to switch the month on display.
  • In part 3 (this post), we will add some sanity checks, and the ability to display events on given days.

Continue reading “Revisiting the JavaScript Calendar Control – Part 3”

Object Caching in Java with EHCache

In a project I was working on recently, we were building up a web page by loading up its template, content hierarchy and other information dynamically. This is a common setup, and a very flexible one since it allows sweeping changes to be made very easily. Unfortunately, this flexibility comes with a cost; pulling everything through EJB calls can give you a speed not unlike that of a slightly stunned tortoise trying to sprint up a treacle covered hill.

One way of mitigating this problem is to use a Facade pattern to load as much as possible with as few calls as possible. However, this is not always the best approach, especially if most of the content is not likely to change very often. In these cases, it’s preferable to store the content at the end where it’s being used, avoiding the remote call completely.

This can be implemented quickly and easily with a Map, but that would leave us with a lot of work to do when it comes to managing the cached content. For example, what if we wanted to make sure that the cache does not continue to fill up indefinitely, or that it gets backed to disk when it goes idle for some time to preserve memory?

Since we were already using Hibernate in the data layer, we were already using a cache at that level in the form of EHCache. It made sense to try and see if it was possible to use this in our controller layer, and it turned out to be extremely elegant to use. Continue reading “Object Caching in Java with EHCache”

Revisiting the JavaScript Calendar Control – Part 2

Show your scripts who’s the boss! Check out The Little Book of JavaScript!

Following last week’s implementation of the basic shape of the calendar, this week we will add behaviours so that we can pick a date on it.

This post is part of a series of three posts:

Revisiting the JavaScript Calendar Control – Part 1

Tame the scripting beast. Check out The Little Book of JavaScript!

A few years ago, I wrote a calendar control for a Code Project article. Although I’ve used it myself several times, and despite the fact that people still appear to be using it, I can’t help but cringe every time I look at it again. Every time, the thought that comes to mind is “It could have been so much cleaner in jQuery…”.

Well, the time has come to bite the bullet and see how it can be pulled off again. Rather than going over the whole thing in one go though, we’re going to take it in steps over a number of posts to implement a feature or a group of features, so we can look each in slightly more detail. This is as much for my benefit as everyone else’s. If anyone spots anything weird, inefficient, or badong in these posts, please let me know. I like to think of this as public code review, so, you know. Bring it on.

We can rebuild him – we have the technology

The posts will be divided as follows:

  • In part 1 (this post), we will deal with the display of a simple static calendar.
  • In part 2, we will add the facility to pick a date, and to switch the month on display.
  • In part 3, we will add some sanity checks, and the ability to display events on given days.

And with that, on to the post itself. Continue reading “Revisiting the JavaScript Calendar Control – Part 1”