@@ -150,7 +150,8 @@ class SuggestionSearchWrapper {
150
150
// Implement the suggest method (needs to be after SuggestionSearchWrapper definition)
151
151
SuggestionSearchWrapper SuggestionSearcherWrapper::suggest (const std::string& query) {
152
152
try {
153
- zim::SuggestionSearch search = searcher->suggest (query);
153
+ // FIX: Use search() method as documented, not suggest()
154
+ zim::SuggestionSearch search = searcher->search (query);
154
155
// Use move constructor
155
156
return SuggestionSearchWrapper (std::move (search));
156
157
} catch (const std::exception& e) {
@@ -173,24 +174,60 @@ std::unique_ptr<EntryWrapper> getEntryByPath(std::string url) {
173
174
}
174
175
}
175
176
176
- // Search for a text, and returns the path of the first result
177
+ // CORRECTED: Search for a text using proper Query API
177
178
std::vector<EntryWrapper> search (std::string text, int numResults) {
178
- auto searcher = zim::Searcher (*g_archive);
179
- auto query = zim::Query (text);
180
- auto search = searcher.search (query);
181
- auto searchResultSet = search.getResults (0 , numResults);
182
- std::vector<EntryWrapper> ret;
183
- for (auto entry:searchResultSet) {
184
- ret.push_back (EntryWrapper (entry));
179
+ try {
180
+ auto searcher = zim::Searcher (*g_archive);
181
+
182
+ // FIX: Use proper Query construction
183
+ zim::Query query; // Create empty query first
184
+ query.setQuery (text); // Then set the query text
185
+
186
+ auto search = searcher.search (query);
187
+ auto searchResultSet = search.getResults (0 , numResults);
188
+ std::vector<EntryWrapper> ret;
189
+ for (auto entry:searchResultSet) {
190
+ ret.push_back (EntryWrapper (entry));
191
+ }
192
+ return ret;
193
+ } catch (const std::exception& e) {
194
+ std::cout << " Search error: " << e.what () << std::endl;
195
+ return std::vector<EntryWrapper>();
196
+ }
197
+ }
198
+
199
+ // CORRECTED: Enhanced search with language control
200
+ std::vector<EntryWrapper> searchWithLanguage (std::string text, int numResults, std::string language = " " ) {
201
+ try {
202
+ auto searcher = zim::Searcher (*g_archive);
203
+ zim::Query query;
204
+
205
+ // Set the query text using proper API
206
+ query.setQuery (text);
207
+
208
+ // TODO: Add language control if libzim supports it
209
+ // This might require additional Query methods or Searcher configuration
210
+
211
+ auto search = searcher.search (query);
212
+ auto searchResultSet = search.getResults (0 , numResults);
213
+ std::vector<EntryWrapper> ret;
214
+ for (auto entry:searchResultSet) {
215
+ ret.push_back (EntryWrapper (entry));
216
+ }
217
+ return ret;
218
+ } catch (const std::exception& e) {
219
+ std::cout << " Search with language error: " << e.what () << std::endl;
220
+ return std::vector<EntryWrapper>();
185
221
}
186
- return ret;
187
222
}
188
223
189
- // Suggestion search function (alternative to class-based approach)
224
+ // CORRECTED: Suggestion search function using proper API
190
225
std::vector<EntryWrapper> suggest (std::string text, int numResults) {
191
226
try {
192
227
auto suggestionSearcher = zim::SuggestionSearcher (*g_archive);
193
- auto suggestionSearch = suggestionSearcher.suggest (text);
228
+
229
+ // FIX: Use search() method as documented
230
+ auto suggestionSearch = suggestionSearcher.search (text);
194
231
auto resultSet = suggestionSearch.getResults (0 , numResults);
195
232
std::vector<EntryWrapper> ret;
196
233
@@ -218,6 +255,7 @@ EMSCRIPTEN_BINDINGS(libzim_module) {
218
255
emscripten::function (" getEntryByPath" , &getEntryByPath);
219
256
emscripten::function (" getArticleCount" , &getArticleCount);
220
257
emscripten::function (" search" , &search);
258
+ emscripten::function (" searchWithLanguage" , &searchWithLanguage);
221
259
emscripten::function (" suggest" , &suggest);
222
260
emscripten::register_vector<char >(" vector<char>" );
223
261
emscripten::register_vector<EntryWrapper>(" vector(EntryWrapper)" );
@@ -243,4 +281,4 @@ EMSCRIPTEN_BINDINGS(libzim_module) {
243
281
.function (" getEstimatedMatches" , &SuggestionSearchWrapper::getEstimatedMatches)
244
282
.function (" getResults" , &SuggestionSearchWrapper::getResults)
245
283
;
246
- }
284
+ }
0 commit comments