mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-09 07:08:49 -04:00
[WIP] Add search wrapping
This commit is contained in:
parent
f9f64991cd
commit
030b2f95f5
34
lib/src/main/java/org/kiwix/libzim/Query.java
Normal file
34
lib/src/main/java/org/kiwix/libzim/Query.java
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* 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;
|
||||
}
|
35
lib/src/main/java/org/kiwix/libzim/Search.java
Normal file
35
lib/src/main/java/org/kiwix/libzim/Search.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* 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;
|
||||
}
|
44
lib/src/main/java/org/kiwix/libzim/SearchIterator.java
Normal file
44
lib/src/main/java/org/kiwix/libzim/SearchIterator.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* 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<Entry>
|
||||
{
|
||||
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;
|
||||
}
|
35
lib/src/main/java/org/kiwix/libzim/SearchResultSet.java
Normal file
35
lib/src/main/java/org/kiwix/libzim/SearchResultSet.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* 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;
|
||||
}
|
60
lib/src/main/java/org/kiwix/libzim/Searcher.java
Normal file
60
lib/src/main/java/org/kiwix/libzim/Searcher.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* 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<Archive> 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<Archive> 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user