From: john Date: Sat, 18 Jan 2003 12:35:11 +0000 (+0000) Subject: made the indexPath parameter-expanded, so we can reference X-Git-Tag: BEFORE_MERGE_1_1~301 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=d0803613812ff7b33f74a7d17e42203489e45fc0;p=mir.git made the indexPath parameter-expanded, so we can reference the centralized location of the index in config.properties from producers.xml --- diff --git a/source/mircoders/producer/IndexingProducerNode.java b/source/mircoders/producer/IndexingProducerNode.java index 739bfbbf..0949f4ef 100755 --- a/source/mircoders/producer/IndexingProducerNode.java +++ b/source/mircoders/producer/IndexingProducerNode.java @@ -70,15 +70,17 @@ public class IndexingProducerNode implements ProducerNode { IndexWriter indexWriter = null; Object data; Entity entity; - + String index = null; long startTime; long endTime; startTime = System.currentTimeMillis(); - + + + try { - data = ParameterExpander.findValueForKey( aValueMap, contentKey ); - + index = ParameterExpander.expandExpression(aValueMap, indexPath); + data = ParameterExpander.findValueForKey( aValueMap, contentKey ); if (! (data instanceof EntityAdapter)) { throw new ProducerFailure("IndexingProducerNode: value of '"+contentKey+"' is not an EntityAdapter, but an " + data.getClass().getName(), null); } @@ -87,20 +89,20 @@ public class IndexingProducerNode implements ProducerNode { if (! (entity instanceof EntityContent)) { throw new ProducerFailure("IndexingProducerNode: value of '"+contentKey+"' is not a content EntityAdapter, but a " + entity.getClass().getName() + " adapter", null); } - aLogger.info("Indexing " + (String) entity.getValue("id") + " into " + indexPath); + aLogger.info("Indexing " + (String) entity.getValue("id") + " into " + index); // create an index here if one did not already exist - if (! (IndexReader.indexExists(indexPath))){ - aLogger.error("Didn't find existing index, so I'm making one in "+indexPath); - IndexWriter indexCreator = new IndexWriter(indexPath,new StandardAnalyzer(),true); + if (! (IndexReader.indexExists(index))){ + aLogger.error("Didn't find existing index, so I'm making one in "+index); + IndexWriter indexCreator = new IndexWriter(index,new StandardAnalyzer(),true); indexCreator.close(); } - indexReader = IndexReader.open(indexPath); + indexReader = IndexReader.open(index); indexReader.delete(new Term("id",entity.getValue("id"))); indexReader.close(); - indexWriter = new IndexWriter(indexPath, new StandardAnalyzer(), false); + indexWriter = new IndexWriter(index, new StandardAnalyzer(), false); Document theDoc = new Document(); // Keyword is stored and indexed, but not tokenized @@ -182,7 +184,7 @@ public class IndexingProducerNode implements ProducerNode { try{ - FSDirectory theIndexDir=FSDirectory.getDirectory(indexPath,false); + FSDirectory theIndexDir=FSDirectory.getDirectory(index,false); if (indexReader.isLocked(theIndexDir)){ indexReader.unlock(theIndexDir); } diff --git a/source/mircoders/producer/UnIndexingProducerNode.java b/source/mircoders/producer/UnIndexingProducerNode.java index 60b21b24..15a5a1f2 100755 --- a/source/mircoders/producer/UnIndexingProducerNode.java +++ b/source/mircoders/producer/UnIndexingProducerNode.java @@ -70,6 +70,7 @@ public class UnIndexingProducerNode implements ProducerNode { IndexReader indexReader = null; Object data; Entity entity; + String index=null; long startTime; long endTime; @@ -77,6 +78,7 @@ public class UnIndexingProducerNode implements ProducerNode { startTime = System.currentTimeMillis(); try { + index = ParameterExpander.expandExpression(aValueMap, indexPath); data = ParameterExpander.findValueForKey( aValueMap, contentKey ); if (! (data instanceof EntityAdapter)) { @@ -87,9 +89,9 @@ public class UnIndexingProducerNode implements ProducerNode { if (! (entity instanceof EntityContent)) { throw new ProducerFailure("UnIndexingProducerNode: value of '"+contentKey+"' is not a content EntityAdapter, but a " + entity.getClass().getName() + " adapter", null); } - aLogger.info("UnIndexing " + (String) entity.getValue("id") + " out of " + indexPath); + aLogger.info("UnIndexing " + (String) entity.getValue("id") + " out of " + index); - indexReader = IndexReader.open(indexPath); + indexReader = IndexReader.open(index); indexReader.delete(new Term("id",entity.getValue("id"))); indexReader.close(); @@ -110,10 +112,12 @@ public class UnIndexingProducerNode implements ProducerNode { } try{ - FSDirectory theIndexDir=FSDirectory.getDirectory(indexPath,false); - if (indexReader.isLocked(theIndexDir)){ - indexReader.unlock(theIndexDir); - } + if (index != null){ + FSDirectory theIndexDir=FSDirectory.getDirectory(index,false); + if (indexReader.isLocked(theIndexDir)){ + indexReader.unlock(theIndexDir); + } + } } catch (Throwable t) { aLogger.warn("Error while unlocking index: " + t.getMessage());