Monday, April 21, 2008

PHP Search engine

One of the most common components added to applications I build is a search engine.

I have a reasonable good search script that performs AND, OR and quoted string searches and ranks the results. This is a live search on the data in a MySQL database not an indexed search. This has worked quite well for me in the past, and I’m sure it will continue to work and get better as I refine the script.

But I was looking through a bunch of search engines seeing how other people did things to try and get some pointers on a better system of ranking search results than I was currently using. And what should I stumble across; Sphider.

Sphider is a PHP search engine that indexes a site and then runs the search queries over the index. It’s a little different than what I usually do, but I thought I’d take a look at it anyway. And I was quite pleasantly surprised.

It installed really easily and was no trouble to set up. After a quick read of the online docs (which are a bit sparse in places), I was able to get it to spider the site and index the content. The search results were relevant and the ranking quite good. It supports robots.txt files, meta tags, and you can tell it not to index parts of a page, like navigation menus and such.

I ended up spending quite bit of time just playing around, indexing and re-indexing the site I was working on with different settings to see what effect the changes had.

The conclusion I came to was that this is actually quite cool. It seems to do a good job of indexing, it’s easy to use, and it gives relevant results. Unfortunately the specs of the project I’m working have since changed, making it mandatory to have a live search of the database, so I won’t be using it this time. But I will be keeping it in the wings ready and waiting for any site that needs a good search engine.

Check it out yourself and see how good it is on your projects.

Sunday, April 13, 2008

Static CSS Div at the bottom of the screen

My boss asked me to create a div at the bottom of the screen for a project I’m working on. He wanted the same functionality as having frames without using the ‘f’ word.

I was also keen not to use Javascript to do it, as this has all kinds of issues cross browser.

I had a chat to my mate Google, who knows everything. It seems this is not a trivial thing.

The different browsers support CSS differently (of course) and although getting it to work in Firefox is pretty easy, IE throws a whole toolbox worth of spanners into the mix.

After a bunch of research, and a bit of playing around I found a way to do it in Firefox and IE without using Javascript (sort of).


Here’s what I did:


Create the CSS for Firefox

#footer{


POSITION: fixed;

height: 100px;

LEFT: 0px;

border: solid 1px black;

bottom: 0px;

width: 100%;

background: #C2DFFF;

}

Then the CSS for IE

* html div#footer {

position: absolute;

top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop +(documentElement.clientHeight-this.clientHeight) : document.body.scrollTop +(document.body.clientHeight-this.clientHeight));

}

Then another Div to go at the bottom of your content.

#content-padding{/*this should be the same height as the footer to enable it to be visible once Firefox scrolls to the bottom of the page*/

bottom: 0px;

height: 100px;

clear: both;

}

This is rock solid in Firefox and a little jittery in IE, but not at all bad really. It also works better than anything I found on the web

Feel free to have a go with it and see how it turns out for you.

Sunday, April 6, 2008

Encrypting your data

Part of an application I’m building at work requires data to be encrypted and placed on removable storage. This was always going to be a bit of a challenge, stepping up to learn how to do encryption in PHP.

Fortunately for me I didn’t have to. A couple of hours research came up with some off-the-shelf options. I tried out one called Cryptainer from Cypherix, and I have to say I’m pretty impressed.

It’s a small download (I grabbed the free version for testing purposes) and it installs easily.

Setting up the container on the USB drive was no sweat and took less than a minute. I could then run my application, which runs in a browser, and copy files into the container. They were encrypted on the fly and as soon as the container was unmounted everything was nice and secure.

Getting the files back out again was just as easy.

Simply plug the USB drive in, mount the container, and then the application can access and use the files.

The learning curve is really small, which is good because this will need to work for users with minimal computer literacy.

So if you need something to secure your files and you can’t be bothered investing lots of dollars or brainpower, give Cryptainer a go.