Archive for June, 2009

sphinx, ColdFusion and geodist

30 June 2009 23:16

Over the past few days I’ve been looking into a new search engine for an application. The chosen search daemon is sphinx and it’ll be called via the Java API (that comes with sphinx) from ColdFusion. Getting the basic searching going was pretty easy, creating an index, do a basic search, set some filters, done. The next step was to look into geodist matching, calcuating how far apart two latitude / longitude’s are, slightly more tricky. In CF you can do it with some crazy curvature of the earth calculations but in sphinx it’s real easy – when you know what it wants. The key there is radians.

You’ll find plenty of tidbits on the web about this but no real end to end examples so hopefully this will help!

If you need to geocode some postcode or zip values I can highly recommend tinygeocoder.com. It’s basic and gives you a straight lat / long value which is perfect. If you want something with a bit more information you’ll need to check out the Yahoo! YDN geocode API or Google’s HTTP API. I’ve got the YDN working with ColdFusion (I’ll post about that later).

First up you’ll need some data, I’ve created a basic DB table called sphinx_test.sql which you can download. It’s been written for MySQL. Quick note on the float values, if you don’t specific float 10,6 (or something similar) your lat/longs will automatically be chopped to only 4 decimal places.

The SQL contains 3 locations in England. The British Airways London Eye (51.502893,-0.118811), Millennium Dome (51.501984,0.004764) and Windsor Castle (51.481971,-0.600686).

Once you’ve created your table you’re ready to create an index. I’m going to assume you’ve already installed sphinx in /opt/sphinx (this is on a CentOS platform). To get the Java API part for ColdFusion is easy as well.

[root@hosting ~]# cd /root/sphinx-0.9.9-rc2/api/java
[root@hosting ~]# make
[root@hosting ~]# cp sphinxapi.jar /opt/coldfusion8/runtime/servers/lib
[root@hosting ~]# /opt/coldfusion8/bin/coldfusion restart

This is the sphinx.conf you’ll need to get this running. Now there’s a whole load of stuff you could do in the configure file but I’ll just give you a basic one which should be enough.

Note you have two options when it comes to getting the lat/long from MySQL, you can either use RADIANS(val) or use a pre-stored the radian value of the lat / long In this case we’re going to use the latter but I’ve included a commented line for the former.

Now for the actual code that does the work. I’ve created a file called sphinx.cfm (view as text or click it to actually see it working) with comments inline. The interesting parts are:

<!--- sort order must be @geodist to allow distance matching --->
<cfset variables.sphinx.SetSortMode(variables.sphinx.SPH_SORT_EXTENDED, '@geodist desc')>

<!--- where are we starting, this will be the london eye latlong converted to radians --->
<cfset variables.sphinx.SetGeoAnchor('latitude', 'longitude', degreesToRadians(51.502893), degreesToRadians(-0.118811))>

All of the API calls are the same as the documented PHP functions so you can refer to the documentation for more information.

Thanks go out to various bloggers and Tim to get this running.

Filed: Technology // Tagged: , , , , // No Comments

Moving on up

22 June 2009 22:29

The continued, and if by continued I mean actually starting, migration of my sites over the Rackspace Cloud is moving forward again at last. I’ve nearly finished setting up the initial Cloud Servers and all the DNS. The 4th server setup this evening however shows more signs of the move from Mosso to Rackspace Cloud, the inital RDNS entry for the previous 3 had been slicehost.com addresses but this time out it’s 000-000-000-000.static.cloud-ips.com. A quick lookup shows that the domain still lives on slicehost nameservers and has a Rackspace contact but I guess it’s movement.

Some changes are present in the control panel but not a lot, maybe they’ll be more or maybe it is just a logo update.

Update:

So after some playing I’m not going anywhere. The cloud servers are great, real easy to get running but for what I’m doing and have hosted, mess around with etc a dedicated box is ideal. Currently with The Planet and have a good deal, a UK server would be nice but the cost just doesn’t make it viable right now. I might look at either a bigger TP box, more RAM or go to iWeb or ServerBeach but not sure – any recommendations or reviews of those?

Filed: Technology // No Comments

Railo, Resin, Caucho and me

12 June 2009 23:06

I’ve finally got resin, railo and caucho playing together in a nice, no longer ripping each other’s hair, out kind of way. I have to say my biggest comment (and probably one of the more tricky things to do) is that for Railo to become a big player in trying to take away Adobe’s CF user base installers are going to be essential. That said railo does seem quicker on processing CFML (need to do more tests to verify that).

