1 | /*
|
---|
2 | * MGPPSearchWrapper.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.mgpp;
|
---|
20 |
|
---|
21 | import java.util.Vector;
|
---|
22 |
|
---|
23 | /** java wrapper class for access to mgpp in C++
|
---|
24 | *
|
---|
25 | * the native side implemented in MGPPWrapperImpl.cpp
|
---|
26 | * uses MGPPQueryResult to hold the result of a query. the
|
---|
27 | * result of a getDocument is a String
|
---|
28 | * uses the jni
|
---|
29 | *
|
---|
30 | *@see MGPPQueryResult
|
---|
31 | */
|
---|
32 | public class MGPPSearchWrapper {
|
---|
33 |
|
---|
34 | /** the query result
|
---|
35 | * will be filled in by runQuery
|
---|
36 | */
|
---|
37 | protected MGPPQueryResult mgpp_query_result_=null;
|
---|
38 | /** pointer to c++ MGPPWrapperData class - cached indexData and queryInfo
|
---|
39 | */
|
---|
40 | protected long mgpp_data_ptr_=0;
|
---|
41 |
|
---|
42 | static {
|
---|
43 | String gsdlos = System.getenv("GSDLOS");
|
---|
44 | if (gsdlos!=null && gsdlos.equals("darwin")) {
|
---|
45 | // As of MacOX 10.11 (El Capitan), effectivly supresses DYLD_LIBRARY_PATH (does
|
---|
46 | // not propagate it to child processes). This is a result of changes to their
|
---|
47 | // security model, and seems to come into effect for 'untrusted' executables.
|
---|
48 | // Greenstone run as a regular user, is 'unstrusted'. It is possible, with
|
---|
49 | // admin rights, to override this, however that is not really a viable solution
|
---|
50 | // for our project. Hence the change here to use Systen.load() with an
|
---|
51 | // absolute pathname, rather than rely of System.loadLibrary().
|
---|
52 |
|
---|
53 | String gsdl3srchome = System.getenv("GSDL3SRCHOME");
|
---|
54 | String full_jni_library = gsdl3srchome + "/lib/jni/libmgppsearchjni.jnilib";
|
---|
55 | System.load(full_jni_library);
|
---|
56 | }
|
---|
57 | else {
|
---|
58 | System.loadLibrary("mgppsearchjni");
|
---|
59 | }
|
---|
60 |
|
---|
61 | initIDs();
|
---|
62 | }
|
---|
63 |
|
---|
64 | public MGPPSearchWrapper() {
|
---|
65 | mgpp_query_result_ = new MGPPQueryResult();
|
---|
66 | initCppSide();
|
---|
67 | }
|
---|
68 |
|
---|
69 | /** initialises field and method IDs for java side to enable access on
|
---|
70 | C++ side */
|
---|
71 | private static native void initIDs();
|
---|
72 |
|
---|
73 | /** initialises the mgpp_data_ptr_ */
|
---|
74 | private native boolean initCppSide();
|
---|
75 |
|
---|
76 | /** returns a document: number docnum at level level
|
---|
77 | * text_path path should provide
|
---|
78 | * the absolute location of the mgpp text files eg ..../index/text/demo
|
---|
79 | * returns the doc in utf-8
|
---|
80 | */
|
---|
81 | //only this method is for search purpose
|
---|
82 | // public native String getDocument(String text_path,
|
---|
83 | // String level,
|
---|
84 | // long docnum );
|
---|
85 |
|
---|
86 | /** the public method - converts between utf-8 and unicode
|
---|
87 | */
|
---|
88 | // public String getDocument(String text_path,
|
---|
89 | // String level,
|
---|
90 | // long docnum ) {
|
---|
91 |
|
---|
92 | //String utf8_doc = getUtF8Document(base_dir, text_path, level, docnum);
|
---|
93 |
|
---|
94 | /** load up the data structure for index
|
---|
95 | * - maintains state between requests as can be slow
|
---|
96 | * index_path should provide
|
---|
97 | * the absolute location of the mgpp index files eg ..../index/tt/demo
|
---|
98 | */
|
---|
99 | public native boolean loadIndexData(String index_path);
|
---|
100 | /** unloads the data */
|
---|
101 | public native boolean unloadIndexData();
|
---|
102 |
|
---|
103 | /** reset all the params back to their defaults */
|
---|
104 | public native void reset();
|
---|
105 | // query param methods
|
---|
106 |
|
---|
107 | /** if on=true, sets default stemming on - its off by default*/
|
---|
108 | public native void setStem(boolean on);
|
---|
109 |
|
---|
110 | /** if on=true, sets default accentfolding on - its off by default*/
|
---|
111 | public native void setAccentFold(boolean on);
|
---|
112 |
|
---|
113 | /** if on=true, sets default casefolding on - its off by default */
|
---|
114 | public native void setCase(boolean on);
|
---|
115 | /** default is 50 */
|
---|
116 | public native void setMaxDocs(int num);
|
---|
117 | /** if on=true, sorts by rank, otherwise returns in build order -
|
---|
118 | default is on */
|
---|
119 | public native void setSortByRank(boolean on);
|
---|
120 | /** if on=true, a query returns term freq info - default is on */
|
---|
121 | public native void setReturnTerms(boolean on);
|
---|
122 | /** sets the granularity of the query - default 'Document' */
|
---|
123 | public native void setQueryLevel(String level);
|
---|
124 | /** sets the granularity of the result - default 'Document' */
|
---|
125 | public native void setReturnLevel(String level);
|
---|
126 | /** sets the default boolean operator - AND(=1)/OR(=0) */
|
---|
127 | public native void setMatchMode(int mode);
|
---|
128 |
|
---|
129 | /** sets maxnumeric */
|
---|
130 | public native void setMaxNumeric(int maxnumeric);
|
---|
131 | /** returns a string with all the current query param settings */
|
---|
132 | public native String getQueryParams();
|
---|
133 |
|
---|
134 | /** actually carry out the query. Use the set methods to set any query
|
---|
135 | params
|
---|
136 | * writes the result to query_result
|
---|
137 | */
|
---|
138 | public native void runQuery(String query_string);
|
---|
139 |
|
---|
140 | /** get the result out of the wrapper */
|
---|
141 | public MGPPQueryResult getQueryResult() {
|
---|
142 | return mgpp_query_result_;
|
---|
143 | }
|
---|
144 |
|
---|
145 | }
|
---|