GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
How to build a "Suggest" search  XML
Forum Index -> General
Author Message
Eddie



Joined: 26/04/2006 13:04:15
Messages: 7
Offline

Hi everyone!

I plan to build an AJAX "Suggest" search (just like Google Suggest) for populated place names. In my search box a search for "b" should bring
1) countries that start with "b"
2) capitals with "b"
3) big cities with "b"
4) any other places with "b"
Problem: the user would always see only the top 10 results of his search!

Speed: How would you do the technical part? I read somewhere that one could use Sphinx to speed up the process and to use a secondary column "suggest matches", that would e.g. for "Bangkok" contain "B Ba Ban Bang ...". What do you think of that approach?

What to include: Are there any feature classes that you would spare? For example H, L, R and U seem to be of less importance considering above search?
And how would you treat the alternative names, given that there is not always a translation for a specific language (e.g. 'de') but you still need a result?

ORDER BY ...: What sort criteria would you use in order to make the result list as intuitive as possible? Probably first order by "A PCL", "A ...", "P PPLC", "P ..." and then order by population?
But I am not sure how to do this in MySQL, since the order is not alphabetical. Is there a way to tell MySQL the desired order of feature classes? Or will I need several queries?

Sorry for all these questions, but probably at the end this will help others too!
Eddie
barryhunter


[Avatar]

Joined: 13/09/2006 21:25:40
Messages: 27
Offline

Re the note on using Sphinx, it was probably my misinformation, but you dont actully need to create that column, Sphinx can do it transarently at the indexing stage.

what to include... I wondered this, in the end not sure can leave anything out, you just want them very low priority so they come last

order by ... I've done basically that in a prototype I am building, but didnt think about the population (although now think it I think geonames does that!) ... what I did was assigna sort order (manually) to each feature code, and sort on that. (can either add it as another column, or just join with a table of feature codes)

--
- www.nearby.org.uk - www.geograph.org.uk -
[WWW]
Mark



Joined: 29/02/2008 20:49:17
Messages: 1
Offline

You may have moved on to other things by now, but I wanted to provide a similar capability in my Books / Maps mashup, www.codexmap.com. I use scriptaculous for Ajaxy stuff, in particular for this I used the Autocompleter, a nifty component that provides a lookahead/suggest framework. You can read many tutorials on the web or on the Scriptaculous site for how to use it. In my case, I include the attached HTML fragment in my page, and it references a PHP script (also attached) which generates the suggest candidates by calling the Geonames web service.

Basically it just calls the geonames web service with the search string the user has typed so far, and leaves the sorting of the candidates to Geonames - it does a reasonable job of this, and you may find it hard to do a better job than the author of Geonames has already done.

My script is pre-configured to only generate 10 suggestions, but it's easy to alter that variable to include more if you have screenspace for them. The more you type, the more likely the suggest will capture what you want. Also, I included some of the features codes in the lookahead string so you might see more detail on what the suggested candidates are. I've also attached a screenshot. You can see this in action on any book page in CodexMap, for example The DaVinci Code page in the image is at: http://codexmap.com/book.php?bookid=2848

(note you will not be able to run the attached PHP directly, as I've removed some code that's not directly relevant here, and some of the globals are defined in other files).

Good luck!

Mark
 Description The HTML Fragment invoking ajax.autocompleter [Disk] Download
 Filesize 898 bytes
 Downloaded:  13258 time(s)

[Thumb - suggest.jpg]
 Description A screenshot of the lookahead in action [Disk] Download
 Filesize 561 Kbytes
 Downloaded:  13271 time(s)

 Description The lookahead/suggestion candidate generator script. [Disk] Download
 Filesize 2 Kbytes
 Downloaded:  13305 time(s)

[WWW]
vak



Joined: 12/05/2009 13:50:24
Messages: 2
Offline

Eddie wrote:

...
I plan to build an AJAX "Suggest" search (just like Google Suggest) for populated place names. In my search box a search for "b" should bring
1) countries that start with "b"
2) capitals with "b"
3) big cities with "b"
4) any other places with "b"
...
 

it is exactly what I am looking for before I try to do it on my own

Any updates on this? Is it already implemented?
(I've seen a similar stuff for country+ZIP pair, but this is not exactly what I'd need)

UPD: a-ha, there is a non-documented argument "name_startsWith" in "search" function! However it is not always delivering any matching results when the result do exist :-/
(Details in German)

 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team