[WIP] Add search wrapping

This commit is contained in:
Matthieu Gautier 2022-12-21 15:52:52 +01:00
parent f9f64991cd
commit 030b2f95f5
5 changed files with 208 additions and 0 deletions

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}