Getting the same result twice when querying geo.places
Hi,
I am using the YUI autocomplete module to find a location when a user is typing it. So my code looks like this :
Y.one('#ilocation').plug(Y.Plugin.AutoComplete, {
resultListLocator: function (response) {
if (response.query.count > 0) {
alert(dump(response));
var p = response.query.results.place;
var places = new Array();
if (response.query.count == 1) {
p[0] = p;
var len = 1;
}
else
var len = p.length;
var woeids = new Array();
for (i = 0; i < len; ++i) {
var ctr = p[i].woeid;
alert(ctr);
if (typeof(woeids[p[i].woeid]) == 'undefined') {
woeids[p[i].woeid] = true;
var p1 = p[i]['name'];
if (typeof(p[i]['admin1']['content']) != 'undefined')
p1 += ', '+p[i]['admin1']['content'];
places[i] = p1+ ', '+p[i]['country']['content'];
}
}
alert(dump(places));
return places;
}
return false;
},
resultHighlighter: 'phraseMatch',
source: 'select * from geo.places where text = "{query}*" or text = "{query}"'
});
This is the query : select * from geo.places where text = "{query}*" or text = "{query}"'
I have to put two where clauses to the query, otherwise it doesn't find any result for a perfect match. For example, if I enter "Lev", the result includes "Levis, Quebec, Canada", but does not if I enter "Levis".
The problem is that when a match is perfect, like if I enter "Levis", the same location (with the same woeid 862) is inclued twice in the results object.
If I only look for a perfect match, with text="{query}", it doesn't find anything when entering "Levis, Quebec, Canada".
I tried a workaround to remove double results in the function associated to resultListLocator (for the autocomplete). The thing is that I get a strange error if the number of elements returned in my array "places" is different from the query's number of results (the error I get is "D is undefined" from a line in a YUI file).
I hope I have made my situation clear and not too complicated.
Thanks !
by
0 Replies