source: main/trunk/greenstone2/common-src/indexers/mg/java/org/greenstone/mg/MGSearchWrapper.java@ 30430

Last change on this file since 30430 was 30430, checked in by davidb, 8 years ago

Corrected mistake in load library name

File size: 4.3 KB
Line 
1/*
2 * MGSearchWrapper.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 */
19package 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 */
31public class MGSearchWrapper
32{
33 /** the query result, filled in by runQuery */
34 protected MGQueryResult mg_query_result_ = null;
35
36 /** pointer to c MGWrapperData class - cached indexData and queryInfo */
37 protected long mg_data_ptr_ = 0;
38
39 static {
40
41 String gsdlos = System.getenv("GSDLOS");
42 if (gsdlos!=null && gsdlos.equals("darwin")) {
43 // As of MacOX 10.11 (El Capitan), effectivly supresses DYLD_LIBRARY_PATH (does
44 // not propagate it to child processes). This is a result of changes to their
45 // security model, and seems to come into effect for 'untrusted' executables.
46 // Greenstone run as a regular user, is 'unstrusted'. It is possible, with
47 // admin rights, to override this, however that is not really a viable solution
48 // for our project. Hence the change here to use Systen.load() with an
49 // absolute pathname, rather than rely of System.loadLibrary().
50
51 String gsdl3srchome = System.getenv("GSDL3SRCHOME");
52 String full_jni_library = gsdl3srchome + "/lib/jni/libmgsearchjni.jnilib";
53 System.load(full_jni_library);
54 }
55 else {
56 System.loadLibrary("mgsearchjni");
57 }
58
59 initIDs();
60 }
61
62 public MGSearchWrapper() {
63 mg_query_result_ = new MGQueryResult();
64 initCSide();
65 }
66
67 /** initialises field and method IDs for java side to enable access on C side */
68 private static native void initIDs();
69
70 /** initialises the mg_data_ptr_ */
71 private native boolean initCSide();
72
73 /** returns a document: number docnum at level level
74 * the base_dir and text_path paths should join together to provide
75 * the absolute location of the mg text files eg ..../index/text/demo
76 * returns the doc in utf-8
77 */
78// public native String getDocument(String base_dir, String text_dir, long docnum);
79
80 /** unloads the data */
81 public native boolean unloadIndexData();
82
83 // query param methods
84
85 /** if on=true, sets default casefolding on - it's off by default */
86 public native void setCase(boolean on);
87 /** if on=true, sets default stemming on - it's off by default */
88 public native void setStem(boolean on);
89 /** default is 50 */
90 public native void setMaxDocs(int num);
91 /** if on=true, a query returns term freq info - default is on */
92 public native void setReturnTerms(boolean on);
93 /** sets the index to search - default is 'dtx' */
94 public native void setIndex(String index);
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 {
118 return mg_query_result_;
119 }
120}
121
Note: See TracBrowser for help on using the repository browser.