1 | /*********************************************************************
|
---|
2 | Copyright (C) 2003 Imperial College London
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
17 | ***********************************************************************/
|
---|
18 |
|
---|
19 | package vishnu.server.Search;
|
---|
20 |
|
---|
21 | import java.util.Vector;
|
---|
22 | import java.io.BufferedReader;
|
---|
23 | import java.io.InputStreamReader;
|
---|
24 | import java.io.File;
|
---|
25 |
|
---|
26 | import org.greenstone.mg.*;
|
---|
27 |
|
---|
28 | public class MGSearcher implements SearchInterface
|
---|
29 | {
|
---|
30 |
|
---|
31 | private String collection_home;
|
---|
32 | private String collection_name;
|
---|
33 | private Vector docIDs;
|
---|
34 | private Vector docDescs;
|
---|
35 | private String mg_index_path;
|
---|
36 | private MGWrapper mg_src;
|
---|
37 |
|
---|
38 | public MGSearcher(String coll_home, String coll_name)
|
---|
39 | {
|
---|
40 | collection_home = coll_home;
|
---|
41 | if (!collection_home.endsWith(File.separator)) {
|
---|
42 | collection_home += File.separator;
|
---|
43 | }
|
---|
44 | collection_name = coll_name;
|
---|
45 | mg_src = new MGWrapper();
|
---|
46 | mg_index_path = "index"+File.separator+"mg_index"+ File.separator+collection_name+File.separator+collection_name;
|
---|
47 | mg_src.setIndex(mg_index_path);
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | public Vector getDocIdentifiers()
|
---|
52 | {
|
---|
53 | return docIDs;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | public Vector getDocDescriptions()
|
---|
58 | {
|
---|
59 | return docDescs;
|
---|
60 | }
|
---|
61 |
|
---|
62 | // why do we want document in a vector ?? -- kjdon
|
---|
63 | public Vector getDocContent(int doc_num) {
|
---|
64 |
|
---|
65 | Vector document = new Vector();
|
---|
66 | String doc_content = this.mg_src.getDocument(collection_home, mg_index_path, doc_num);
|
---|
67 | String [] lines = doc_content.split("\n");
|
---|
68 | for (int i=0; i<lines.length; i++) {
|
---|
69 | document.addElement(lines[i]);
|
---|
70 | }
|
---|
71 | return document;
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | public void search(String query) {
|
---|
76 | this.mg_src.runQuery(collection_home, mg_index_path, query);
|
---|
77 | MGQueryResult mqr = this.mg_src.getQueryResult();
|
---|
78 | docIDs = new Vector();
|
---|
79 | docDescs = new Vector();
|
---|
80 | Vector doc_results = mqr.getDocs();
|
---|
81 | int max_docs = Math.min(MAX_DOCS,doc_results.size());
|
---|
82 | for (int i=0; i<max_docs; i++) {
|
---|
83 | int doc_num = (int)((MGDocInfo)doc_results.get(i)).num_;
|
---|
84 | docIDs.addElement(new Integer(doc_num));
|
---|
85 | String doc_content = this.mg_src.getDocument(collection_home, mg_index_path, doc_num);
|
---|
86 | docDescs.addElement(doc_content.substring(0,MAX_DESCRIPTION_LENGTH));
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|