@@ -73,7 +73,7 @@ build/lib/libxapian.a : build/lib/libz.a
73
73
# Some options coming from https://github.com/xapian/xapian/tree/master/xapian-core/emscripten
74
74
# cd xapian-core-1.4.18; emconfigure ./configure --prefix=`pwd`/../build "CFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib" "CXXFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib" CPPFLAGS='-DFLINTLOCK_USE_FLOCK' CXXFLAGS='-Oz -s USE_ZLIB=1 -fno-rtti' --disable-backend-honey --disable-backend-inmemory --disable-shared --disable-backend-remote
75
75
cd xapian-core-*/ ; emconfigure ./configure --prefix=`pwd`/../build "CFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib" "CXXFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib" --disable-shared --disable-backend-remote
76
- cd xapian-core-*/ ; emmake make "CFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib -std=c++14" "CXXFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib -std=c++14"
76
+ cd xapian-core-*/ ; emmake make "CFLAGS=-I`pwd`/../build/include -L`pwd`/../build/lib -std=c++14" "CXXFLAGS=" -I`pwd`/../build/include -L`pwd`/../build/lib -std=c++14"
77
77
cd xapian-core-*/ ; emmake make install
78
78
79
79
build/lib/libzim.a : build/lib/liblzma.so build/lib/libz.a build/lib/libzstd.a build/lib/libicudata.so build/lib/libxapian.a
@@ -140,13 +140,13 @@ build/lib/libzim.a : build/lib/liblzma.so build/lib/libz.a build/lib/libzstd.a b
140
140
'' \
141
141
' std::cerr << "[SNIPPET DEBUG] No stored snippet, generating from content..." << std::endl;' \
142
142
' Entry& entry = internal->get_entry();' \
143
- ' ' \
143
+ '' \
144
144
' try {' \
145
145
' std::cerr << "[SNIPPET DEBUG] Getting entry item data..." << std::endl;' \
146
146
' zim::MyHtmlParser htmlParser;' \
147
147
' std::string content = entry.getItem().getData();' \
148
148
' std::cerr << "[SNIPPET DEBUG] Got content: " << content.length() << " bytes" << std::endl;' \
149
- ' ' \
149
+ '' \
150
150
' try {' \
151
151
' std::cerr << "[SNIPPET DEBUG] Starting HTML parsing..." << std::endl;' \
152
152
' htmlParser.parse_html(content, "UTF-8", true);' \
@@ -158,12 +158,12 @@ build/lib/libzim.a : build/lib/liblzma.so build/lib/libz.a build/lib/libzstd.a b
158
158
' } catch (...) {' \
159
159
' std::cerr << "[SNIPPET DEBUG] Caught unknown exception during HTML parsing" << std::endl;' \
160
160
' }' \
161
- ' ' \
161
+ '' \
162
162
' std::cerr << "[SNIPPET DEBUG] HTML dump length after parsing: " << htmlParser.dump.length() << " chars" << std::endl;' \
163
163
' if (htmlParser.dump.length() > 0) {' \
164
164
' std::cerr << "[SNIPPET DEBUG] First 100 chars of dump: " << htmlParser.dump.substr(0, 100) << "..." << std::endl;' \
165
165
' }' \
166
- ' ' \
166
+ '' \
167
167
' try {' \
168
168
' std::cerr << "[SNIPPET DEBUG] Calling Xapian snippet generation..." << std::endl;' \
169
169
' std::cerr << "[SNIPPET DEBUG] MSet pointer valid: " << (internal->mp_mset != nullptr) << std::endl;' \
@@ -187,14 +187,14 @@ build/lib/libzim.a : build/lib/liblzma.so build/lib/libz.a build/lib/libzstd.a b
187
187
' } catch (...) {' \
188
188
' std::cerr << "[SNIPPET DEBUG] Caught unknown exception from Xapian snippet()" << std::endl;' \
189
189
' }' \
190
- ' ' \
190
+ '' \
191
191
' std::cerr << "[SNIPPET DEBUG] Falling back to manual snippet extraction" << std::endl;' \
192
192
' std::string htmlText = htmlParser.dump;' \
193
193
' if (htmlText.empty()) {' \
194
194
' std::cerr << "[SNIPPET DEBUG] HTML dump empty, using raw content" << std::endl;' \
195
195
' htmlText = content;' \
196
196
' }' \
197
- ' ' \
197
+ '' \
198
198
' if (htmlText.length() > 500) {' \
199
199
' std::string fallback = htmlText.substr(0, 500) + "...";' \
200
200
' std::cerr << "[SNIPPET DEBUG] Returning fallback snippet: " << fallback.length() << " chars" << std::endl;' \
@@ -220,15 +220,51 @@ build/lib/libzim.a : build/lib/liblzma.so build/lib/libz.a build/lib/libzstd.a b
220
220
' std::cerr << "[SNIPPET DEBUG] Caught unknown exception at top level" << std::endl;' \
221
221
' return "";' \
222
222
' }' \
223
- > libzim-9.3.0/src/snippet_diagnostic.tmp
223
+ '}' \
224
+ > libzim-9.3.0/src/snippet_diagnostic.tmp
224
225
# Use sed to remove the original getSnippet method completely, then append our diagnostic version
225
226
@echo "Replacing getSnippet() method with diagnostic version..."
226
227
@sed '/^std::string SearchIterator::getSnippet() const {$$/,/^}$$/d' libzim-9.3.0/src/search_iterator.cpp > libzim-9.3.0/src/search_iterator_temp.cpp
227
228
@sed '/^} \/\/ namespace zim$$/i\\n' libzim-9.3.0/src/search_iterator_temp.cpp | sed '/^} \/\/ namespace zim$$/e cat libzim-9.3.0/src/snippet_diagnostic.tmp' > libzim-9.3.0/src/search_iterator.cpp
228
229
@rm libzim-9.3.0/src/snippet_diagnostic.tmp
229
230
@echo "=== DIAGNOSTIC PATCHES APPLIED ==="
230
231
@echo "When you run the test after building, look for [SNIPPET DEBUG] messages in the console"
231
- @echo "=== VERIFYING LIBZIM BUILD ==="
232
+
233
+ @echo "=== APPLYING SUGGESTION ITERATOR DIAGNOSTIC PATCHES ==="
234
+ # Add iostream header for debug output to suggestion_iterator.cpp
235
+ sed -i '/# include "suggestion_iterator.h"/a #include <iostream>' libzim-9.3.0/src/suggestion_iterator.cpp
236
+
237
+ # Replace the simple getIndexSnippet method with a diagnostic version
238
+ sed -i '/^std::string SuggestionIterator::getIndexSnippet() const {$$/,/^}$$/c\
239
+ std::string SuggestionIterator::getIndexSnippet() const {\
240
+ if (! mp_internal) {\
241
+ return "";\
242
+ }\
243
+ \
244
+ try {\
245
+ std::cerr << "[SUGGESTION DEBUG] Calling Xapian snippet for suggestion..." << std::endl;\
246
+ std::string snippet = mp_internal->mp_mset->snippet(getIndexTitle(), 500, mp_internal->mp_internalDb->m_stemmer);\
247
+ std::cerr << "[SUGGESTION DEBUG] Suggestion snippet generated: " << snippet.length() << " chars" << std::endl;\
248
+ if (snippet.length() > 0) {\
249
+ std::cerr << "[SUGGESTION DEBUG] Snippet preview: " << snippet.substr(0, 50) << "..." << std::endl;\
250
+ }\
251
+ return snippet;\
252
+ } catch (const Xapian::Error& e) {\
253
+ std::cerr << "[SUGGESTION DEBUG] Xapian error in snippet generation: " << e.get_description() << std::endl;\
254
+ return "";\
255
+ } catch (const std::exception& e) {\
256
+ std::cerr << "[SUGGESTION DEBUG] Exception in snippet generation: " << e.what() << std::endl;\
257
+ return "";\
258
+ } catch (...) {\
259
+ std::cerr << "[SUGGESTION DEBUG] Unknown exception in snippet generation" << std::endl;\
260
+ return "";\
261
+ }\
262
+ }' libzim-9.3.0/src/suggestion_iterator.cpp
263
+
264
+ @echo "Suggestion iterator patched with detailed exception handling"
265
+ @echo ""
266
+
267
+ @echo "=== VERIFYING LIBZIM BUILD ==="
232
268
@echo "search.cpp - Headers added: $$(grep -c '# include <set>' libzim-*/src/search.cpp || echo '0')"
233
269
@echo "suggestion.cpp - Headers added: $$(grep -c '# include <set>' libzim-*/src/suggestion.cpp || echo '0')"
234
270
@echo "search.cpp - Whitelist added: $$(grep -c 'supportedLangs' libzim-*/src/search.cpp || echo '0')"
0 commit comments