@@ -84,6 +84,9 @@ class EntryWrapper{
84
84
zim::Entry m_entry;
85
85
};
86
86
87
+ // Forward declaration
88
+ class SuggestionSearchWrapper ;
89
+
87
90
// SuggestionSearcher wrapper
88
91
class SuggestionSearcherWrapper {
89
92
public:
@@ -103,8 +106,9 @@ class SuggestionSearcherWrapper {
103
106
// SuggestionSearch wrapper
104
107
class SuggestionSearchWrapper {
105
108
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)) {}
108
112
109
113
unsigned int getEstimatedMatches () const {
110
114
try {
@@ -120,8 +124,16 @@ class SuggestionSearchWrapper {
120
124
zim::SuggestionResultSet resultSet = search_.getResults (start, count);
121
125
std::vector<EntryWrapper> results;
122
126
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
+ }
125
137
}
126
138
127
139
return results;
@@ -139,7 +151,8 @@ class SuggestionSearchWrapper {
139
151
SuggestionSearchWrapper SuggestionSearcherWrapper::suggest (const std::string& query) {
140
152
try {
141
153
zim::SuggestionSearch search = searcher->suggest (query);
142
- return SuggestionSearchWrapper (search);
154
+ // Use move constructor
155
+ return SuggestionSearchWrapper (std::move (search));
143
156
} catch (const std::exception& e) {
144
157
std::cout << " suggest error: " << e.what () << std::endl;
145
158
throw ;
@@ -180,8 +193,17 @@ std::vector<EntryWrapper> suggest(std::string text, int numResults) {
180
193
auto suggestionSearch = suggestionSearcher.suggest (text);
181
194
auto resultSet = suggestionSearch.getResults (0 , numResults);
182
195
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
+ }
185
207
}
186
208
return ret;
187
209
} catch (const std::exception& e) {
0 commit comments