I’ve got apache 2.2.3 running on CentOS 5.3. I have railo 3.1.0.015 (not updated to 016 yet) and caucho.

My resin.conf has this addition (multiple times for the different domains):

<host id="www.domain.co.uk" root-directory="/home/domain/public_html">
<host-name>www.domain.co.uk</host-name>
<host-alias>domain.co.uk</host-alias>
<web-app id="/" document-directory="."/>
</host>

The apache virtual hosts are just normal vhosts. No extras.

My caucho.conf (in /etc/httpd/conf.d) looks like this:

LoadModule caucho_module /usr/lib64/httpd/modules/mod_caucho.so
ResinConfigServer localhost 6800
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
<Location /caucho-status>
SetHandler caucho-status
</Location>

Hopefully that might help someone out. I’m going to try and do a from scratch CentOS build guide for The Rackspace Cloud sometime next week. I’ve started migrating some sites over to the cloud server and so far not hit any issues.

Filed: Technology // Tagged: , , , , // 1 Comment

Rackspace Cloud (Mosso) DNS

12 June 2009 22:59

Some people aren’t aware that for Rackspace Cloud Servers they also offer DNS which is pretty handy. The setup however is a little odd and the interface different to any other DNS/zone editor I’ve used. There’s a number of KB entries under The Rackspace Cloud control panel as well.

A quick guide on how to enter the details to get it to work. If you login, access your server and click DNS you’ll first need to add the domain name, in these examples domain.com. Once done click on the domain and then you can add away. You can’t edit, well if you call delete and add editing then yes you can.

So, for an A record:

Name: domain.com
Content: 1.2.3.4
Priority: 10
TTL: 300
Type: A

And a CNAME record:

Name: cname.domain.com
Content: another.domain.co.uk
Priority: 10
TTL: 300
Type: CNAME

For sub-domains you have to put the full domain in rather than just the sub-domain so:

Name: sub.domain.com
Content: 1.2.3.4 (or a CNAME)
Priority: 10
TTL: 300
Type: A

For MX records they say just use your IP as the content:

Name: domain.com
Content: 1.2.3.4
Priority: 10 (increment for additional MX entries)
TTL: 300
Type: MX

I think however you can also do this:

Name: domain.com
Content: 10 mail.domain.com (assuming you have a standard A record setup with IP called mail)
Priority: 10
TTL: 300
Type: MX

That’s it.

Filed: Technology // Tagged: , , , // No Comments

Moving into the clouds

10 June 2009 21:46

I’ve decided to take a leap and try moving all the sites I host into the cloud. Currently I’ve got a dedicated server but it doesn’t really do a lot most of the time and the pay for usage idea appeals. I’ve got a cloud server over at Mosso (soon to be The Rackspace Cloud) running CentOS 5.3 and I’m also in the process of getting Railo server / Resin running to handle the CFML stuff. So far it’s going OK.

Few things that I needed to get resin to compile, like gcc, glibc-devel, openssl-devel, openssl but aside from that pretty easy. I’ll try and write up a step by step guide when it’s working.

Filed: Technology // Tagged: , , , // No Comments

iPhone 3GS and o2

10 June 2009 10:49

With the announcement of the new iPhone 3GS the predictable rage at upgrades is now the issue. It’s not unexpected as the handsets aren’t subsidised however still annoying to those people who want the latest and greatest.

o2 have now published their upgrade policy on how you can get a 3GS. Basically, buy a pay as you go phone, pay up your remaining monthly contract and sign a new one or dependent on how much you pay monthly take advantage of the early upgrade windows.

I’ll certainly put 3.0 on my phone but if it’s worth upgrading as much as I’d like to I’m not sure. In my case with 9 months left I think the pay out contract option would be cheapest – still very expensive though. Of course there’s always eBay…

Filed: General // Tagged: , , // No Comments

Useful sed command

8 June 2009 15:29

Posting this more as a reminder to myself than anything else, but, if you need to replace all instances of the word old in a file with the word new this command is really handy!

sed -i 's/old/new/g' file.txt

Filed: Technology // Tagged: , , , // No Comments

 
Twitter   •   About   •   Contact
©2010 Ian Winter. All Rights Reserved.   •   Powered by WordPress   •   Hosted at Memset