1 | /*
|
---|
2 | * MGRetrieveWrapper.java
|
---|
3 | * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.greenstone.mg;
|
---|
20 |
|
---|
21 |
|
---|
22 | /** java wrapper class for access to mg in C
|
---|
23 | *
|
---|
24 | * the native side implemented in MGWrapperImpl.c
|
---|
25 | * uses MGQueryResult to hold the result of a query.
|
---|
26 | * the result of a getDocument is a String
|
---|
27 | * uses the jni
|
---|
28 | *
|
---|
29 | *@see MGQueryResult
|
---|
30 | */
|
---|
31 | public class MGRetrieveWrapper {
|
---|
32 | /** the query result, filled in by runQuery */
|
---|
33 | // protected MGQueryResult mg_query_result_ = null;
|
---|
34 |
|
---|
35 | /** pointer to c MGWrapperData class - cached indexData and queryInfo */
|
---|
36 | protected long mg_data_ptr_ = 0;
|
---|
37 |
|
---|
38 | static {
|
---|
39 |
|
---|
40 | String gsdlos = System.getenv("GSDLOS");
|
---|
41 | if (gsdlos!=null && gsdlos.equals("darwin")) {
|
---|
42 | // As of MacOX 10.11 (El Capitan), effectivly supresses DYLD_LIBRARY_PATH (does
|
---|
43 | // not propagate it to child processes). This is a result of changes to their
|
---|
44 | // security model, and seems to come into effect for 'untrusted' executables.
|
---|
45 | // Greenstone run as a regular user, is 'unstrusted'. It is possible, with
|
---|
46 | // admin rights, to override this, however that is not really a viable solution
|
---|
47 | // for our project. Hence the change here to use Systen.load() with an
|
---|
48 | // absolute pathname, rather than rely of System.loadLibrary().
|
---|
49 |
|
---|
50 | String gsdl3srchome = System.getenv("GSDL3SRCHOME");
|
---|
51 | String full_jni_library = gsdl3srchome + "/lib/jni/libmgretrievejni.jnilib";
|
---|
52 | System.load(full_jni_library);
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | System.loadLibrary ("mgretrievejni");
|
---|
56 | }
|
---|
57 | initIDs ();
|
---|
58 | }
|
---|
59 |
|
---|
60 | public MGRetrieveWrapper () {
|
---|
61 | // mg_query_result_ = new MGQueryResult ();
|
---|
62 | initCSide ();
|
---|
63 | }
|
---|
64 |
|
---|
65 | /** initialises field and method IDs for java side to enable access on C side */
|
---|
66 | private static native void initIDs ();
|
---|
67 |
|
---|
68 | /** initialises the mg_data_ptr_ */
|
---|
69 | private native boolean initCSide ();
|
---|
70 |
|
---|
71 | /** unloads the data */
|
---|
72 | public native boolean unloadIndexData ();
|
---|
73 |
|
---|
74 | /** sets the index to search - default is 'dtx' */
|
---|
75 | public native void setIndex (String index);
|
---|
76 |
|
---|
77 | /** returns a document: number docnum at level level
|
---|
78 | * the base_dir and text_path paths should join together to provide
|
---|
79 | * the absolute location of the mg text files eg ..../index/text/demo
|
---|
80 | * returns the doc in utf-8
|
---|
81 | */
|
---|
82 | public native String getDocument (String base_dir, String text_dir, long docnum);
|
---|
83 |
|
---|
84 |
|
---|
85 | // the following is for search service // query param methods
|
---|
86 | //
|
---|
87 | // /** if on=true, sets default casefolding on - it's off by default */
|
---|
88 | // public native void setCase (boolean on);
|
---|
89 | // /** if on=true, sets default stemming on - it's off by default */
|
---|
90 | // public native void setStem (boolean on);
|
---|
91 | // /** default is 50 */
|
---|
92 | // public native void setMaxDocs (int num);
|
---|
93 | // /** if on=true, a query returns term freq info - default is on */
|
---|
94 | // public native void setReturnTerms (boolean on);
|
---|
95 | // /** sets the default boolean operator - AND(=1)/OR(=0) */
|
---|
96 | // public native void setMatchMode (int mode);
|
---|
97 | //
|
---|
98 | // /** returns a string with all the current query param settings */
|
---|
99 | // public native String getQueryParams ();
|
---|
100 | //
|
---|
101 | // /** sets maxnumeric */
|
---|
102 | // public native void setMaxNumeric (int maxnumeric);
|
---|
103 | //
|
---|
104 | // /** actually carry out the query.
|
---|
105 | // * Use the set methods to set query results.
|
---|
106 | // * Writes the result to query_result.
|
---|
107 | // * - maintains state between requests as can be slow
|
---|
108 | // * base_dir and index_path should join together to provide
|
---|
109 | // * the absolute location of the mg index files eg ..../index/dtx/demo
|
---|
110 | // * base_dir must end with a file separator (OS dependant)
|
---|
111 | // */
|
---|
112 | // public native void runQuery (String base_dir, String text_dir, String query_string);
|
---|
113 | //
|
---|
114 | //
|
---|
115 | // /** get the result out of the wrapper */
|
---|
116 | // public MGQueryResult getQueryResult () {
|
---|
117 | // return mg_query_result_;
|
---|
118 | // }
|
---|
119 | }
|
---|