From 030b2f95f5aa1c6caf107acbcf69aeed82384176 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 21 Dec 2022 15:52:52 +0100 Subject: [PATCH] [WIP] Add search wrapping --- lib/src/main/java/org/kiwix/libzim/Query.java | 34 +++++++++++ .../main/java/org/kiwix/libzim/Search.java | 35 +++++++++++ .../java/org/kiwix/libzim/SearchIterator.java | 44 ++++++++++++++ .../org/kiwix/libzim/SearchResultSet.java | 35 +++++++++++ .../main/java/org/kiwix/libzim/Searcher.java | 60 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 lib/src/main/java/org/kiwix/libzim/Query.java create mode 100644 lib/src/main/java/org/kiwix/libzim/Search.java create mode 100644 lib/src/main/java/org/kiwix/libzim/SearchIterator.java create mode 100644 lib/src/main/java/org/kiwix/libzim/SearchResultSet.java create mode 100644 lib/src/main/java/org/kiwix/libzim/Searcher.java diff --git a/lib/src/main/java/org/kiwix/libzim/Query.java b/lib/src/main/java/org/kiwix/libzim/Query.java new file mode 100644 index 0000000..30eb781 --- /dev/null +++ b/lib/src/main/java/org/kiwix/libzim/Query.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.libzim; + +public class Query +{ + public Query(string query); + public native Query setQuery(string query); + public native Query setGeorange(float latitude, float longitute, float distance); + +///--------- The wrapper thing + // To delete our native wrapper + public native void dispose(); + + // A pointer (as a long) to a native Handle + private long nativeHandle; +} diff --git a/lib/src/main/java/org/kiwix/libzim/Search.java b/lib/src/main/java/org/kiwix/libzim/Search.java new file mode 100644 index 0000000..e3c62b8 --- /dev/null +++ b/lib/src/main/java/org/kiwix/libzim/Search.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.libzim; + +import org.kiwix.libzim.SearchResultSet; + +public class Search +{ + public native SearchResultSet getResults(int start, int maxResults); + public native long getEstimatedMatches(); + +///--------- The wrapper thing + // To delete our native wrapper + public native void dispose(); + + // A pointer (as a long) to a native Handle + private long nativeHandle; +} diff --git a/lib/src/main/java/org/kiwix/libzim/SearchIterator.java b/lib/src/main/java/org/kiwix/libzim/SearchIterator.java new file mode 100644 index 0000000..ac93003 --- /dev/null +++ b/lib/src/main/java/org/kiwix/libzim/SearchIterator.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.libzim; + +import org.kiwix.libzim.SearchIterator; + +public class SearchIterator implement Iterator +{ + public native string getPath(); + public native string getTitle(); + public native int getScore(); + public native string getSnippet(); + public native int getWordCount(); + public native int getFileIndex(); + public native int size(); + public native string getZimId(); + + public native boolean hasNext(); + public native Entry next(); + +///--------- The wrapper thing + // To delete our native wrapper + public native void dispose(); + + // A pointer (as a long) to a native Handle + private long nativeHandle; +} diff --git a/lib/src/main/java/org/kiwix/libzim/SearchResultSet.java b/lib/src/main/java/org/kiwix/libzim/SearchResultSet.java new file mode 100644 index 0000000..27c9833 --- /dev/null +++ b/lib/src/main/java/org/kiwix/libzim/SearchResultSet.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.libzim; + +import org.kiwix.libzim.SearchIterator; + +public class SearchResultSet +{ + public native SearchIterator begin(); + public native long size(); + +///--------- The wrapper thing + // To delete our native wrapper + public native void dispose(); + + // A pointer (as a long) to a native Handle + private long nativeHandle; +} diff --git a/lib/src/main/java/org/kiwix/libzim/Searcher.java b/lib/src/main/java/org/kiwix/libzim/Searcher.java new file mode 100644 index 0000000..b1158a3 --- /dev/null +++ b/lib/src/main/java/org/kiwix/libzim/Searcher.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.libzim; + +import org.kiwix.libzim.ZimFileFormatException; +import org.kiwix.libzim.Archive; +import org.kiwix.libzim.Search; +import org.kiwix.libzim.Query; +import java.io.FileDescriptor; + +public class Searcher +{ + + public Searcĥer(Archive archive) throws ZimFileFormatException + { + nativeHandle = getNativeSearcher(archive); + if (nativeHandle == 0) { + throw new ZimFileFormatException("Cannot open zimfile "+filename); + } + } + + public Searcher(List archives) throws ZimFileFormatException + { + nativeHandle = getNativeSearcher(archives); + if (nativeHandle == 0) { + throw new ZimFileFormatException("Cannot open zimfile by fd "+fd.toString()); + } + } + + public native Searcher addArchive(Archive archive); + public native Search search(Query query); + public native void setVerbose(boolean verbose); + + private native long getNativeSearcher(Archive archive); + private native long getNativeSearcherMulti(List archives); + +///--------- The wrapper thing + // To delete our native wrapper + public native void dispose(); + + // A pointer (as a long) to a native Handle + private long nativeHandle; +}