source: trunk/indexers/mg/java/org/greenstone/mg/MGWrapper.java@ 3744

Last change on this file since 3744 was 3744, checked in by mdewsnip, 21 years ago

Initial implementation of MG JNI (Java side).

  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
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 */
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 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, sorts by rank, otherwise returns in build order -
74 default is on */
75 public native void setSortByRank(boolean on);
76 /** if on=true, a query returns term freq info - default is on */
77 public native void setReturnTerms(boolean on);
78 /** sets the index to search - default is 'dtx' */
79 public native void setIndex(String index);
80 /** sets the default boolean operator - AND(=1)/OR(=0) */
81 public native void setMatchMode(int mode);
82
83 /** returns a string with all the current query param settings */
84 public native String getQueryParams();
85
86 /** actually carry out the query.
87 Use the set methods to set query results.
88 Writes the result to query_result.
89 * - maintains state between requests as can be slow
90 * base_dir and index_path should join together to provide
91 * the absolute location of the mg index files eg ..../index/dtx/demo
92 * base_dir must end with a file separator (OS dependant)
93 */
94 public native void runQuery(String base_dir, String text_dir, String query_string);
95
96
97 /** get the result out of the wrapper */
98 public MGQueryResult getQueryResult()
99 {
100 return mg_query_result_;
101 }
102}
Note: See TracBrowser for help on using the repository browser.