[sword-svn] r2045 - trunk/src/modules
chrislit at www.crosswire.org
chrislit at www.crosswire.org
Thu May 3 03:41:08 MST 2007
Author: chrislit
Date: 2007-05-03 03:41:07 -0700 (Thu, 03 May 2007)
New Revision: 2045
Modified:
trunk/src/modules/swmodule.cpp
Log:
DM's RAMDirectory patch for CLucene indexing
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2007-05-01 17:35:31 UTC (rev 2044)
+++ trunk/src/modules/swmodule.cpp 2007-05-03 10:41:07 UTC (rev 2045)
@@ -515,7 +515,7 @@
is = new IndexSearcher(ir);
(*percent)(10, percentUserData);
- standard::StandardAnalyzer analyzer;
+ SimpleAnalyzer analyzer;
lucene_utf8towcs(wcharBuffer, istr, MAX_CONV_SIZE); //TODO Is istr always utf8?
q = QueryParser::parse(wcharBuffer, _T("content"), &analyzer);
(*percent)(20, percentUserData);
@@ -960,10 +960,12 @@
setKey(*searchKey);
}
- IndexWriter *writer = NULL;
+ RAMDirectory *ramDir = NULL;
+ IndexWriter *coreWriter = NULL;
+ IndexWriter *fsWriter = NULL;
Directory *d = NULL;
- standard::StandardAnalyzer *an = new standard::StandardAnalyzer();
+ SimpleAnalyzer *an = new SimpleAnalyzer();
SWBuf target = getConfigEntry("AbsoluteDataPath");
bool includeKeyInSearch = getConfig().has("SearchOption", "IncludeKeyInSearch");
char ch = target.c_str()[strlen(target.c_str())-1];
@@ -972,19 +974,10 @@
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);
- }
+ ramDir = new RAMDirectory();
+ coreWriter = new IndexWriter(ramDir, an, true);
+
-
char perc = 1;
VerseKey *vkcheck = 0;
@@ -1222,7 +1215,7 @@
if (good) {
//printf("writing (%s).\n", (const char *)*key);
//fflush(stdout);
- writer->addDocument(doc);
+ coreWriter->addDocument(doc);
}
delete doc;
@@ -1230,9 +1223,29 @@
err = Error();
}
- writer->optimize();
- writer->close();
- delete writer;
+ // Optimizing automatically happens with the call to addIndexes
+ //coreWriter->optimize();
+ coreWriter->close();
+
+ if (IndexReader::indexExists(target.c_str())) {
+ d = FSDirectory::getDirectory(target.c_str(), false);
+ if (IndexReader::isLocked(d)) {
+ IndexReader::unlock(d);
+ }
+
+ fsWriter = new IndexWriter( d, an, false);
+ } else {
+ d = FSDirectory::getDirectory(target.c_str(), true);
+ fsWriter = new IndexWriter( d ,an, true);
+ }
+
+ Directory *dirs[] = { ramDir, 0 };
+ fsWriter->addIndexes(dirs);
+ fsWriter->close();
+
+ delete ramDir;
+ delete coreWriter;
+ delete fsWriter;
delete an;
// reposition module back to where it was before we were called
More information about the sword-cvs
mailing list