Skip to content

Commit 803abbd

Browse files
committed
[WIP] Add search wrapping
1 parent d6ac65d commit 803abbd

File tree

5 files changed

+208
-0
lines changed

5 files changed

+208
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.libzim;
21+
22+
public class Query
23+
{
24+
public Query(string query);
25+
public native Query setQuery(string query);
26+
public native Query setGeorange(float latitude, float longitute, float distance);
27+
28+
///--------- The wrapper thing
29+
// To delete our native wrapper
30+
public native void dispose();
31+
32+
// A pointer (as a long) to a native Handle
33+
private long nativeHandle;
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.libzim;
21+
22+
import org.kiwix.libzim.SearchResultSet;
23+
24+
public class Search
25+
{
26+
public native SearchResultSet getResults(int start, int maxResults);
27+
public native long getEstimatedMatches();
28+
29+
///--------- The wrapper thing
30+
// To delete our native wrapper
31+
public native void dispose();
32+
33+
// A pointer (as a long) to a native Handle
34+
private long nativeHandle;
35+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.libzim;
21+
22+
import org.kiwix.libzim.SearchIterator;
23+
24+
public class SearchIterator implement Iterator<Entry>
25+
{
26+
public native string getPath();
27+
public native string getTitle();
28+
public native int getScore();
29+
public native string getSnippet();
30+
public native int getWordCount();
31+
public native int getFileIndex();
32+
public native int size();
33+
public native string getZimId();
34+
35+
public native boolean hasNext();
36+
public native Entry next();
37+
38+
///--------- The wrapper thing
39+
// To delete our native wrapper
40+
public native void dispose();
41+
42+
// A pointer (as a long) to a native Handle
43+
private long nativeHandle;
44+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.libzim;
21+
22+
import org.kiwix.libzim.SearchIterator;
23+
24+
public class SearchResultSet
25+
{
26+
public native SearchIterator begin();
27+
public native long size();
28+
29+
///--------- The wrapper thing
30+
// To delete our native wrapper
31+
public native void dispose();
32+
33+
// A pointer (as a long) to a native Handle
34+
private long nativeHandle;
35+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
20+
package org.kiwix.libzim;
21+
22+
import org.kiwix.libzim.ZimFileFormatException;
23+
import org.kiwix.libzim.Archive;
24+
import org.kiwix.libzim.Search;
25+
import org.kiwix.libzim.Query;
26+
import java.io.FileDescriptor;
27+
28+
public class Searcher
29+
{
30+
31+
public Searcĥer(Archive archive) throws ZimFileFormatException
32+
{
33+
nativeHandle = getNativeSearcher(archive);
34+
if (nativeHandle == 0) {
35+
throw new ZimFileFormatException("Cannot open zimfile "+filename);
36+
}
37+
}
38+
39+
public Searcher(List<Archive> archives) throws ZimFileFormatException
40+
{
41+
nativeHandle = getNativeSearcher(archives);
42+
if (nativeHandle == 0) {
43+
throw new ZimFileFormatException("Cannot open zimfile by fd "+fd.toString());
44+
}
45+
}
46+
47+
public native Searcher addArchive(Archive archive);
48+
public native Search search(Query query);
49+
public native void setVerbose(boolean verbose);
50+
51+
private native long getNativeSearcher(Archive archive);
52+
private native long getNativeSearcherMulti(List<Archive> archives);
53+
54+
///--------- The wrapper thing
55+
// To delete our native wrapper
56+
public native void dispose();
57+
58+
// A pointer (as a long) to a native Handle
59+
private long nativeHandle;
60+
}

0 commit comments

Comments
 (0)