source: main/trunk/greenstone2/runtime-src/src/colservr/lucenesource.cpp@ 25234

Last change on this file since 25234 was 20730, checked in by kjdon, 15 years ago

now we are using gs2:docOID to find the right section in a document xml file, instead of gs2:id. gs2:id was stored as docnum in the database. when getting the section, gs2:docOID will be the same as the greenstone OID.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/**********************************************************************
2 *
3 * lucenesource.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 "lucenesource.h"
27#include "fileutil.h"
28#include "OIDtools.h"
29#include "expat_document.h"
30#include "lucenesearch.h"
31
32lucenesourceclass::lucenesourceclass ()
33 : sourceclass()
34{
35 classname = "lucenesource";
36}
37
38lucenesourceclass::~lucenesourceclass () {
39}
40
41bool lucenesourceclass::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 (db_ptr == NULL) {
47 // most likely a configuration problem
48 logout << text_t2ascii
49 << "configuration error: lucenesource contains a null dbclass\n\n";
50 err = configurationError;
51 return true;
52 }
53
54 // open the database
55 db_ptr->setlogout(&logout);
56 if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
57 // most likely a system problem (we have already checked that the database exists)
58 logout << text_t2ascii
59 << "system problem: open on database \"" << db_filename << "\" failed\n\n";
60 err = systemProblem;
61 return true;
62 }
63
64 text_t tOID = OID;
65 if (needs_translating (OID))
66 translate_OID (OID, tOID, err, logout);
67 infodbclass info;
68 if (!db_ptr->getinfo(tOID, info)) {
69 db_ptr->closedatabase(); // Important that local library doesn't leave any files open
70 return false;
71 }
72
73 if (info["hastxt"].getint() == 0) { // there is no text for this section
74 return false; // true??
75 }
76
77 // get the parent id
78 text_t parent_OID;
79 get_top(tOID, parent_OID);
80
81 if (!db_ptr->getinfo(parent_OID, info)) {
82 db_ptr->closedatabase(); // Important that local library doesn't leave any files open
83 return false;
84 }
85
86 text_t archive_dir = info["archivedir"];
87 text_t full_path_to_doc = filename_cat(collectdir, "index", "text", archive_dir, "doc.xml");
88
89 doc.clear();
90 db_ptr->closedatabase(); // Important that local library doesn't leave any files open
91 expat_document(full_path_to_doc, ((lucenesearchclass*)textsearchptr)->textlevel, tOID, doc);
92 return true;
93}
Note: See TracBrowser for help on using the repository browser.