Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Google Suggest in your own web application (e.g. using Python)

In my website, users have the possibility to store links.

During typing the internet address into the designated field I would like to display a suggest/autocomplete box similar to Google Suggest or the Chrome Omnibar.

Example:

User is typing as URL:

http://www.sta

Suggestions which would be displayed:

http://www.staples.com
http://www.starbucks.com
http://www.stackoverflow.com

How can I achieve this while not reinventing the wheel? :)

like image 308
Federico Elles Avatar asked Nov 01 '08 15:11

Federico Elles


People also ask

How do you make a search engine like Google in Python?

Create a file urls.py in the engine folder. Append the following lines. Our project is now done , to fire it up type python3 manage.py runserver enter this url in your browser and you should see this. Now enter your query in the search bar and your should get your results like this.


2 Answers

You could try with http://google.com/complete/search?output=toolbar&q=keyword

and then parse the xml result.

like image 134
Pesto D Avatar answered Oct 06 '22 10:10

Pesto D


I did this once before in a Django server. There's two parts - client-side and server-side.

Client side you will have to send out XmlHttpRequests to the server as the user is typing, and then when the information comes back, display it. This part will require a decent amount of javascript, including some tricky parts like callbacks and keypress handlers.

Server side you will have to handle the XmlHttpRequests which will be something that contains what the user has typed so far. Like a url of

www.yoursite.com/suggest?typed=www.sta

and then respond with the suggestions encoded in some way. (I'd recommend JSON-encoding the suggestions.) You also have to actually get the suggestions from your database, this could be just a simple SQL call or something else depending on your framework.

But the server-side part is pretty simple. The client-side part is trickier, I think. I found this article helpful

He's writing things in php, but the client side work is pretty much the same. In particular you might find his CSS helpful.

like image 31
lacker Avatar answered Oct 06 '22 10:10

lacker