Skip to content

Commit 2566813

Browse files
committed
Attempt to correct compilation errors
1 parent 0cca629 commit 2566813

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

libzim_bindings.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class EntryWrapper{
8484
zim::Entry m_entry;
8585
};
8686

87+
// Forward declaration
88+
class SuggestionSearchWrapper;
89+
8790
// SuggestionSearcher wrapper
8891
class SuggestionSearcherWrapper {
8992
public:
@@ -103,8 +106,9 @@ class SuggestionSearcherWrapper {
103106
// SuggestionSearch wrapper
104107
class SuggestionSearchWrapper {
105108
public:
106-
SuggestionSearchWrapper(zim::SuggestionSearch search)
107-
: search_(search) {}
109+
// Use move constructor to avoid copy issues
110+
SuggestionSearchWrapper(zim::SuggestionSearch&& search)
111+
: search_(std::move(search)) {}
108112

109113
unsigned int getEstimatedMatches() const {
110114
try {
@@ -120,8 +124,16 @@ class SuggestionSearchWrapper {
120124
zim::SuggestionResultSet resultSet = search_.getResults(start, count);
121125
std::vector<EntryWrapper> results;
122126

123-
for (const auto& entry : resultSet) {
124-
results.push_back(EntryWrapper(entry));
127+
// Use the iterator to get entries
128+
for (auto it = resultSet.begin(); it != resultSet.end(); ++it) {
129+
try {
130+
// Use the iterator's getEntry() method
131+
zim::Entry entry = it.getEntry();
132+
results.push_back(EntryWrapper(entry));
133+
} catch (const std::exception& e) {
134+
std::cout << "Error getting entry from suggestion iterator: " << e.what() << std::endl;
135+
// Skip this item and continue
136+
}
125137
}
126138

127139
return results;
@@ -139,7 +151,8 @@ class SuggestionSearchWrapper {
139151
SuggestionSearchWrapper SuggestionSearcherWrapper::suggest(const std::string& query) {
140152
try {
141153
zim::SuggestionSearch search = searcher->suggest(query);
142-
return SuggestionSearchWrapper(search);
154+
// Use move constructor
155+
return SuggestionSearchWrapper(std::move(search));
143156
} catch (const std::exception& e) {
144157
std::cout << "suggest error: " << e.what() << std::endl;
145158
throw;
@@ -180,8 +193,17 @@ std::vector<EntryWrapper> suggest(std::string text, int numResults) {
180193
auto suggestionSearch = suggestionSearcher.suggest(text);
181194
auto resultSet = suggestionSearch.getResults(0, numResults);
182195
std::vector<EntryWrapper> ret;
183-
for(auto entry : resultSet) {
184-
ret.push_back(EntryWrapper(entry));
196+
197+
// Use the iterator to get entries
198+
for (auto it = resultSet.begin(); it != resultSet.end(); ++it) {
199+
try {
200+
// Use the iterator's getEntry() method
201+
zim::Entry entry = it.getEntry();
202+
ret.push_back(EntryWrapper(entry));
203+
} catch (const std::exception& e) {
204+
std::cout << "Error getting entry from suggestion iterator: " << e.what() << std::endl;
205+
// Skip this item and continue
206+
}
185207
}
186208
return ret;
187209
} catch(const std::exception& e) {

0 commit comments

Comments
 (0)