[sword-svn] r1717 - in trunk: include lib/bcppmake src/modules
src/modules/filters src/modules/texts/rawtext
src/modules/texts/ztext
scribe at crosswire.org
scribe at crosswire.org
Thu Feb 10 07:44:59 MST 2005
Author: scribe
Date: 2005-02-10 07:44:58 -0700 (Thu, 10 Feb 2005)
New Revision: 1717
Modified:
trunk/include/rawtext.h
trunk/include/swmodule.h
trunk/include/ztext.h
trunk/lib/bcppmake/libsword.bpr
trunk/src/modules/filters/osisheadings.cpp
trunk/src/modules/filters/osisstrongs.cpp
trunk/src/modules/swmodule.cpp
trunk/src/modules/texts/rawtext/rawtext.cpp
trunk/src/modules/texts/ztext/ztext.cpp
Log:
Fixed logic bug in osisheadings.cpp
Fixed overrun bug in osisstrongs.cpp (Mark 1:9 KJV) Probably markup error, but shouldn't overrun.
Generalized and moved CLucene code from drivers, to SWModule so all modules can be indexed.
Moved CLucene to its own search type -4 instead of replacing -2
Modified: trunk/include/rawtext.h
===================================================================
--- trunk/include/rawtext.h 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/include/rawtext.h 2005-02-10 14:44:58 UTC (rev 1717)
@@ -56,13 +56,14 @@
virtual SWBuf &getRawEntryBuf();
virtual void increment(int steps = 1);
virtual void decrement(int steps = 1) { increment(-steps); }
+#ifndef USELUCENE
virtual signed char createSearchFramework(
void (*percent) (char, void *) = &nullPercent,
void *percentUserData = 0);
virtual void deleteSearchFramework();
virtual bool hasSearchFramework() { return true; }
virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
-
+#endif
// write interface ----------------------------
virtual bool isWritable() { return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & O_RDWR) == O_RDWR)); }
static char createModule(const char *path) { return RawVerse::createModule(path); }
Modified: trunk/include/swmodule.h
===================================================================
--- trunk/include/swmodule.h 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/include/swmodule.h 2005-02-10 14:44:58 UTC (rev 1717)
@@ -219,7 +219,7 @@
/**
* Sets/gets module KeyText
- *
+ * @deprecated Use getKeyText/setKey
* @param ikeytext Value which to set keytext; [0]-only get
* @return pointer to keytext
*/
@@ -228,6 +228,16 @@
return *getKey();
}
+ /**
+ * gets the key text for the module.
+ * do we really need this?
+ */
+
+ virtual const char *getKeyText() const {
+ return *getKey();
+ }
+
+
virtual long Index() const { return entryIndex; }
virtual long Index(long iindex) { entryIndex = iindex; return entryIndex; }
@@ -597,6 +607,15 @@
// OPERATORS -----------------------------------------------------------------
+
+#ifdef USELUCENE
+ virtual signed char createSearchFramework(
+ void (*percent) (char, void *) = &nullPercent,
+ void *percentUserData = 0);
+ virtual void deleteSearchFramework();
+ virtual bool hasSearchFramework() { return true; }
+#endif
+
SWMODULE_OPERATORS
};
Modified: trunk/include/ztext.h
===================================================================
--- trunk/include/ztext.h 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/include/ztext.h 2005-02-10 14:44:58 UTC (rev 1717)
@@ -83,14 +83,6 @@
virtual void flush() { flushCache(); }
// end swcacher interface ----------------------
- virtual signed char createSearchFramework(
- void (*percent) (char, void *) = &nullPercent,
- void *percentUserData = 0);
- virtual void deleteSearchFramework();
- virtual bool hasSearchFramework() { return true; }
- virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
-
-
SWMODULE_OPERATORS
};
Modified: trunk/lib/bcppmake/libsword.bpr
===================================================================
--- trunk/lib/bcppmake/libsword.bpr 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/lib/bcppmake/libsword.bpr 2005-02-10 14:44:58 UTC (rev 1717)
@@ -115,7 +115,7 @@
<PATHRC value=".;"/>
<PATHASM value=".;"/>
<LINKER value="TLib"/>
- <USERDEFINES value="_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG;USELUCENE;LUCENE_DISABLE_MULTITHREADING;_WIN32;HAVE_DIRENT"/>
+ <USERDEFINES value="_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;LUCENE_DISABLE_MULTITHREADING;_WIN32;HAVE_DIRENT"/>
<SYSDEFINES value="NO_STRICT"/>
<MAINSOURCE value="libsword.bpf"/>
<INCLUDEPATH value="..\..\src\utilfuns\zlib;..\..\src\modules\lexdict\zld;..\..\src\modules\lexdict\rawld4;..\..\src\modules\comments\zcom;..\..\src\modules\genbook\rawgenbook;..\..\src\modules\genbook;..\..\src\modules\texts\ztext;..\..\src\modules\texts\rawtext;..\..\src\modules\texts;..\..\src\modules\lexdict\rawld;..\..\src\modules\lexdict;..\..\src\modules\filters;..\..\src\modules\common;..\..\src\modules\comments\rawfiles;..\..\src\modules\comments\rawcom;..\..\src\modules\comments\hrefcom;..\..\src\modules\comments;..\..\src\modules;..\..\src\frontend;..\..\src\utilfuns;..\..\src\mgr;..\..\src\keys;..\..\..\icu-sword\source\common;..\..\apps\windoze\CBuilder5\InstallMgr\curl\include;..\..\include;$(BCB)\include;$(BCB)\include\vcl;..\..\..\icu-sword\source\i18n;..\..\..\biblecs\clucene\src"/>
@@ -139,9 +139,9 @@
-I$(BCB)\include -I$(BCB)\include\vcl -I..\..\..\icu-sword\source\i18n
-src_suffix cpp -D_ICU_ -D_ICUSWORD_ -DUSBINARY -D_DEBUG
-DU_HAVE_PLACEMENT_NEW=0 -boa"/>
- <CFLAG1 value="-vGc -vGt -vGd -Od -Vx -X- -r- -a8 -b- -k -y -v -vi- -c -tW -tWM"/>
- <PFLAGS value="-$Y+ -$W -$O- -v -JPHNE -M"/>
- <AFLAGS value="/mx /w2 /zi"/>
+ <CFLAG1 value="-O2 -Vx -X- -a8 -b- -k- -vi -c -tW -tWM"/>
+ <PFLAGS value="-$Y- -$L- -$D- -v -JPHNE -M"/>
+ <AFLAGS value="/mx /w2 /zn"/>
<LFLAGS value="/P512"/>
</OPTIONS>
<LINKER>
@@ -211,20 +211,22 @@
Item0=$(BCB)\source\vcl
[HistoryLists\hlConditionals]
-Count=13
-Item0=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG;USELUCENE;LUCENE_DISABLE_MULTITHREADING;_WIN32;HAVE_DIRENT
-Item1=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG;USELUCENE
-Item2=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG
-Item3=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0
-Item4=_ICU_;_ICUSWORD_;USBINARY;_DEBUG;U_HAVE_PLACEMENT_NEW=0
-Item5=_ICU_;_ICUSWORD_;USBINARY;_DEBUG
-Item6=_ICU_;_ICUSWORD_;USBINARY
-Item7=_ICU_;_ICUSWORD_;USBINARY;CURLAVAILABLE;_DEBUG
-Item8=_ICU_;_ICUSWORD_;USBINARY;CURLAVAILABLE
-Item9=;USBINARY;_DEBUG
-Item10=_ICU_;_ICUSWORD_
-Item11=_ICU_;_ICUSWORD_;_DEBUG
-Item12=_DEBUG
+Count=15
+Item0=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;LUCENE_DISABLE_MULTITHREADING;_WIN32;HAVE_DIRENT
+Item1=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;LUCENE_DISABLE_MULTITHREADING;_WIN32;HAVE_DIRENT;_DEBUG
+Item2=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG;USELUCENE;LUCENE_DISABLE_MULTITHREADING;_WIN32;HAVE_DIRENT
+Item3=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG;USELUCENE
+Item4=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;_DEBUG
+Item5=_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0
+Item6=_ICU_;_ICUSWORD_;USBINARY;_DEBUG;U_HAVE_PLACEMENT_NEW=0
+Item7=_ICU_;_ICUSWORD_;USBINARY;_DEBUG
+Item8=_ICU_;_ICUSWORD_;USBINARY
+Item9=_ICU_;_ICUSWORD_;USBINARY;CURLAVAILABLE;_DEBUG
+Item10=_ICU_;_ICUSWORD_;USBINARY;CURLAVAILABLE
+Item11=;USBINARY;_DEBUG
+Item12=_ICU_;_ICUSWORD_
+Item13=_ICU_;_ICUSWORD_;_DEBUG
+Item14=_DEBUG
[HistoryLists\hlFinalOutputDir]
Count=3
@@ -253,7 +255,7 @@
[Compiler]
ShowInfoMsgs=0
LinkDebugVcl=0
-LinkCGLIB=1
+LinkCGLIB=0
[Language]
ActiveLang=
Modified: trunk/src/modules/filters/osisheadings.cpp
===================================================================
--- trunk/src/modules/filters/osisheadings.cpp 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/src/modules/filters/osisheadings.cpp 2005-02-10 14:44:58 UTC (rev 1717)
@@ -83,8 +83,7 @@
continue;
}
if (hide && tag.isEndTag()) {
- SWBuf subType = startTag.getAttribute("subType");
- if (module->isProcessEntryAttributes() && (option || (subType != "x-Section"))) {
+ if (module->isProcessEntryAttributes() && (option || (!preverse))) {
if (preverse) {
sprintf(buf, "%i", pvHeaderNum++);
module->getEntryAttributes()["Heading"]["Preverse"][buf] = header;
Modified: trunk/src/modules/filters/osisstrongs.cpp
===================================================================
--- trunk/src/modules/filters/osisstrongs.cpp 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/src/modules/filters/osisstrongs.cpp 2005-02-10 14:44:58 UTC (rev 1717)
@@ -33,7 +33,7 @@
char OSISStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
- char token[2048]; // cheese. Fix.
+ char token[2112]; // cheese. Fix.
int tokpos = 0;
bool intoken = false;
bool lastspace = false;
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/src/modules/swmodule.cpp 2005-02-10 14:44:58 UTC (rev 1717)
@@ -9,10 +9,18 @@
#include <regex.h> // GNU
#include <swfilter.h>
#include <versekey.h> // KLUDGE for Search
+#include <filemgr.h>
#ifndef _MSC_VER
#include <iostream>
#endif
+#ifdef USELUCENE
+#include <CLucene.h>
+using namespace lucene::search;
+using namespace lucene::queryParser;
+#endif
+
+
SWORD_NAMESPACE_START
SWDisplay SWModule::rawdisp;
@@ -366,6 +374,7 @@
* -1 - phrase
* -2 - multiword
* -3 - entryAttrib (eg. Word//Strongs/G1234/)
+ * -4 - clucene
* flags - options flags for search
* justCheckIfSupported - if set, don't search, only tell if this
* function supports requested search.
@@ -377,8 +386,20 @@
listkey.ClearList();
+#ifdef USELUCENE
+ SWBuf target = getConfigEntry("AbsoluteDataPath");
+ char ch = target.c_str()[strlen(target.c_str())-1];
+ if ((ch != '/') && (ch != '\\'))
+ target.append('/');
+ target.append("lucene");
+#endif
if (justCheckIfSupported) {
*justCheckIfSupported = (searchType >= -3);
+#ifdef USELUCENE
+ if ((searchType == -4) && (IndexReader::indexExists(target.c_str()))) {
+ *justCheckIfSupported = true;
+ }
+#endif
return listkey;
}
@@ -432,6 +453,73 @@
}
(*percent)(++perc, percentUserData);
+
+
+#ifdef USELUCENE
+ if (searchType == -4) { // lucene
+ // test to see if our scope for this search is bounded by a
+ // VerseKey
+ VerseKey *testKeyType = 0, vk;
+ SWTRY {
+ testKeyType = SWDYNAMIC_CAST(VerseKey, ((scope)?scope:key));
+ }
+ SWCATCH ( ... ) {}
+ // if we don't have a VerseKey * decendant we can't handle
+ // because of scope.
+ // In the future, add bool SWKey::isValid(const char *tryString);
+ // For now just drop back to multiword unindexed
+ if (!testKeyType) {
+ searchType = -3;
+ }
+ else {
+ lucene::index::IndexReader *ir;
+ lucene::search::IndexSearcher *is;
+ ir = &IndexReader::open(target);
+ is = new IndexSearcher(*ir);
+ (*percent)(10, percentUserData);
+
+ standard::StandardAnalyzer analyzer;
+ Query &q = QueryParser::Parse(istr, _T("content"), analyzer);
+ (*percent)(20, percentUserData);
+ Hits &h = is->search(q);
+ (*percent)(80, percentUserData);
+
+
+ // iterate thru each good module position that meets the search
+ for (long i = 0; i < h.Length(); i++) {
+ Document &doc = h.doc(i);
+
+ // set a temporary verse key to this module position
+ vk = doc.get(_T("key"));
+
+ // check scope
+ // Try to set our scope key to this verse key
+ if (scope) {
+ *testKeyType = vk;
+
+ // check to see if it set ok and if so, add to our return list
+ if (*testKeyType == vk) {
+ listkey << (const char *) vk;
+ listkey.GetElement()->userData = reinterpret_cast<void *>((int)(h.score(i)*100));
+ }
+ }
+ else {
+ listkey << (const char*) vk;
+ listkey.GetElement()->userData = reinterpret_cast<void *>((int)(h.score(i)*100));
+ }
+ }
+ (*percent)(98, percentUserData);
+
+ delete &h;
+ delete &q;
+
+ delete is;
+ ir->close();
+ }
+ }
+#endif
+
+
if (searchType == -2) {
wordBuf = (char *)calloc(sizeof(char), strlen(istr) + 1);
strcpy(wordBuf, istr);
@@ -477,7 +565,8 @@
perc = 5;
(*percent)(perc, percentUserData);
- while (!Error() && !terminateSearch) {
+
+ while ((searchType > -4) && !Error() && !terminateSearch) {
long mindex = 0;
if (vkcheck)
mindex = vkcheck->NewIndex();
@@ -752,4 +841,127 @@
this->config = config;
}
+
+#ifdef USELUCENE
+void SWModule::deleteSearchFramework() {
+ SWBuf target = getConfigEntry("AbsoluteDataPath");
+ char ch = target.c_str()[strlen(target.c_str())-1];
+ if ((ch != '/') && (ch != '\\'))
+ target.append('/');
+ target.append("lucene");
+
+ FileMgr::removeDir(target.c_str());
+}
+
+
+signed char SWModule::createSearchFramework(void (*percent)(char, void *), void *percentUserData) {
+ SWKey *savekey = 0;
+ SWKey *searchkey = 0;
+ SWKey textkey;
+ char *word = 0;
+ char *wordBuf = 0;
+
+ // be sure we give CLucene enough file handles
+ FileMgr::getSystemFileMgr()->flush();
+
+ // save key information so as not to disrupt original
+ // module position
+ if (!key->Persist()) {
+ savekey = CreateKey();
+ *savekey = *key;
+ }
+ else savekey = key;
+
+ searchkey = (key->Persist())?key->clone():0;
+ if (searchkey) {
+ searchkey->Persist(1);
+ setKey(*searchkey);
+ }
+
+ // position module at the beginning
+ *this = TOP;
+
+ // iterate thru each entry in module
+
+ IndexWriter *writer = NULL;
+ Directory *d = NULL;
+
+ lucene::analysis::SimpleAnalyzer *an = new lucene::analysis::SimpleAnalyzer();
+ SWBuf target = getConfigEntry("AbsoluteDataPath");
+ char ch = target.c_str()[strlen(target.c_str())-1];
+ if ((ch != '/') && (ch != '\\'))
+ target.append('/');
+ target.append("lucene");
+ FileMgr::createParent(target+"/dummy");
+
+ if (IndexReader::indexExists(target.c_str())) {
+ d = &FSDirectory::getDirectory(target.c_str(), false);
+ if (IndexReader::isLocked(*d)) {
+ IndexReader::unlock(*d);
+ }
+
+ writer = new IndexWriter(*d, *an, false);
+ } else {
+ d = &FSDirectory::getDirectory(target.c_str(), true);
+ writer = new IndexWriter( *d ,*an, true);
+ }
+
+
+
+ char perc = 1;
+ VerseKey *vkcheck = 0;
+ SWTRY {
+ vkcheck = SWDYNAMIC_CAST(VerseKey, key);
+ }
+ SWCATCH (...) {}
+ long highIndex = (vkcheck)?32300/*vkcheck->NewIndex()*/:key->Index();
+ if (!highIndex)
+ highIndex = 1; // avoid division by zero errors.
+
+ while (!Error()) {
+ long mindex = 0;
+ if (vkcheck)
+ mindex = vkcheck->NewIndex();
+ else mindex = key->Index();
+ float per = (float)mindex / highIndex;
+ per *= 93;
+ per += 5;
+ char newperc = (char)per;
+// char newperc = (char)(5+(93*(((float)((vkcheck)?vkcheck->NewIndex():key->Index()))/highIndex)));
+ if (newperc > perc) {
+ perc = newperc;
+ (*percent)(perc, percentUserData);
+ }
+ const char *stripText = StripText();
+ if (stripText && *stripText) {
+ Document *doc = new Document();
+ doc->add( Field::Text(_T("key"), getKeyText() ) );
+ doc->add( Field::Text(_T("content"), stripText) );
+ writer->addDocument(*doc);
+ delete doc;
+ }
+
+ (*this)++;
+ }
+
+ writer->optimize();
+ writer->close();
+ delete writer;
+ delete an;
+
+ // reposition module back to where it was before we were called
+ setKey(*savekey);
+
+ if (!savekey->Persist())
+ delete savekey;
+
+ if (searchkey)
+ delete searchkey;
+
+ return 0;
+}
+#endif
+
+
+
SWORD_NAMESPACE_END
Modified: trunk/src/modules/texts/rawtext/rawtext.cpp
===================================================================
--- trunk/src/modules/texts/rawtext/rawtext.cpp 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/src/modules/texts/rawtext/rawtext.cpp 2005-02-10 14:44:58 UTC (rev 1717)
@@ -19,26 +19,23 @@
#include <rawtext.h>
#include <regex.h> // GNU
-#ifdef USELUCENE
-#include <CLucene.h>
-using namespace lucene::search;
-using namespace lucene::queryParser;
-#else
#include <map>
#include <list>
#include <algorithm>
+#ifndef USELUCENE
using std::map;
using std::list;
using std::find;
-
#endif
SWORD_NAMESPACE_START
+#ifndef USELUCENE
typedef map < SWBuf, list<long> > strlist;
typedef list<long> longlist;
+#endif
/******************************************************************************
* RawText Constructor - Initializes data for instance of RawText
@@ -144,114 +141,14 @@
}
+#ifndef USELUCENE
signed char RawText::createSearchFramework(void (*percent)(char, void *), void *percentUserData) {
-#ifdef USELUCENE
SWKey *savekey = 0;
SWKey *searchkey = 0;
SWKey textkey;
char *word = 0;
char *wordBuf = 0;
- // be sure we give CLucene enough file handles
- FileMgr::getSystemFileMgr()->flush();
- // save key information so as not to disrupt original
- // module position
- if (!key->Persist()) {
- savekey = CreateKey();
- *savekey = *key;
- }
- else savekey = key;
-
- searchkey = (key->Persist())?key->clone():0;
- if (searchkey) {
- searchkey->Persist(1);
- setKey(*searchkey);
- }
-
- // position module at the beginning
- *this = TOP;
-
- VerseKey *lkey = (VerseKey *)key;
-
- // iterate thru each entry in module
-
- IndexWriter* writer = NULL;
- Directory* d = NULL;
-
- lucene::analysis::SimpleAnalyzer& an = *new lucene::analysis::SimpleAnalyzer();
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- FileMgr::createParent(target+"/dummy");
-
- if (IndexReader::indexExists(target.c_str())) {
- d = &FSDirectory::getDirectory(target.c_str(), false);
- if (IndexReader::isLocked(*d)) {
- IndexReader::unlock(*d);
- }
-
- writer = new IndexWriter(*d, an, false);
- } else {
- d = &FSDirectory::getDirectory(target.c_str(), true);
- writer = new IndexWriter( *d ,an, true);
- }
-
-
- char perc = 1;
- VerseKey *vkcheck = 0;
- SWTRY {
- vkcheck = SWDYNAMIC_CAST(VerseKey, key);
- }
- SWCATCH (...) {}
- long highIndex = (vkcheck)?32300/*vkcheck->NewIndex()*/:key->Index();
- if (!highIndex)
- highIndex = 1; // avoid division by zero errors.
-
- while (!Error()) {
- long mindex = 0;
- if (vkcheck)
- mindex = vkcheck->NewIndex();
- else mindex = key->Index();
- float per = (float)mindex / highIndex;
- per *= 93;
- per += 5;
- char newperc = (char)per;
-// char newperc = (char)(5+(93*(((float)((vkcheck)?vkcheck->NewIndex():key->Index()))/highIndex)));
- if (newperc > perc) {
- perc = newperc;
- (*percent)(perc, percentUserData);
- }
- Document &doc = *new Document();
- doc.add( Field::Text(_T("key"), (const char *)*lkey ) );
- doc.add( Field::Text(_T("content"), StripText()) );
- writer->addDocument(doc);
- delete &doc;
-
- (*this)++;
- }
-
- writer->optimize();
- writer->close();
- delete writer;
- delete &an;
-
- // reposition module back to where it was before we were called
- setKey(*savekey);
-
- if (!savekey->Persist())
- delete savekey;
-
- if (searchkey)
- delete searchkey;
-
-#else
- SWKey *savekey = 0;
- SWKey *searchkey = 0;
- SWKey textkey;
- char *word = 0;
- char *wordBuf = 0;
-
// dictionary holds words associated with a list
// containing every module position that contains
// the word. [0] Old Testament; [1] NT
@@ -371,18 +268,22 @@
close(datfd);
close(idxfd);
}
-#endif
return 0;
}
+
void RawText::deleteSearchFramework() {
SWBuf target = path;
char ch = target.c_str()[strlen(target.c_str())-1];
if ((ch != '/') && (ch != '\\'))
target += "/lucene";
- FileMgr::removeDir(target.c_str());
+ FileMgr::removeFile(target + "ntwords.dat");
+ FileMgr::removeFile(target + "otwords.dat");
+ FileMgr::removeFile(target + "ntwords.idx");
+ FileMgr::removeFile(target + "otwords.idx");
}
+
/******************************************************************************
* SWModule::search - Searches a module for a string
*
@@ -399,102 +300,8 @@
*/
ListKey &RawText::search(const char *istr, int searchType, int flags, SWKey *scope, bool *justCheckIfSupported, void (*percent)(char, void *), void *percentUserData) {
-#ifdef USELUCENE
listkey.ClearList();
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- if (IndexReader::indexExists(target.c_str())) {
-
- switch (searchType) {
- case -2: { // let lucene replace multiword for now
-
-
- // test to see if our scope for this search is bounded by a
- // VerseKey
- VerseKey *testKeyType = 0, vk;
- SWTRY {
- testKeyType = SWDYNAMIC_CAST(VerseKey, ((scope)?scope:key));
- }
- SWCATCH ( ... ) {}
- // if we don't have a VerseKey * decendant we can't handle
- // because of scope.
- // In the future, add bool SWKey::isValid(const char *tryString);
- if (!testKeyType)
- break;
-
-
- // check if we just want to see if search is supported.
- // If we've gotten this far, then it is supported.
- if (justCheckIfSupported) {
- *justCheckIfSupported = true;
- return listkey;
- }
-
- lucene::index::IndexReader *ir;
- lucene::search::IndexSearcher *is;
- ir = &IndexReader::open(target);
- is = new IndexSearcher(*ir);
- (*percent)(10, percentUserData);
-
- standard::StandardAnalyzer analyzer;
- Query &q = QueryParser::Parse(istr, _T("content"), analyzer);
- (*percent)(20, percentUserData);
- Hits &h = is->search(q);
- (*percent)(80, percentUserData);
-
-
- // iterate thru each good module position that meets the search
- for (long i = 0; i < h.Length(); i++) {
- Document &doc = h.doc(i);
-
- // set a temporary verse key to this module position
- vk = doc.get(_T("key"));
-
- // check scope
- // Try to set our scope key to this verse key
- if (scope) {
- *testKeyType = vk;
-
- // check to see if it set ok and if so, add to our return list
- if (*testKeyType == vk) {
- listkey << (const char *) vk;
- listkey.GetElement()->userData = reinterpret_cast<void *>((int)(h.score(i)*100));
- }
- }
- else {
- listkey << (const char*) vk;
- listkey.GetElement()->userData = reinterpret_cast<void *>((int)(h.score(i)*100));
- }
- }
- (*percent)(98, percentUserData);
-
- delete &h;
- delete &q;
-
- delete is;
- ir->close();
-
- listkey = TOP;
- (*percent)(100, percentUserData);
- return listkey;
- }
-
- default:
- break;
- }
- }
-
- // check if we just want to see if search is supported
- if (justCheckIfSupported) {
- *justCheckIfSupported = false;
- return listkey;
- }
-#else
- listkey.ClearList();
-
if ((fastSearch[0]) && (fastSearch[1])) {
switch (searchType) {
@@ -671,10 +478,10 @@
return listkey;
}
-#endif
// if we don't support this search, fall back to base class
return SWModule::search(istr, searchType, flags, scope, justCheckIfSupported, percent, percentUserData);
}
+#endif
void RawText::setEntry(const char *inbuf, long len) {
Modified: trunk/src/modules/texts/ztext/ztext.cpp
===================================================================
--- trunk/src/modules/texts/ztext/ztext.cpp 2005-02-10 11:09:38 UTC (rev 1716)
+++ trunk/src/modules/texts/ztext/ztext.cpp 2005-02-10 14:44:58 UTC (rev 1717)
@@ -22,12 +22,6 @@
#include <regex.h> // GNU
-#ifdef USELUCENE
-#include <CLucene.h>
-using namespace lucene::search;
-using namespace lucene::queryParser;
-#endif
-
SWORD_NAMESPACE_START
/******************************************************************************
@@ -233,234 +227,7 @@
#define O_BINARY 0
#endif
-signed char zText::createSearchFramework(void (*percent)(char, void *), void *percentUserData) {
-#ifdef USELUCENE
- SWKey *savekey = 0;
- SWKey *searchkey = 0;
- SWKey textkey;
- char *word = 0;
- char *wordBuf = 0;
- // be sure we give CLucene enough file handles
- FileMgr::getSystemFileMgr()->flush();
- // save key information so as not to disrupt original
- // module position
- if (!key->Persist()) {
- savekey = CreateKey();
- *savekey = *key;
- }
- else savekey = key;
- searchkey = (key->Persist())?key->clone():0;
- if (searchkey) {
- searchkey->Persist(1);
- setKey(*searchkey);
- }
-
- // position module at the beginning
- *this = TOP;
-
- VerseKey *lkey = (VerseKey *)key;
-
- // iterate thru each entry in module
-
- IndexWriter *writer = NULL;
- Directory *d = NULL;
-
- lucene::analysis::SimpleAnalyzer *an = new lucene::analysis::SimpleAnalyzer();
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- FileMgr::createParent(target+"/dummy");
-
- if (IndexReader::indexExists(target.c_str())) {
- d = &FSDirectory::getDirectory(target.c_str(), false);
- if (IndexReader::isLocked(*d)) {
- IndexReader::unlock(*d);
- }
-
- writer = new IndexWriter(*d, *an, false);
- } else {
- d = &FSDirectory::getDirectory(target.c_str(), true);
- writer = new IndexWriter( *d ,*an, true);
- }
-
-
-
- char perc = 1;
- VerseKey *vkcheck = 0;
- SWTRY {
- vkcheck = SWDYNAMIC_CAST(VerseKey, key);
- }
- SWCATCH (...) {}
- long highIndex = (vkcheck)?32300/*vkcheck->NewIndex()*/:key->Index();
- if (!highIndex)
- highIndex = 1; // avoid division by zero errors.
-
- while (!Error()) {
- long mindex = 0;
- if (vkcheck)
- mindex = vkcheck->NewIndex();
- else mindex = key->Index();
- float per = (float)mindex / highIndex;
- per *= 93;
- per += 5;
- char newperc = (char)per;
-// char newperc = (char)(5+(93*(((float)((vkcheck)?vkcheck->NewIndex():key->Index()))/highIndex)));
- if (newperc > perc) {
- perc = newperc;
- (*percent)(perc, percentUserData);
- }
- Document *doc = new Document();
- doc->add( Field::Text(_T("key"), (const char *)*lkey ) );
- doc->add( Field::Text(_T("content"), StripText()) );
- writer->addDocument(*doc);
- delete doc;
-
- (*this)++;
- }
-
- writer->optimize();
- writer->close();
- delete writer;
- delete an;
-
- // reposition module back to where it was before we were called
- setKey(*savekey);
-
- if (!savekey->Persist())
- delete savekey;
-
- if (searchkey)
- delete searchkey;
-
-#endif
- return 0;
-}
-
-void zText::deleteSearchFramework() {
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- FileMgr::removeDir(target.c_str());
-}
-
-/******************************************************************************
- * SWModule::Search - Searches a module for a string
- *
- * ENT: istr - string for which to search
- * searchType - type of search to perform
- * >=0 - regex
- * -1 - phrase
- * -2 - multiword
- * flags - options flags for search
- * justCheckIfSupported - if set, don't search, only tell if this
- * function supports requested search.
- *
- * RET: listkey set to verses that contain istr
- */
-
-ListKey &zText::search(const char *istr, int searchType, int flags, SWKey *scope, bool *justCheckIfSupported, void (*percent)(char, void *), void *percentUserData) {
-#ifdef USELUCENE
- listkey.ClearList();
-
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- if (IndexReader::indexExists(target.c_str())) {
-
- switch (searchType) {
- case -2: { // let lucene replace multiword for now
-
-
- // test to see if our scope for this search is bounded by a
- // VerseKey
- VerseKey *testKeyType = 0, vk;
- SWTRY {
- testKeyType = SWDYNAMIC_CAST(VerseKey, ((scope)?scope:key));
- }
- SWCATCH ( ... ) {}
- // if we don't have a VerseKey * decendant we can't handle
- // because of scope.
- // In the future, add bool SWKey::isValid(const char *tryString);
- if (!testKeyType)
- break;
-
-
- // check if we just want to see if search is supported.
- // If we've gotten this far, then it is supported.
- if (justCheckIfSupported) {
- *justCheckIfSupported = true;
- return listkey;
- }
-
- lucene::index::IndexReader *ir;
- lucene::search::IndexSearcher *is;
- ir = &IndexReader::open(target);
- is = new IndexSearcher(*ir);
- (*percent)(10, percentUserData);
-
- standard::StandardAnalyzer analyzer;
- Query &q = QueryParser::Parse(istr, _T("content"), analyzer);
- (*percent)(20, percentUserData);
- Hits &h = is->search(q);
- (*percent)(80, percentUserData);
-
-
- // iterate thru each good module position that meets the search
- for (long i = 0; i < h.Length(); i++) {
- Document &doc = h.doc(i);
-
- // set a temporary verse key to this module position
- vk = doc.get(_T("key"));
-
- // check scope
- // Try to set our scope key to this verse key
- if (scope) {
- *testKeyType = vk;
-
- // check to see if it set ok and if so, add to our return list
- if (*testKeyType == vk) {
- listkey << (const char *) vk;
- listkey.GetElement()->userData = reinterpret_cast<void *>((int)(h.score(i)*100));
- }
- }
- else {
- listkey << (const char*) vk;
- listkey.GetElement()->userData = reinterpret_cast<void *>((int)(h.score(i)*100));
- }
- }
- (*percent)(98, percentUserData);
-
- delete &h;
- delete &q;
-
- delete is;
- ir->close();
-
- listkey = TOP;
- (*percent)(100, percentUserData);
- return listkey;
- }
-
- default:
- break;
- }
- }
-
- // check if we just want to see if search is supported
- if (justCheckIfSupported) {
- *justCheckIfSupported = false;
- return listkey;
- }
-#endif
- // if we don't support this search, fall back to base class
- return SWModule::search(istr, searchType, flags, scope, justCheckIfSupported, percent, percentUserData);
-}
-
-
SWORD_NAMESPACE_END
More information about the sword-cvs
mailing list