| 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 | """ |
|---|
| 24 | import os |
|---|
| 25 | import sys |
|---|
| 26 | import logging |
|---|
| 27 | |
|---|
| 28 | from model import sql_db |
|---|
| 29 | from model import index_data |
|---|
| 30 | from model import remove_data |
|---|
| 31 | |
|---|
| 32 | def reset(): |
|---|
| 33 | """resets the DBs""" |
|---|
| 34 | sql_db.execute('delete from xap_index_data') |
|---|
| 35 | sql_db.execute('delete from xap_remove_data') |
|---|
| 36 | |
|---|
| 37 | def 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 | |
|---|
| 42 | def 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 | |
|---|
| 47 | def 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 | |
|---|
| 53 | def is_working(): |
|---|
| 54 | """checks for the db content""" |
|---|
| 55 | return work_in_process() != ([], []) |
|---|