[8027] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * lucenegdbmsource.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "lucenegdbmsource.h"
|
---|
[9916] | 27 | #include "fileutil.h"
|
---|
| 28 | #include "OIDtools.h"
|
---|
| 29 | #include "expat_document.h"
|
---|
| 30 | #include "lucenesearch.h"
|
---|
[8027] | 31 |
|
---|
[9346] | 32 | lucenegdbmsourceclass::lucenegdbmsourceclass ()
|
---|
| 33 | : gdbmsourceclass()
|
---|
| 34 | {
|
---|
| 35 | classname = "lucenegdbmsource";
|
---|
[8027] | 36 | }
|
---|
| 37 |
|
---|
| 38 | lucenegdbmsourceclass::~lucenegdbmsourceclass () {
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[9916] | 41 | bool lucenegdbmsourceclass::get_document (const text_t &OID, text_t &doc,
|
---|
| 42 | comerror_t &err, ostream &logout) {
|
---|
| 43 |
|
---|
| 44 | outconvertclass text_t2ascii;
|
---|
| 45 | err = noError;
|
---|
| 46 | if (gdbmptr == NULL) {
|
---|
| 47 | // most likely a configuration problem
|
---|
| 48 | logout << text_t2ascii
|
---|
| 49 | << "configuration error: lucenegdbmsource contains a null gdbmclass\n\n";
|
---|
| 50 | err = configurationError;
|
---|
| 51 | return true;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | // open the database
|
---|
| 55 | gdbmptr->setlogout(&logout);
|
---|
| 56 | if (!gdbmptr->opendatabase (gdbm_filename, GDBM_READER, 100, false)) {
|
---|
| 57 | // most likely a system problem (we have already checked that the
|
---|
| 58 | // gdbm database exists)
|
---|
| 59 | logout << text_t2ascii
|
---|
| 60 | << "system problem: open on gdbm database \""
|
---|
| 61 | << gdbm_filename << "\" failed\n\n";
|
---|
| 62 | err = systemProblem;
|
---|
| 63 | return true;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | text_t tOID = OID;
|
---|
| 67 | if (needs_translating (OID))
|
---|
| 68 | translate_OID (OID, tOID, err, logout);
|
---|
| 69 | infodbclass info;
|
---|
[13780] | 70 | if (!gdbmptr->getinfo(tOID, info)) {
|
---|
| 71 | gdbmptr->closedatabase(); // Important that local library doesn't leave any files open
|
---|
| 72 | return false;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[9916] | 75 | if (info["hastxt"].getint() == 0) { // there is no text for this section
|
---|
| 76 | return false; // true??
|
---|
| 77 | }
|
---|
| 78 | int docnum = info["docnum"].getint();
|
---|
| 79 |
|
---|
| 80 | // get the parent id
|
---|
| 81 | text_t parent_OID;
|
---|
| 82 | get_top(tOID, parent_OID);
|
---|
| 83 |
|
---|
| 84 | // locate the parent info ingdbm db
|
---|
[13780] | 85 | if (!gdbmptr->getinfo(parent_OID, info)) {
|
---|
| 86 | gdbmptr->closedatabase(); // Important that local library doesn't leave any files open
|
---|
| 87 | return false;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[9916] | 90 | text_t archive_dir = info["assocfilepath"];
|
---|
| 91 | text_t full_path_to_doc = filename_cat(collectdir, "index", "text", archive_dir, "doc.xml");
|
---|
| 92 |
|
---|
| 93 | doc.clear();
|
---|
[13780] | 94 | gdbmptr->closedatabase(); // Important that local library doesn't leave any files open
|
---|
[9916] | 95 | expat_document(full_path_to_doc, ((lucenesearchclass*)textsearchptr)->gdbm_level, text_t(docnum), doc);
|
---|
| 96 | return true;
|
---|
| 97 | }
|
---|