From cb287756a5bafc9882d3ad6bda97049b544ebc7c Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 13 Feb 2013 14:01:53 -0600 Subject: [PATCH] Fix FTBFS with CLucene v2 (cherry picked from commit 9e9e51c2eb3b7bb64e1d68be0d42bae3a4f24f79) --- bibletime/backend/cswordmoduleinfo.cpp | 44 +++++++++++++++++++++++++- clucene.m4 | 18 +++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/bibletime/backend/cswordmoduleinfo.cpp b/bibletime/backend/cswordmoduleinfo.cpp index ecb03d0..e03d519 100644 --- a/bibletime/backend/cswordmoduleinfo.cpp +++ b/bibletime/backend/cswordmoduleinfo.cpp @@ -48,9 +48,11 @@ //Lucence includes #include +#ifndef CLUCENE_V2 #include #include #include +#endif // CLUCENE_V2 //Increment this, if the index format changes //Then indices on the user's systems will be rebuilt @@ -256,7 +258,9 @@ void CSwordModuleInfo::buildIndex() { util::scoped_ptr writer( new lucene::index::IndexWriter(index.ascii(), &an, true) ); //always create a new index writer->setMaxFieldLength(BT_MAX_LUCENE_FIELD_LENGTH); writer->setUseCompoundFile(true); //merge segments into a single file +#ifndef CLUCENE_V2 writer->setMinMergeDocs(1000); +#endif // CLUCENE_V2 *m_module = sword::TOP; unsigned long verseLowIndex = m_module->Index(); @@ -304,13 +308,23 @@ void CSwordModuleInfo::buildIndex() { //index the key lucene_utf8towcs(wcharBuffer, key->getText(), BT_MAX_LUCENE_FIELD_LENGTH); +#ifdef CLUCENE_V2 + lucene::document::Field field1(_T("key"), wcharBuffer, lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO); + doc->add(field1); +#else // CLUCENE_V2 doc->add(*lucene::document::Field::UnIndexed(_T("key"), wcharBuffer)); +#endif // CLUCENE_V2 // index the main text //at this point we have to make sure we disabled the strongs and the other options //so the plain filters won't include the numbers somehow. lucene_utf8towcs(wcharBuffer, (const char*) textBuffer.append(m_module->StripText()), BT_MAX_LUCENE_FIELD_LENGTH); +#ifdef CLUCENE_V2 + lucene::document::Field field2(_T("key"), wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED); + doc->add(field2); +#else // CLUCENE_V2 doc->add(*lucene::document::Field::UnStored(_T("content"), wcharBuffer)); +#endif // CLUCENE_V2 textBuffer.resize(0); //clean up // index attributes @@ -321,7 +335,12 @@ void CSwordModuleInfo::buildIndex() { attListI != m_module->getEntryAttributes()["Footnote"].end(); attListI++) { lucene_utf8towcs(wcharBuffer, attListI->second["body"], BT_MAX_LUCENE_FIELD_LENGTH); +#ifdef CLUCENE_V2 + lucene::document::Field field3(_T("footnote"), wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED); + doc->add(field3); +#else // CLUCENE_V2 doc->add(*lucene::document::Field::UnStored(_T("footnote"), wcharBuffer)); +#endif // CLUCENE_V2 } // for attListI // Headings @@ -329,7 +348,12 @@ void CSwordModuleInfo::buildIndex() { attValueI != m_module->getEntryAttributes()["Heading"]["Preverse"].end(); attValueI++) { lucene_utf8towcs(wcharBuffer, attValueI->second, BT_MAX_LUCENE_FIELD_LENGTH); +#ifdef CLUCENE_V2 + lucene::document::Field field4(_T("heading"), wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED); + doc->add(field4); +#else // CLUCENE_V2 doc->add(*lucene::document::Field::UnStored(_T("heading"), wcharBuffer)); +#endif // CLUCENE_V2 } // for attValueI // Strongs/Morphs @@ -339,12 +363,22 @@ void CSwordModuleInfo::buildIndex() { // for each attribute if (attListI->second["LemmaClass"] == "strong") { lucene_utf8towcs(wcharBuffer, attListI->second["Lemma"], BT_MAX_LUCENE_FIELD_LENGTH); +#ifdef CLUCENE_V2 + lucene::document::Field field5(_T("strong"), wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED); + doc->add(field5); +#else // CLUCENE_V2 doc->add(*lucene::document::Field::UnStored(_T("strong"), wcharBuffer)); +#endif // CLUCENE_V2 //qWarning("Adding strong %s", attListI->second["Lemma"].c_str()); } if (attListI->second.find("Morph") != attListI->second.end()) { lucene_utf8towcs(wcharBuffer, attListI->second["Morph"], BT_MAX_LUCENE_FIELD_LENGTH); +#ifdef CLUCENE_V2 + lucene::document::Field field6(_T("morph"), wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED); + doc->add(field6); +#else // CLUCENE_V2 doc->add(*lucene::document::Field::UnStored(_T("morph"), wcharBuffer)); +#endif // CLUCENE_V2 } } // for attListI @@ -409,7 +443,11 @@ const bool CSwordModuleInfo::searchIndexed(const TQString& searchedText, sword:: lucene_utf8towcs(wcharBuffer, searchedText.utf8(), BT_MAX_LUCENE_FIELD_LENGTH); util::scoped_ptr q( lucene::queryParser::QueryParser::parse(wcharBuffer, _T("content"), &analyzer) ); - util::scoped_ptr h( searcher.search(q, lucene::search::Sort::INDEXORDER) ); +#ifdef CLUCENE_V2 + util::scoped_ptr h( searcher.search(q, lucene::search::Sort::INDEXORDER()) ); +#else // CLUCENE_V2 + util::scoped_ptr h( searcher.search(q, lucene::search::Sort::INDEXORDER) ); +#endif // CLUCENE_V2 const bool useScope = (scope.Count() > 0); // const bool isVerseModule = (type() == CSwordModuleInfo::Bible) || (type() == CSwordModuleInfo::Commentary); @@ -418,7 +456,11 @@ const bool CSwordModuleInfo::searchIndexed(const TQString& searchedText, sword:: util::scoped_ptr swKey( module()->CreateKey() ); +#ifdef CLUCENE_V2 + for (unsigned int i = 0; i < h->length(); ++i) { +#else // CLUCENE_V2 for (int i = 0; i < h->length(); ++i) { +#endif // CLUCENE_V2 doc = &h->doc(i); lucene_wcstoutf8(utfBuffer, doc->get(_T("key")), BT_MAX_LUCENE_FIELD_LENGTH); diff --git a/clucene.m4 b/clucene.m4 index 09817d8..e643e75 100644 --- a/clucene.m4 +++ b/clucene.m4 @@ -28,7 +28,8 @@ AC_ARG_ENABLE(static-clucene, dnl try to find CLucene library files AC_MSG_CHECKING([for CLucene library files]) -ac_clucene_library_dirs="$ac_clucene_dir/lib $exec_prefix/lib $prefix/lib /usr/lib /usr/lib64 /usr/local/lib" +clucene_multiarch_libs="/usr/lib/`uname -m`-linux-gnu" +ac_clucene_library_dirs="$ac_clucene_dir/lib $exec_prefix/lib $prefix/lib /usr/lib /usr/lib64 /usr/local/lib $clucene_multiarch_libs" if test "x$ac_static_clucene" = "xYES"; then SEARCH_LIBS="libclucene.a"; @@ -40,13 +41,24 @@ fi AC_CACHE_VAL(ac_cv_clucene_libdir, AC_FIND_FILE($SEARCH_LIBS, $ac_clucene_library_dirs, ac_cv_clucene_libdir)) if test "x$ac_cv_clucene_libdir" = "xNO"; then - AC_MSG_ERROR(CLucene library not found. Try to use configure with --with-clucene-dir=/path/to/clucene); + AC_MSG_CHECKING([for CLucene 2.x library files]) + SEARCH_LIBS="libclucene-shared.so libclucene-shared.so.1"; + AC_CACHE_VAL(ac_cv_clucene2_libdir, AC_FIND_FILE($SEARCH_LIBS, $ac_clucene_library_dirs, ac_cv_clucene_libdir)) + + if test "x$ac_cv_clucene2_libdir" = "xNO"; then + AC_MSG_ERROR(CLucene library not found. Try to use configure with --with-clucene-dir=/path/to/clucene); + fi fi if test "x$ac_static_clucene" = "xYES"; then LIB_CLUCENE="$ac_cv_clucene_libdir/libclucene.a"; else - LIB_CLUCENE="-lclucene"; + if test "x$ac_cv_clucene2_libdir" = "xNO"; then + LIB_CLUCENE="-lclucene"; + else + CXXFLAGS="$CXXFLAGS -DCLUCENE_V2" + LIB_CLUCENE="-lclucene-shared"; + fi fi AC_SUBST(CLUCENE_LIBRARY_PATH)