1 | /*
|
---|
2 | * MGWrapper.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 MGWrapper
|
---|
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 | System.loadLibrary("mgjni");
|
---|
41 | initIDs();
|
---|
42 | }
|
---|
43 |
|
---|
44 | public MGWrapper() {
|
---|
45 | mg_query_result_ = new MGQueryResult();
|
---|
46 | initCSide();
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** initialises field and method IDs for java side to enable access on C side */
|
---|
50 | private static native void initIDs();
|
---|
51 |
|
---|
52 | /** initialises the mg_data_ptr_ */
|
---|
53 | private native boolean initCSide();
|
---|
54 |
|
---|
55 | /** returns a document: number docnum at level level
|
---|
56 | * the base_dir and text_path paths should join together to provide
|
---|
57 | * the absolute location of the mg text files eg ..../index/text/demo
|
---|
58 | * returns the doc in utf-8
|
---|
59 | */
|
---|
60 | public native String getDocument(String base_dir, String text_dir, long docnum);
|
---|
61 |
|
---|
62 | /** unloads the data */
|
---|
63 | public native boolean unloadIndexData();
|
---|
64 |
|
---|
65 | // query param methods
|
---|
66 |
|
---|
67 | /** if on=true, sets default casefolding on - it's off by default */
|
---|
68 | public native void setCase(boolean on);
|
---|
69 | /** if on=true, sets default stemming on - it's off by default */
|
---|
70 | public native void setStem(boolean on);
|
---|
71 | /** default is 50 */
|
---|
72 | public native void setMaxDocs(int num);
|
---|
73 | /** if on=true, a query returns term freq info - default is on */
|
---|
74 | public native void setReturnTerms(boolean on);
|
---|
75 | /** sets the index to search - default is 'dtx' */
|
---|
76 | public native void setIndex(String index);
|
---|
77 | /** sets the default boolean operator - AND(=1)/OR(=0) */
|
---|
78 | public native void setMatchMode(int mode);
|
---|
79 |
|
---|
80 | /** returns a string with all the current query param settings */
|
---|
81 | public native String getQueryParams();
|
---|
82 |
|
---|
83 | /** actually carry out the query.
|
---|
84 | Use the set methods to set query results.
|
---|
85 | Writes the result to query_result.
|
---|
86 | * - maintains state between requests as can be slow
|
---|
87 | * base_dir and index_path should join together to provide
|
---|
88 | * the absolute location of the mg index files eg ..../index/dtx/demo
|
---|
89 | * base_dir must end with a file separator (OS dependant)
|
---|
90 | */
|
---|
91 | public native void runQuery(String base_dir, String text_dir, String query_string);
|
---|
92 |
|
---|
93 |
|
---|
94 | /** get the result out of the wrapper */
|
---|
95 | public MGQueryResult getQueryResult()
|
---|
96 | {
|
---|
97 | return mg_query_result_;
|
---|
98 | }
|
---|
99 | }
|
---|