root / xap / tags / 0.1.5 / indexer.py

Revision 226:7bbf27312bd7, 1.8 kB (checked in by Lafaye Philippe (RAGE2000) <lafaye@…>, 8 months ago)

Add a new version

Line 
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""" Indexer, takes the work into the SQL DB
23"""
24import os
25import sys
26import logging
27
28from model import sql_db
29from model import index_data
30from model import remove_data
31
32def reset():
33    """resets the DBs"""
34    sql_db.execute('delete from xap_index_data')
35    sql_db.execute('delete from xap_remove_data')
36
37def index_document(docid, data, language=None):
38    """puts the data into the table for the indexer to pick it up"""
39    logging.debug('sql:indexing %s' % docid)
40    index_data.insert().execute(docid=docid, data=data, language_iso=language)
41
42def delete_document(docid):
43    """puts the data into the table for the indexer to remove it"""
44    logging.debug('sql:deleting %s' % docid)
45    remove_data.insert().execute(docid=docid)
46
47def work_in_process():
48    """retrieve the work in process"""
49    index = [doc.docid for doc in index_data.select().execute()]
50    remove = [doc.docid for doc in remove_data.select().execute()]
51    return index, remove
52
53def is_working():
54    """checks for the db content"""
55    return work_in_process() != ([], [])
Note: See TracBrowser for help on using the browser.