Skip to content

Commit 0feb520

Browse files
committed
Also patch getIndexSnippet
1 parent 135b49c commit 0feb520

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

Makefile

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ build/lib/libxapian.a : build/lib/libz.a
7373
# Some options coming from https://github.com/xapian/xapian/tree/master/xapian-core/emscripten
7474
# 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
7575
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"
7777
cd xapian-core-*/ ; emmake make install
7878

7979
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
140140
'' \
141141
' std::cerr << "[SNIPPET DEBUG] No stored snippet, generating from content..." << std::endl;' \
142142
' Entry& entry = internal->get_entry();' \
143-
' ' \
143+
'' \
144144
' try {' \
145145
' std::cerr << "[SNIPPET DEBUG] Getting entry item data..." << std::endl;' \
146146
' zim::MyHtmlParser htmlParser;' \
147147
' std::string content = entry.getItem().getData();' \
148148
' std::cerr << "[SNIPPET DEBUG] Got content: " << content.length() << " bytes" << std::endl;' \
149-
' ' \
149+
'' \
150150
' try {' \
151151
' std::cerr << "[SNIPPET DEBUG] Starting HTML parsing..." << std::endl;' \
152152
' 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
158158
' } catch (...) {' \
159159
' std::cerr << "[SNIPPET DEBUG] Caught unknown exception during HTML parsing" << std::endl;' \
160160
' }' \
161-
' ' \
161+
'' \
162162
' std::cerr << "[SNIPPET DEBUG] HTML dump length after parsing: " << htmlParser.dump.length() << " chars" << std::endl;' \
163163
' if (htmlParser.dump.length() > 0) {' \
164164
' std::cerr << "[SNIPPET DEBUG] First 100 chars of dump: " << htmlParser.dump.substr(0, 100) << "..." << std::endl;' \
165165
' }' \
166-
' ' \
166+
'' \
167167
' try {' \
168168
' std::cerr << "[SNIPPET DEBUG] Calling Xapian snippet generation..." << std::endl;' \
169169
' 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
187187
' } catch (...) {' \
188188
' std::cerr << "[SNIPPET DEBUG] Caught unknown exception from Xapian snippet()" << std::endl;' \
189189
' }' \
190-
' ' \
190+
'' \
191191
' std::cerr << "[SNIPPET DEBUG] Falling back to manual snippet extraction" << std::endl;' \
192192
' std::string htmlText = htmlParser.dump;' \
193193
' if (htmlText.empty()) {' \
194194
' std::cerr << "[SNIPPET DEBUG] HTML dump empty, using raw content" << std::endl;' \
195195
' htmlText = content;' \
196196
' }' \
197-
' ' \
197+
'' \
198198
' if (htmlText.length() > 500) {' \
199199
' std::string fallback = htmlText.substr(0, 500) + "...";' \
200200
' 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
220220
' std::cerr << "[SNIPPET DEBUG] Caught unknown exception at top level" << std::endl;' \
221221
' return "";' \
222222
' }' \
223-
> libzim-9.3.0/src/snippet_diagnostic.tmp
223+
'}' \
224+
> libzim-9.3.0/src/snippet_diagnostic.tmp
224225
# Use sed to remove the original getSnippet method completely, then append our diagnostic version
225226
@echo "Replacing getSnippet() method with diagnostic version..."
226227
@sed '/^std::string SearchIterator::getSnippet() const {$$/,/^}$$/d' libzim-9.3.0/src/search_iterator.cpp > libzim-9.3.0/src/search_iterator_temp.cpp
227228
@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
228229
@rm libzim-9.3.0/src/snippet_diagnostic.tmp
229230
@echo "=== DIAGNOSTIC PATCHES APPLIED ==="
230231
@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 ==="
232268
@echo "search.cpp - Headers added: $$(grep -c '#include <set>' libzim-*/src/search.cpp || echo '0')"
233269
@echo "suggestion.cpp - Headers added: $$(grep -c '#include <set>' libzim-*/src/suggestion.cpp || echo '0')"
234270
@echo "search.cpp - Whitelist added: $$(grep -c 'supportedLangs' libzim-*/src/search.cpp || echo '0')"

0 commit comments

Comments
 (0)