Monday, March 28, 2011

Partly Cloudy - Node.js and the IFS

With Node.js surfing the hype wave, we have received some requests from our clients on how to use Node.js to poll the IFS web services.

This is actually a good idea ... let me add another buzz word to explain why: SEO.

In the following scenario we'll make Node.js call the casa.keru search service from the Tredix IFS and serve the results as HTML to the browser. The result will be a static web page listing some properties for sale.

It is very important to understand the difference between a static and a dynamic web page. In most of our other examples (including the casa.keru.pt web application itself), we are calling the IFS web services from within the browser. This technology is commonly known as AJAX; the DOM is manipulated on the fly. AJAX is really cool and fun to use, because all the magic happens dynamically within your page without any page reloads. However, in SEO terms, AJAX is not helpful at all. When the Google bot stops by, it can only index the static content of our page (which is usually not much more than a HTML wrapper) - but not the dynamically generated content. However, this is where the beef is.

So the good old fashioned static web page can still be desirable, especially in terms of SEO. With Node.js, there's no need to write a server side program in yet another language such as PHP, Python, Ruby or ASP.NET/C#. Instead, JavaScript developers can use their client-side JavaScript skills to let rip on the server.

Plus: It's incredibly simple! Check out the basic example below which sets up a web server on 127.0.0.1:8124, calls the IFS search service, and delivers a static list of properties to the browser. Each time you hit refresh, you'll skip to the next page of property listings. The code is pretty self-explanatory and should allow for an instant start - enjoy!

// tested on Node.js 0.4.x

var http=require('http');

var GroupID='PT-08_ABF_01'; // Freguesia Albufeira
var counter=0, html="";

http.createServer(function (req, nodeResponse) {

  // Ignore browser requests for Favicon
  // console.log(req.url);
  if (req.url=="/favicon.ico") return false;

  counter++;
  var options = {
    host: 'arrakis.tredix.com',
    method: 'GET',
    port: 59180,
    path: '/apache-tomcat/Tredix/ISS?Context=Tredix/IFS/ImmoPT/ProtoTyp2/Search&ContentType=json'+
    '&BusinessType=SALE' +
    // '&PropertyType=' +
    '&MinPrice=0' +
    '&MaxPrice=0' +
    '&NumberOfBedrooms=' +
    '&Language=PT' +
    '&IncludeObjectsWithPriceOnApplication=true' +
    '&IncludeBoundaries=false' +
    '&IncludeMisses=false' +
    '&Currency=EUR' +
    // '&Tags=' +
    '&ListNumberOfPage=' + counter +
    '&ListItemsPerPage=5' +
    '&GroupID='+GroupID +
    '&SortBy=PriceASC' +
    '&ResponseDetails=List',
    headers: {
      "User-Agent": "Tredix CaKe Client"
    }
  };

  var ifsRequest = http.request(options, function(ifsResponse) {

    var responseBody = "";
    ifsResponse.setEncoding("utf8");

    // echo some IFS response details
    console.log('STATUS: ' + ifsResponse.statusCode);
    console.log('HEADERS: ' + JSON.stringify(ifsResponse.headers));
    console.log('counter: ' + counter);
    console.log('################');

    ifsResponse.on("data", function(chunk) {
      responseBody += chunk;
    });

    ifsResponse.on("end", function() {
      // build static HTML for the client
      html="<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>";
      html+="<html><head><title>"+GroupID+"</title></head><body><table>";
      var hits = JSON.parse(responseBody),
      results = hits.SearchResult.ListHits,
      length = results.length;
      for (var i = 0; i <= (length-1); i++) {
        html+="<tr><td><b>"+results[i].Title + "</b></td><td><b>"+ results[i].Price+"</b></td></tr>";
        html+="<tr><td colspan='2'>"+results[i].Description + "</td></tr>";
      }
      html+="</table></body></html>";

      nodeResponse.writeHead(200, {
        'Content-Type': 'text/html; charset=UTF-8'
      });
      nodeResponse.end(html);

    });
  });

  ifsRequest.end();

}).listen(8124, "127.0.0.1");

console.log('Node server running at http://127.0.0.1:8124/');

Friday, March 11, 2011

What's that bird?

We proudly present Keru's new testemonial: a Peregrine Falcon!

Since our maps based sites use the bird's eye view for primary navigation, the choice of a bird was rather obvious. But why didn't we go for a funny parrot, a peaceful dove, a Portuguese stork, or some odd duck?

The Peregrine is renowned for its speed, reaching speeds of up to 290 to 390 km/h (180 to 240 mph), making it the fastest extant member of the animal kingdom. With a vision five times more powerful the human eye's, falcons spot their targets quicker than most other birds.

We liked these analogies to the speed of casa.keru and a growing number of other maps-based applications. Under the hood, instantaneous search, clustering and navigation are provided by the Tredix IFS.

Thanks again to our designer friend Rabea of La Bam for providing both a great concept and perfect realisation of Keru's new CI. Well done, right on time for the upcoming IMOBITUR real estate trade show in Porto.

PS: Our agency did tell us that we are not the first to use the Peregrine metaphor for speed ... ever heard of the Suzuki Hayabusa (or GSX1300R)?

Monday, March 7, 2011

casa.keru adds 50.000 properties around Porto

Just a quick note that, as of today, casa.keru is also covering the greater Metropolitan Area of Porto (Oporto). Right from the start, there are more 50.000 listings available in the district of Porto alone.

Located along the Douro river estuary in northern Portugal, Porto is one of the oldest European centres, and registered as a World Heritage Site by UNESCO in 1996. The area is very popular with travellers and home seekers alike.

In total, casa.keru is now promoting more than 100.000 properties for sale and rent in Portugal. Currently, the website is focussing on the two largest Portuguese cities - Lisbon and Porto - and the popular Algarve region. Full coverage of Continental Portugal is being scheduled for Q2/11.

Tuesday, March 1, 2011

casa.keru now covering the Lisbon Metropolitan Area

We are proud to announce the immediate availability of casa.keru in the Lisbon area.

Since it's launch less than ten weeks ago, casa.keru covered the Algarve exclusively. Meanwhile, there are more than 25.000 offers available in the district of Faro. 

As of today, casa.keru is presenting another 25.000 properties in and around the Portuguese capital. Within Portugal, the district of Lisbon has got by far the most agile real estate market. For the initial Lisbon data set, we have been working with almost a hundred real estate agents.

The doubling of the number of offers (50K+ in total) immediately reflects in casa.keru's local mirror sites (Spain, UK, Germany).

It is our declared objective to cover all areas of continental Portugal by Q2/11.