| CODENOTIFIER | HelpYou are not signed inSign in |
Project: ThruDB
Revision: 356
Author: thai
Date: 20 Apr 2008 22:27:32
Diff at Trac: http://trac.thrudb.org/changeset/356
Changes:update tweetsearch/py to the latest version
Files:| ... | ...@@ -7,11 +7,9 @@ | |
| 7 | 7 | |
| 8 | 8 | def search(request): |
| 9 | 9 | query = request.GET.get('q', '').encode('utf-8') |
| 10 | offset = request.GET.get('offset', '') | |
| 10 | offset = request.GET.get('offset', 0) | |
| 11 | 11 | if offset: |
| 12 | offset = int(offset) | |
| 13 | else: | |
| 14 | offset = 0 | |
| 12 | offset = int(offset) | |
| 15 | 13 | tweets = None |
| 16 | 14 | total = None |
| 17 | 15 | next = None |
| ... | ...@@ -7,15 +7,15 @@ | |
| 7 | 7 | 3. config apache with mod_python. Here's a sample conf: |
| 8 | 8 | |
| 9 | 9 | <VirtualHost *> |
| 10 | ServerName tweetsearch.local | |
| 11 | DocumentRoot /path/to/thrudb/tutorial/tweetsearch | |
| 10 | ServerName tweetsearch.local | |
| 11 | DocumentRoot /path/to/thrudb/tutorial/tweetsearch/py | |
| 12 | 12 | <Location "/"> |
| 13 | 13 | SetHandler python-program |
| 14 | 14 | PythonHandler django.core.handlers.modpython |
| 15 | 15 | SetEnv DJANGO_SETTINGS_MODULE tweetsearch.settings |
| 16 | 16 | SetEnv PYTHON_EGG_CACHE /tmp |
| 17 | 17 | PythonDebug On |
| 18 | PythonPath "['/path/to/thrudb/tutorial'] + sys.path" | |
| 18 | PythonPath "['/path/to/thrudb/tutorial/py'] + sys.path" | |
| 19 | 19 | </Location> |
| 20 | 20 | |
| 21 | 21 | </VirtualHost> |
| ... | ...@@ -12,13 +12,13 @@ | |
| 12 | 12 | from random import random |
| 13 | 13 | from time import time |
| 14 | 14 | |
| 15 | import urllib2 | |
| 16 | import cjson | |
| 17 | import sys | |
| 18 | 15 | import socket |
| 19 | 16 | # timeout in seconds |
| 20 | 17 | TIMEOUT = 10 |
| 21 | 18 | socket.setdefaulttimeout(TIMEOUT) |
| 19 | import urllib2 | |
| 20 | import cjson | |
| 21 | import sys | |
| 22 | 22 | |
| 23 | 23 | # Config Constants |
| 24 | 24 | THRUDEX_PORT = 11299; |
| ... | ...@@ -80,19 +80,20 @@ | |
| 80 | 80 | response = urllib2.urlopen(url) |
| 81 | 81 | json = response.read() |
| 82 | 82 | tweets = cjson.decode(json) |
| 83 | except: | |
| 83 | except Exception, e: | |
| 84 | print e | |
| 84 | 85 | continue |
| 85 | 86 | for tweet in tweets: |
| 86 | 87 | # somehow sometimes tweet is not a dictionary, check to make sure |
| 87 | 88 | if isinstance(tweet, dict): |
| 89 | # if sth serious wrong happened in thrudb, better to log it and continue | |
| 88 | 90 | try: |
| 89 | 91 | self.index_tweet(tweet) |
| 90 | 92 | self.save_tweet(tweet) |
| 91 | 93 | self.count = self.count + 1 |
| 92 | 94 | self.since_id = tweet["id"] |
| 93 | except: | |
| 94 | # sth serious wrong happened in thrudb, better to raise the error and continue | |
| 95 | raise | |
| 95 | except Exception, e: | |
| 96 | print e | |
| 96 | 97 | continue |
| 97 | 98 | print "loaded %s tweets, last since_id %s" % (self.count, self.since_id) |
| 98 | 99 | |
| ... | ...@@ -120,7 +121,7 @@ | |
| 120 | 121 | def search_tweet(self, terms, offset=0, limit=10): |
| 121 | 122 | q = ThrudexTypes.SearchQuery() |
| 122 | 123 | q.index = THRUDEX_INDEX |
| 123 | q.query = "+text:(%s)" % terms | |
| 124 | q.query = '+text:(%s)' % terms | |
| 124 | 125 | q.offset = offset |
| 125 | 126 | q.limit = limit |
| 126 | 127 | q.sortby = 'date' |
| ... | ...@@ -21,7 +21,7 @@ | |
| 21 | 21 | <br/> |
| 22 | 22 | |
| 23 | 23 | {% if query %} |
| 24 | {{ total }} results for: <b>"{{ query|escape }}"</b> showing ({{ current }} - {{ next }}) | |
| 24 | {{ total }} results for: <b>{{ query|escape }}</b> showing ({{ current }} - {{ next }}) | |
| 25 | 25 | <br/> |
| 26 | 26 | |
| 27 | 27 | <div style="float:right"> |