1 /**
2  Copyright (c) 2003, Technology Concepts & Design, Inc.
3  Copyright (c) 2008,2011, Olly Betts
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted
7  provided that the following conditions are met:
8 
9  - Redistributions of source code must retain the above copyright notice, this list of conditions
10  and the following disclaimer.
11 
12  - Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13  and the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  - Neither the name of Technology Concepts & Design, Inc. nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
21  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  THE POSSIBILITY OF SUCH DAMAGE.
26  **/
27 
28 #include "xapian_jni.h"
29 
30 using namespace std;
31 using namespace Xapian;
32 
Java_org_xapian_XapianJNI_mset_1convert_1to_1percent__JJ(JNIEnv * env,jclass clazz,jlong msetid,jlong msetiteratorid)33 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1convert_1to_1percent__JJ(JNIEnv *env, jclass clazz, jlong msetid, jlong msetiteratorid) {
34     TRY
35         MSet *this_mset = obj_from_id<MSet *>(msetid);
36         MSetIterator *itr = obj_from_id<MSetIterator *>(msetiteratorid);
37         return this_mset->convert_to_percent(*itr);
38     CATCH(-1)
39 }
40 
Java_org_xapian_XapianJNI_mset_1convert_1to_1percent__JD(JNIEnv * env,jclass clazz,jlong msetid,jdouble weight)41 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1convert_1to_1percent__JD(JNIEnv *env, jclass clazz, jlong msetid, jdouble weight) {
42     TRY
43         MSet *mset = obj_from_id<MSet *>(msetid);
44         return mset->convert_to_percent(weight);
45     CATCH(-1)
46 }
47 
Java_org_xapian_XapianJNI_mset_1get_1termfreq(JNIEnv * env,jclass clazz,jlong msetid,jstring term)48 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1get_1termfreq(JNIEnv *env, jclass clazz, jlong msetid, jstring term) {
49     TRY
50         MSet *mset = obj_from_id<MSet *>(msetid);
51         return mset->get_termfreq(cpp_string(env, term));
52     CATCH(-1)
53 }
54 
Java_org_xapian_XapianJNI_mset_1get_1termweight(JNIEnv * env,jclass clazz,jlong msetid,jstring term)55 JNIEXPORT jdouble JNICALL Java_org_xapian_XapianJNI_mset_1get_1termweight(JNIEnv *env, jclass clazz, jlong msetid, jstring term) {
56     TRY
57         MSet *mset = obj_from_id<MSet *>(msetid);
58         return mset->get_termweight(cpp_string(env, term));
59     CATCH(-1)
60 }
61 
Java_org_xapian_XapianJNI_mset_1get_1firstitem(JNIEnv * env,jclass clazz,jlong msetid)62 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1get_1firstitem(JNIEnv *env, jclass clazz, jlong msetid) {
63     TRY
64         MSet *mset = obj_from_id<MSet *>(msetid);
65         return mset->get_firstitem();
66     CATCH(-1)
67 }
68 
Java_org_xapian_XapianJNI_mset_1get_1matches_1lower_1bound(JNIEnv * env,jclass clazz,jlong msetid)69 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1get_1matches_1lower_1bound(JNIEnv *env, jclass clazz, jlong msetid) {
70     TRY
71         MSet *mset = obj_from_id<MSet *>(msetid);
72         return mset->get_matches_lower_bound();
73     CATCH(-1)
74 }
75 
Java_org_xapian_XapianJNI_mset_1get_1matches_1estimated(JNIEnv * env,jclass clazz,jlong msetid)76 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1get_1matches_1estimated(JNIEnv *env, jclass clazz, jlong msetid) {
77     TRY
78         MSet *mset = obj_from_id<MSet *>(msetid);
79         return mset->get_matches_estimated();
80     CATCH(-1)
81 }
82 
Java_org_xapian_XapianJNI_mset_1get_1matches_1upper_1bound(JNIEnv * env,jclass clazz,jlong msetid)83 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1get_1matches_1upper_1bound(JNIEnv *env, jclass clazz, jlong msetid) {
84     TRY
85         MSet *mset = obj_from_id<MSet *>(msetid);
86         return mset->get_matches_upper_bound();
87     CATCH(-1)
88 }
89 
Java_org_xapian_XapianJNI_mset_1get_1max_1possible(JNIEnv * env,jclass clazz,jlong msetid)90 JNIEXPORT jdouble JNICALL Java_org_xapian_XapianJNI_mset_1get_1max_1possible(JNIEnv *env, jclass clazz, jlong msetid) {
91     TRY
92         MSet *mset = obj_from_id<MSet *>(msetid);
93         return mset->get_max_possible();
94     CATCH(-1)
95 }
96 
Java_org_xapian_XapianJNI_mset_1get_1max_1attained(JNIEnv * env,jclass clazz,jlong msetid)97 JNIEXPORT jdouble JNICALL Java_org_xapian_XapianJNI_mset_1get_1max_1attained(JNIEnv *env, jclass clazz, jlong msetid) {
98     TRY
99         MSet *mset = obj_from_id<MSet *>(msetid);
100         return mset->get_max_attained();
101     CATCH(-1)
102 }
103 
Java_org_xapian_XapianJNI_mset_1size(JNIEnv * env,jclass clazz,jlong msetid)104 JNIEXPORT jint JNICALL Java_org_xapian_XapianJNI_mset_1size(JNIEnv *env, jclass clazz, jlong msetid) {
105     TRY
106         MSet *mset = obj_from_id<MSet *>(msetid);
107         return mset->size();
108     CATCH(-1)
109 }
110 
Java_org_xapian_XapianJNI_mset_1empty(JNIEnv * env,jclass clazz,jlong msetid)111 JNIEXPORT jboolean JNICALL Java_org_xapian_XapianJNI_mset_1empty(JNIEnv *env, jclass clazz, jlong msetid) {
112     TRY
113         MSet *mset = obj_from_id<MSet *>(msetid);
114         return mset->empty();
115     CATCH(0)
116 }
117 
Java_org_xapian_XapianJNI_mset_1begin(JNIEnv * env,jclass clazz,jlong msetid)118 JNIEXPORT jlong JNICALL Java_org_xapian_XapianJNI_mset_1begin(JNIEnv *env, jclass clazz, jlong msetid) {
119     TRY
120         MSet *mset = obj_from_id<MSet *>(msetid);
121         MSetIterator *itr = new MSetIterator(mset->begin());
122         return id_from_obj(itr);
123     CATCH(-1)
124 }
125 
Java_org_xapian_XapianJNI_mset_1end(JNIEnv * env,jclass clazz,jlong msetid)126 JNIEXPORT jlong JNICALL Java_org_xapian_XapianJNI_mset_1end(JNIEnv *env, jclass clazz, jlong msetid) {
127     TRY
128         MSet *mset = obj_from_id<MSet *>(msetid);
129         MSetIterator *itr = new MSetIterator(mset->end());
130         return id_from_obj(itr);
131     CATCH(-1)
132 }
133 
Java_org_xapian_XapianJNI_mset_1back(JNIEnv * env,jclass clazz,jlong msetid)134 JNIEXPORT jlong JNICALL Java_org_xapian_XapianJNI_mset_1back(JNIEnv *env, jclass clazz, jlong msetid) {
135     TRY
136         MSet *mset = obj_from_id<MSet *>(msetid);
137         MSetIterator *itr = new MSetIterator(mset->back());
138         return id_from_obj(itr);
139     CATCH(-1)
140 }
141 
Java_org_xapian_XapianJNI_mset_1element(JNIEnv * env,jclass clazz,jlong msetid,jlong index)142 JNIEXPORT jlong JNICALL Java_org_xapian_XapianJNI_mset_1element (JNIEnv *env, jclass clazz, jlong msetid, jlong index) {
143     TRY
144         MSet *mset = obj_from_id<MSet *>(msetid);
145         MSetIterator *itr = new MSetIterator((*mset)[index]);
146         return id_from_obj(itr);
147     CATCH(-1)
148 }
149 
Java_org_xapian_XapianJNI_mset_1get_1description(JNIEnv * env,jclass clazz,jlong msetid)150 JNIEXPORT jstring JNICALL Java_org_xapian_XapianJNI_mset_1get_1description (JNIEnv *env, jclass clazz, jlong msetid) {
151     TRY
152         MSet *mset = obj_from_id<MSet *>(msetid);
153         return env->NewStringUTF(mset->get_description().c_str());
154     CATCH(NULL)
155 }
156 
Java_org_xapian_XapianJNI_mset_1finalize(JNIEnv * env,jclass clazz,jlong msetid)157 JNIEXPORT void JNICALL Java_org_xapian_XapianJNI_mset_1finalize (JNIEnv *env, jclass clazz, jlong msetid) {
158     MSet *mset = obj_from_id<MSet *>(msetid);
159     delete mset;
160 }
161 
162