| 1 | Django Google Search |
|---|
| 2 | -------------------- |
|---|
| 3 | |
|---|
| 4 | Django Google Search is a simple wrapper around Google Site |
|---|
| 5 | Search. You can use it to add a custom, Google-powered search engine |
|---|
| 6 | to your Web site by using Google Site Search XML service. |
|---|
| 7 | |
|---|
| 8 | Even though this application is free, a key for Google Site Search is |
|---|
| 9 | needed to make it work. |
|---|
| 10 | |
|---|
| 11 | http://www.google.com/sitesearch/ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | REQUIREMENTS |
|---|
| 15 | ------------ |
|---|
| 16 | |
|---|
| 17 | Django Google Search requires at least Django 0.96 running on Python |
|---|
| 18 | 2.3+. |
|---|
| 19 | |
|---|
| 20 | The ElementTree library for XML parsing is also required for Python |
|---|
| 21 | 2.3 and 2.4, whereas Python 2.5+ have ElementTree built-in and Django |
|---|
| 22 | Google Search knows how to find it. |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | INSTALL |
|---|
| 26 | ------- |
|---|
| 27 | |
|---|
| 28 | Put the googlesearch directory anywhere in your PYTHONPATH and add |
|---|
| 29 | "googlesearch" to your Django INSTALLED_APPS. |
|---|
| 30 | |
|---|
| 31 | You’ll need to add a key to your per-project settings file with this |
|---|
| 32 | entry: |
|---|
| 33 | |
|---|
| 34 | G_BUSINESS_KEY = '<your Google business key here>' |
|---|
| 35 | |
|---|
| 36 | You’ll also need to wire the app in your global urls.py: |
|---|
| 37 | |
|---|
| 38 | (r'^search/$', 'googlesearch.views.search'), |
|---|
| 39 | |
|---|
| 40 | Assuming you have a base.html master template this is all you need to |
|---|
| 41 | do for now. If not, create one with a basic HTML page skeleton, a |
|---|
| 42 | block called “title”, and another called “content” in the spots you |
|---|
| 43 | find best and Django Google Search will pick it up. |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | CONFIGURATION |
|---|
| 47 | ------------- |
|---|
| 48 | |
|---|
| 49 | There are other parameters you can configure: |
|---|
| 50 | |
|---|
| 51 | - G_LANGUAGE_CODE, which specifies how Google replies to your queries |
|---|
| 52 | |
|---|
| 53 | - G_NUM_RESULTS, how many results you want on each page |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | TEMPLATES |
|---|
| 57 | --------- |
|---|
| 58 | |
|---|
| 59 | - goooglesearch/search.html |
|---|
| 60 | |
|---|
| 61 | As stated above, by default Django Google Search has a few custom |
|---|
| 62 | templates. The main one is googlesearch/search.html, the other two |
|---|
| 63 | extend this. |
|---|
| 64 | |
|---|
| 65 | You may override googlesearch/search.html with your own, just remember |
|---|
| 66 | to create a block called “results” for the other two templates to |
|---|
| 67 | write into. |
|---|
| 68 | |
|---|
| 69 | - googlesearch/no_results.html |
|---|
| 70 | |
|---|
| 71 | Default template for “no results” scenario. |
|---|
| 72 | |
|---|
| 73 | - googlesearch/not_available.html |
|---|
| 74 | |
|---|
| 75 | Default template displayed when the Google XML service is down. |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | VIEWS |
|---|
| 79 | ----- |
|---|
| 80 | |
|---|
| 81 | - googlesearch.views.search |
|---|
| 82 | |
|---|
| 83 | Django Google Search has a single view, “search”, that receives the |
|---|
| 84 | GET parameter “q”, calls Google XML service, parses the XML response |
|---|
| 85 | and finally renders it via the googlesearch/search.html template. |
|---|
| 86 | |
|---|
| 87 | This view also accepts the “page” parameter, for pagination. It |
|---|
| 88 | doesn’t use the default Django pagination system because Google’s |
|---|
| 89 | pagination results are unpredictable. |
|---|
| 90 | |
|---|
| 91 | The “search” view instantiates a RequestContext by default, so you |
|---|
| 92 | have access to all the request objects from the template, including |
|---|
| 93 | “request.user”. |
|---|
| 94 | |
|---|
| 95 | It takes three parameters, all optional: |
|---|
| 96 | |
|---|
| 97 | - G_BUSINESS_KEY (str), defaults to the business key specified in the |
|---|
| 98 | settings, but can be overridden in case you want to work with |
|---|
| 99 | multiple keys for any reason. |
|---|
| 100 | |
|---|
| 101 | - extra_context (dict), stuff you may want to pass as extra variables |
|---|
| 102 | in the template context |
|---|
| 103 | |
|---|
| 104 | - extra_query_params (dict), extra query parameters you may want to |
|---|
| 105 | pass to Google, like a custom site:http://example.org/ filter to |
|---|
| 106 | provide sub-site search support |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | ACKNOWLEDGEMENTS |
|---|
| 110 | ---------------- |
|---|
| 111 | |
|---|
| 112 | For all the bugs in the current version of Django Google Search blame |
|---|
| 113 | its original writer, Antonio Cavedoni <http://cavedoni.com/> |
|---|
| 114 | |
|---|
| 115 | Other people that have helped with suggestions and fixes: |
|---|
| 116 | |
|---|
| 117 | - Marco Beri <http://beri.it/> |
|---|
| 118 | - Your Name Here |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | $Id$ |
|---|