Basically I have a hotel search engine and on top of the site there is a search field which must show autocomplete results. Results can be Hotels or Locations (cities). Comparable to Facebook autocomplete (searching can be persons, pages,...)
I started from the basic geonames jsuery example: http://jqueryui.com/autocomplete/#remote-jsonp
But I cannot figure out how to use my own JSON api for the hotels. I know I should merge my JSON hotels with the ones from geonames? Anyone who can show me a snippet of how to this?
Simplest high level code should look like this, where requestFromSource1 is where you request geonames, requestFromSource2 is where you query your own autocomplete engine.
$( "#city" ).autocomplete({
source: function( request, response ) {
var resultFromSource1 = null;
var resultFromSource2 = null;
var agregateResults = function(){
if( resultFromSource1 && resultFromSource2){
var result = resultFromSource1.concat(resultFromSource2);
response(result);
}
}
requestFromSource1(function( result ){
resultFromSource1 = result;
agregateResults();
});
requestFromSource2(function( result ){
resultFromSource2 = result;
agregateResults();
});
}
});
});
The more complex case is merging by relevance score. I'm afraid that this note possible in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With