From f0b64affbd5133b451b528b18c1928b7ef8346b2 Mon Sep 17 00:00:00 2001 From: K Rahul Reddy Date: Wed, 1 Jul 2020 23:17:07 +0530 Subject: [PATCH 01/15] Added suggestions part --- dist/assets/js/suggest.js | 119 ++++++++++++++++++++++++++++++++++++++ dist/search.html | 5 ++ 2 files changed, 124 insertions(+) create mode 100644 dist/assets/js/suggest.js diff --git a/dist/assets/js/suggest.js b/dist/assets/js/suggest.js new file mode 100644 index 00000000..9a9a50a8 --- /dev/null +++ b/dist/assets/js/suggest.js @@ -0,0 +1,119 @@ + +function suggester() { + var query = document.getElementById("q").value; + // console.log(window.location.href + "?q=" + query + "&polygon_geojson=1"); + // $.ajax({ + // type: "POST", + // url: "../lib/es.py", + // data: { param: query }, + // success: callbackFunc, + // error: callbackFunc + // }); + + var xmlhttp = new XMLHttpRequest(); + var url = "http://localhost:8000/pref/?q=" + query; + console.log(url); + + xmlhttp.onreadystatechange = function () { + // if(!(this.responseText === "")) + // { + // console.log(this.status, this.responseText); + // } + if (this.readyState == 4 && this.status == 200) { + var myArr = JSON.parse(this.responseText); + // var hits = myArr['features']; + var hits = myArr['hits'].hits; + // console.log(hits, hits.length); + var options = ''; + for (var i = 0; i < hits.length; i++) { + res = ''; + // console.log(hits[i]['properties'].length); + // for(var j in hits[i]['properties']) + // { + // res += hits[i]['properties'][j]; + // if(j != 0 && hits[i]['properties'][j] !== '') + // res += ", "; + // } + + // console.log(i, hits[i]._source.name); + res = hits[i]._source.name; + // if(hits[i]._source.hasOwnProperty('name')) + // if(hits[i]._source.hasOwnProperty('city')) + // res += ", " + hits[i]._source.city['default']; + // if(hits[i]._source.hasOwnProperty('country')) + // res += ", " + hits[i]._source['country']['default']; + // if(hits[i]._source.hasOwnProperty('osm_value')) + // res += " (" + hits[i]._source['osm_value'] + ")"; + // if(res === '') + // res = query; + res = hits[i]._source.address; + res = res.replace(/\"/g, "'") + // console.log(res); + // Using photon API + // if(hits[i]['properties'].hasOwnProperty('name')) + // res += hits[i]['properties']['name']; + // if(hits[i]['properties'].hasOwnProperty('city')) + // res += ", " + hits[i]['properties']['city']; + // if(hits[i]['properties'].hasOwnProperty('country')) + // res += ", " + hits[i]['properties']['country']; + // if(hits[i]['properties'].hasOwnProperty('osm_value')) + // res += " (" + hits[i]['properties']['osm_value'] + ")"; + // if(res === '') + // res = query; + options += '