Skip to content

Commit 8c3a358

Browse files
authored
Merge pull request #34 from kiwix/search_testing
2 parents 08d59c4 + 15f42f0 commit 8c3a358

17 files changed

Lines changed: 325 additions & 25 deletions

.github/workflows/pull_request.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ name: Pull requests
22

33
on:
44
pull_request:
5+
push:
56
branches:
6-
- '**'
7+
- main
78

89
jobs:
910

lib/src/main/cpp/libzim/search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DISPOSE
3737

3838
METHOD(jobject, getResults, jint start, jint maxResults) {
3939
auto results = THIS->getResults(TO_C(start), TO_C(maxResults));
40-
auto obj = NEW_OBJECT("ork/kiwix/libzim/SearchIterator");
40+
auto obj = NEW_OBJECT("org/kiwix/libzim/SearchIterator");
4141
SET_HANDLE(zim::SearchIterator, obj, results.begin());
4242

4343
// We have to set the nativeHandleEnd but no macro ease our work here.

lib/src/main/cpp/libzim/search_iterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ METHOD0(jboolean, hasNext) {
6464
}
6565

6666
METHOD0(jobject, next) {
67-
(*THIS)++;
6867
zim::Entry entry = **THIS;
68+
(*THIS)++;
6969
return BUILD_WRAPPER("org/kiwix/libzim/Entry", entry);
7070
}
7171

lib/src/main/cpp/libzim/suggestion_iterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ METHOD0(jboolean, hasNext) {
4949
}
5050

5151
METHOD0(jobject, next) {
52-
(*THIS)++;
5352
zim::SuggestionItem item = **THIS;
53+
(*THIS)++;
5454
return BUILD_WRAPPER("org/kiwix/libzim/SuggestionItem", item);
5555
}
5656

lib/src/main/cpp/libzim/suggestion_search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DISPOSE
3737

3838
METHOD(jobject, getResults, jint start, jint maxResults) {
3939
auto results = THIS->getResults(TO_C(start), TO_C(maxResults));
40-
auto obj = NEW_OBJECT("ork/kiwix/libzim/SuggestionIterator");
40+
auto obj = NEW_OBJECT("org/kiwix/libzim/SuggestionIterator");
4141
SET_HANDLE(zim::SuggestionIterator, obj, results.begin());
4242

4343
// We have to set the nativeHandleEnd but no macro ease our work here.

lib/src/test/create_test_zimfiles

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ die()
88

99
cd "$(dirname "$0")"
1010
rm -f small.zim
11-
zimwriterfs --withoutFTIndex \
12-
-w main.html \
13-
-f favicon.png \
14-
-l en \
11+
zimwriterfs -w main.html \
12+
-n "Test" \
13+
-I favicon.png \
14+
-l eng \
1515
-t "Test ZIM file" \
1616
-d "N/A" \
17+
-L "Test File" \
1718
-c "N/A" \
1819
-p "N/A" \
1920
small_zimfile_data \
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.test.libzim;
21+
22+
import org.kiwix.libzim.Query;
23+
24+
public class TestQuery
25+
{
26+
private Query inner;
27+
public Query inner() { return inner; }
28+
public TestQuery(String query) {
29+
inner = new Query(query);
30+
}
31+
32+
public TestQuery setQuery(String query) {
33+
inner.setQuery(query);
34+
return this;
35+
}
36+
37+
public TestQuery setGeorange(float latitude, float longitute, float distance) {
38+
inner.setGeorange(latitude, latitude, distance);
39+
return this;
40+
}
41+
42+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.test.libzim;
21+
22+
import org.kiwix.libzim.Search;
23+
import org.kiwix.libzim.SearchIterator;
24+
25+
public class TestSearch
26+
{
27+
private Search inner;
28+
public TestSearch(Search _inner) { inner = _inner; }
29+
public TestSearchIterator getResults(int start, int maxResults) { return new TestSearchIterator(inner.getResults(start, maxResults)); }
30+
public long getEstimatedMatches() { return inner.getEstimatedMatches(); }
31+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.test.libzim;
21+
22+
import org.kiwix.libzim.SearchIterator;
23+
import java.util.Iterator;
24+
25+
public class TestSearchIterator implements Iterator<TestEntry>
26+
{
27+
private SearchIterator inner;
28+
public TestSearchIterator(SearchIterator _inner) { inner = _inner; }
29+
public String getPath() { return inner.getPath(); }
30+
public String getTitle() { return inner.getTitle(); }
31+
public int getScore() { return inner.getScore(); }
32+
public String getSnippet() { return inner.getSnippet(); }
33+
public int getWordCount() { return inner.getWordCount(); }
34+
public int getFileIndex() { return inner.getFileIndex(); }
35+
public int getSize() { return inner.getSize(); }
36+
public String getZimId() { return inner.getZimId(); }
37+
38+
public boolean hasNext() { return inner.hasNext(); }
39+
public TestEntry next() { return new TestEntry(inner.next()); }
40+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.test.libzim;
21+
22+
import org.kiwix.libzim.Archive;
23+
import org.kiwix.libzim.Searcher;
24+
import org.kiwix.libzim.Search;
25+
import java.util.stream.Stream;
26+
27+
public class TestSearcher
28+
{
29+
private Searcher inner;
30+
public TestSearcher(TestArchive archive) throws Exception
31+
{
32+
inner = new Searcher(archive.inner());
33+
}
34+
35+
public TestSearcher(TestArchive[] archives) throws Exception
36+
{
37+
inner = new Searcher(
38+
Stream.of(archives).map(a -> a.inner()).toArray(Archive[]::new)
39+
);
40+
}
41+
42+
public TestSearcher addArchive(TestArchive archive) {
43+
inner.addArchive(archive.inner());
44+
return this;
45+
}
46+
public TestSearch search(TestQuery query) { return new TestSearch(inner.search(query.inner())); }
47+
public void setVerbose(boolean verbose) { inner.setVerbose(verbose); }
48+
49+
public void dispose() { inner.dispose(); }
50+
}

0 commit comments

Comments
 (0)