* fixed a bug in Index.create() to correctly work for both disk- and ram-indexes

* added missing argument documentation
* fixed typo in Index.addDocuments()
This commit is contained in:
grob 2007-05-07 14:58:52 +00:00
parent 84e03145e5
commit cd05f1679b

View file

@ -17,9 +17,9 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// //
// //
// $Revision: 1.10 $ // $Revision: 1.11 $
// $Author: robert $ // $Author: robert $
// $Date: 2007/02/07 17:04:51 $ // $Date: 2007/02/07 18:11:01 $
// //
@ -280,6 +280,8 @@ helma.Search.Index = function(directory, analyzer) {
* index is currently locked this method will try for the next * index is currently locked this method will try for the next
* two seconds to create the IndexModifier, otherwise it will * two seconds to create the IndexModifier, otherwise it will
* throw an error. * throw an error.
* @param {Boolean} create True to create the index (overwriting an
* existing index), false to append to an existing index.
* @returns An IndexModifier instance. * @returns An IndexModifier instance.
* @type org.apache.lucene.index.IndexModifier * @type org.apache.lucene.index.IndexModifier
*/ */
@ -293,6 +295,8 @@ helma.Search.Index = function(directory, analyzer) {
* If the index is currently locked this method will try for the next * If the index is currently locked this method will try for the next
* two seconds to create the IndexWriter, otherwise it will * two seconds to create the IndexWriter, otherwise it will
* throw an error. * throw an error.
* @param {Boolean} create True to create the index (overwriting an
* existing index), false to append to an existing index.
* @returns An IndexWriter instance. * @returns An IndexWriter instance.
* @type org.apache.lucene.index.IndexWriter * @type org.apache.lucene.index.IndexWriter
*/ */
@ -382,23 +386,25 @@ helma.Search.Index.prototype.addIndexes = function(dir /* [, dir[, dir...] */) {
* @type Boolean * @type Boolean
*/ */
helma.Search.Index.prototype.create = function() { helma.Search.Index.prototype.create = function() {
try { var dir = this.getDirectory();
if (dir instanceof Packages.org.apache.lucene.store.FSDirectory) {
// FIXME: IndexWriter is supposed to remove files // FIXME: IndexWriter is supposed to remove files
// if instantiated with create == true, but for some reason // if instantiated with create == true, but for some reason
// it doesn't, so instead use FSDirectory.getDirectory() // it doesn't, so instead use FSDirectory.getDirectory()
// for deletion and then re-create the index segments file // for deletion and then re-create the index segments file
var dir = this.getDirectory().getFile(); Packages.org.apache.lucene.store.FSDirectory.getDirectory(dir.getFile(), true);
Packages.org.apache.lucene.store.FSDirectory.getDirectory(dir, true); }
try {
var writer = this.getWriter(true); var writer = this.getWriter(true);
return true; return true;
} catch (e) { } catch (e) {
app.logger.warn("Unable to create the index " + this.getDirectory()); app.logger.warn("Unable to create the index " + this.getDirectory());
return false;
} finally { } finally {
if (writer != null) { if (writer != null) {
writer.close(); writer.close();
} }
} }
return false;
}; };
/** /**
@ -516,9 +522,9 @@ helma.Search.Index.prototype.addDocuments = function(docs, mergeFactor) {
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
modifier.addDocument(e.nextElement().getDocument()); modifier.addDocument(e.nextElement().getDocument());
} }
} else if (doc instanceof Array) { } else if (docs instanceof Array) {
for (var i=0;i<docs.length;i++) { for (var i=0;i<docs.length;i++) {
modifier.addDocument(docs[i]); modifier.addDocument(docs[i].getDocument());
} }
} }
} finally { } finally {
@ -1145,13 +1151,12 @@ helma.Search.Document.prototype.addField = function(name, value, param) {
helma.Search.Document.prototype.getField = function(name) { helma.Search.Document.prototype.getField = function(name) {
var f = this.getDocument().getField(name); var f = this.getDocument().getField(name);
if (f != null) { if (f != null) {
var result = {name: name, return {name: name,
boost: f.getBoost(), boost: f.getBoost(),
indexed: f.isIndexed(), indexed: f.isIndexed(),
stored: f.isStored(), stored: f.isStored(),
tokenized: f.isTokenized(), tokenized: f.isTokenized(),
value: f.stringValue()}; value: f.stringValue()};
return result;
} }
return null; return null;
}; };