Skip to content

Commit 751c876

Browse files
committed
Try new query constructor approach
1 parent f1d65b4 commit 751c876

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

libzim_bindings.cpp

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class SuggestionSearchWrapper {
150150
// Implement the suggest method (needs to be after SuggestionSearchWrapper definition)
151151
SuggestionSearchWrapper SuggestionSearcherWrapper::suggest(const std::string& query) {
152152
try {
153-
zim::SuggestionSearch search = searcher->suggest(query);
153+
// FIX: Use search() method as documented, not suggest()
154+
zim::SuggestionSearch search = searcher->search(query);
154155
// Use move constructor
155156
return SuggestionSearchWrapper(std::move(search));
156157
} catch (const std::exception& e) {
@@ -173,24 +174,60 @@ std::unique_ptr<EntryWrapper> getEntryByPath(std::string url) {
173174
}
174175
}
175176

176-
// Search for a text, and returns the path of the first result
177+
// CORRECTED: Search for a text using proper Query API
177178
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>();
185221
}
186-
return ret;
187222
}
188223

189-
// Suggestion search function (alternative to class-based approach)
224+
// CORRECTED: Suggestion search function using proper API
190225
std::vector<EntryWrapper> suggest(std::string text, int numResults) {
191226
try {
192227
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);
194231
auto resultSet = suggestionSearch.getResults(0, numResults);
195232
std::vector<EntryWrapper> ret;
196233

@@ -218,6 +255,7 @@ EMSCRIPTEN_BINDINGS(libzim_module) {
218255
emscripten::function("getEntryByPath", &getEntryByPath);
219256
emscripten::function("getArticleCount", &getArticleCount);
220257
emscripten::function("search", &search);
258+
emscripten::function("searchWithLanguage", &searchWithLanguage);
221259
emscripten::function("suggest", &suggest);
222260
emscripten::register_vector<char>("vector<char>");
223261
emscripten::register_vector<EntryWrapper>("vector(EntryWrapper)");
@@ -243,4 +281,4 @@ EMSCRIPTEN_BINDINGS(libzim_module) {
243281
.function("getEstimatedMatches", &SuggestionSearchWrapper::getEstimatedMatches)
244282
.function("getResults", &SuggestionSearchWrapper::getResults)
245283
;
246-
}
284+
}

0 commit comments

Comments
 (0)