Changeset 163:a1304a86b5d2

Show
Ignore:
Timestamp:
08/23/07 13:25:06 (15 months ago)
Author:
Tarek Ziad?? <tarek@…>
Message:

merged

Location:
xap
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • xap/doc/indexer.txt

    r145 r163  
    143143    [] 
    144144 
     145statistics 
     146========== 
     147 
     148We can also do a bit of statistics:: 
     149 
     150 
     151 
  • xap/model.py

    r150 r163  
    77 
    88 
    9 index_data = Table('index_data', metadata, 
     9index_data = Table('xap_index_data', metadata, 
    1010                   Column('docid', String(10)), 
    1111                   Column('data', TEXT())) 
     
    1717    pass 
    1818 
    19 remove_data = Table('remove_data', metadata, 
     19remove_data = Table('xap_remove_data', metadata, 
    2020                   Column('docid', String(10)),) 
    2121 
     
    2626    pass 
    2727 
     28statistics = Table('xap_statistics', metadata, 
     29                   Column('query', String(200)), 
     30                   Column('count', Integer)) 
    2831 
     32try: 
     33    statistics.create() 
     34except exceptions.SQLError: 
     35    # already exists 
     36    pass 
     37 
     38 
  • xap/searcher.py

    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 
    125import os 
    226import logging 
     
    529from tokenizer import tokenize 
    630from settings import DB_FILE 
     31from model import statistics 
    732 
    833def read_only(): 
     
    6388    logging.debug('searching for "%s" is over' % query) 
    6489 
     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 
    6599    return (_extract_uid(el) for el in res) 
    66100 
     101def 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 
    67107 
     108def query_suggestions(query): 
     109    """will return suggestions on search""" 
     110    return statistics.select(statistics.c.query.like(query+'%')).execute() 
     111