Changeset 163:a1304a86b5d2
- Timestamp:
- 08/23/07 13:25:06 (15 months ago)
- Author:
- Tarek Ziad?? <tarek@…>
- Message:
-
merged
- Location:
- xap
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r145
|
r163
|
|
| 143 | 143 | [] |
| 144 | 144 | |
| | 145 | statistics |
| | 146 | ========== |
| | 147 | |
| | 148 | We can also do a bit of statistics:: |
| | 149 | |
| | 150 | |
| | 151 | |
-
|
r150
|
r163
|
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | | index_data = Table('index_data', metadata, |
| | 9 | index_data = Table('xap_index_data', metadata, |
| 10 | 10 | Column('docid', String(10)), |
| 11 | 11 | Column('data', TEXT())) |
| … |
… |
|
| 17 | 17 | pass |
| 18 | 18 | |
| 19 | | remove_data = Table('remove_data', metadata, |
| | 19 | remove_data = Table('xap_remove_data', metadata, |
| 20 | 20 | Column('docid', String(10)),) |
| 21 | 21 | |
| … |
… |
|
| 26 | 26 | pass |
| 27 | 27 | |
| | 28 | statistics = Table('xap_statistics', metadata, |
| | 29 | Column('query', String(200)), |
| | 30 | Column('count', Integer)) |
| 28 | 31 | |
| | 32 | try: |
| | 33 | statistics.create() |
| | 34 | except exceptions.SQLError: |
| | 35 | # already exists |
| | 36 | pass |
| | 37 | |
| | 38 | |
-
|
r148
|
r163
|
|
| | 1 | #!/usr/bin/python |
| | 2 | # -*- coding: UTF-8 -*- |
| | 3 | # |
| | 4 | # Copyright (c) 2007 Tarek Ziadé |
| | 5 | # |
| | 6 | # Authors: |
| | 7 | # Tarek Ziadé <tarek@ziade.org> |
| | 8 | # |
| | 9 | # This program is free software; you can redistribute it and/or |
| | 10 | # modify it under the terms of the GNU General Public License |
| | 11 | # as published by the Free Software Foundation; either version 2 |
| | 12 | # of the License, or (at your option) any later version. |
| | 13 | # |
| | 14 | # This program is distributed in the hope that it will be useful, |
| | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | 17 | # GNU General Public License for more details. |
| | 18 | # |
| | 19 | # You should have received a copy of the GNU General Public License |
| | 20 | # along with this program; if not, write to the Free Software |
| | 21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| | 22 | """ Searcher |
| | 23 | """ |
| | 24 | |
| 1 | 25 | import os |
| 2 | 26 | import logging |
| … |
… |
|
| 5 | 29 | from tokenizer import tokenize |
| 6 | 30 | from settings import DB_FILE |
| | 31 | from model import statistics |
| 7 | 32 | |
| 8 | 33 | def read_only(): |
| … |
… |
|
| 63 | 88 | logging.debug('searching for "%s" is over' % query) |
| 64 | 89 | |
| | 90 | stat = statistics.select(statistics.c.query==query).execute().fetchone() |
| | 91 | |
| | 92 | if stat is not None: |
| | 93 | count = stat.count |
| | 94 | stat.close() |
| | 95 | statistics.update(statistics.c.query==query).execute(count=count+1) |
| | 96 | else: |
| | 97 | statistics.insert().execute(query=query, count=1) |
| | 98 | |
| 65 | 99 | return (_extract_uid(el) for el in res) |
| 66 | 100 | |
| | 101 | def query_stats(query): |
| | 102 | """will return stats""" |
| | 103 | stat = statistics.select(statistics.c.query==query).execute().fetchone() |
| | 104 | if stat is None: |
| | 105 | return 0 |
| | 106 | return stat.count |
| 67 | 107 | |
| | 108 | def query_suggestions(query): |
| | 109 | """will return suggestions on search""" |
| | 110 | return statistics.select(statistics.c.query.like(query+'%')).execute() |
| | 111 | |