You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2005/03/29 10:08:00 UTC
cvs commit: jakarta-slide/src/stores/org/apache/slide/index/lucene IndexInitializer.java Index.java LuceneContentIndexer.java LucenePropertiesIndexer.java
luetzkendorf 2005/03/29 00:08:00
Modified: src/stores/org/apache/slide/index/lucene Index.java
LuceneContentIndexer.java
LucenePropertiesIndexer.java
Added: src/stores/org/apache/slide/index/lucene
IndexInitializer.java
Log:
First solution for initializing a new index
Revision Changes Path
1.11 +9 -3 jakarta-slide/src/stores/org/apache/slide/index/lucene/Index.java
Index: Index.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/lucene/Index.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Index.java 11 Mar 2005 09:48:52 -0000 1.10
+++ Index.java 29 Mar 2005 08:08:00 -0000 1.11
@@ -99,6 +99,7 @@
*/
private int jobCounter = 0;
+ private boolean needsInitialization = false;
public Index(IndexConfiguration configuration, Logger logger, String name)
throws IndexException
@@ -121,6 +122,7 @@
IndexReader.unlock(directory);
}
} else {
+ this.needsInitialization = true;
IndexWriter writer = new IndexWriter(directory,
configuration.getAnalyzer(), true);
writer.close();
@@ -144,6 +146,10 @@
return this.logger;
}
+ public boolean needsInitialization() {
+ return this.needsInitialization;
+ }
+
public void start() {
if (configuration.indexAsynchron) {
this.indexThread = new JobRunner();
1.2 +8 -0 jakarta-slide/src/stores/org/apache/slide/index/lucene/LuceneContentIndexer.java
Index: LuceneContentIndexer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/lucene/LuceneContentIndexer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LuceneContentIndexer.java 8 Nov 2004 09:45:47 -0000 1.1
+++ LuceneContentIndexer.java 29 Mar 2005 08:08:00 -0000 1.2
@@ -36,6 +36,8 @@
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.event.DomainEvent;
+import org.apache.slide.event.EventDispatcher;
import org.apache.slide.extractor.ExtractorManager;
import org.apache.slide.search.IndexException;
@@ -60,6 +62,12 @@
this.index = new Index(indexConfiguration, getLogger(),
"content " + this.scope);
+
+ if (this.index.needsInitialization()) {
+ DomainEvent.NAMESPACE_INITIALIZED.setEnabled(true);
+ EventDispatcher.getInstance().addEventListener(
+ new IndexInitializer(this.scope, IndexInitializer.CONTENT, getLogger()));
+ }
}
catch (IndexException e) {
throw new ServiceInitializationFailedException(this, e);
1.7 +8 -0 jakarta-slide/src/stores/org/apache/slide/index/lucene/LucenePropertiesIndexer.java
Index: LucenePropertiesIndexer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/lucene/LucenePropertiesIndexer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LucenePropertiesIndexer.java 7 Jan 2005 16:47:48 -0000 1.6
+++ LucenePropertiesIndexer.java 29 Mar 2005 08:08:00 -0000 1.7
@@ -32,6 +32,8 @@
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.event.DomainEvent;
+import org.apache.slide.event.EventDispatcher;
import org.apache.slide.search.IndexException;
import org.apache.slide.util.conf.Configurable;
import org.apache.slide.util.conf.Configuration;
@@ -58,6 +60,12 @@
this.index = new Index(indexConfiguration, getLogger(),
"properties " + this.scope);
+
+ if (this.index.needsInitialization()) {
+ DomainEvent.NAMESPACE_INITIALIZED.setEnabled(true);
+ EventDispatcher.getInstance().addEventListener(new IndexInitializer(
+ this.scope, IndexInitializer.PROPERTIES, getLogger()));
+ }
}
catch (IndexException e) {
throw new ServiceInitializationFailedException(this, e);
1.1 jakarta-slide/src/stores/org/apache/slide/index/lucene/IndexInitializer.java
Index: IndexInitializer.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/stores/org/apache/slide/index/lucene/IndexInitializer.java,v 1.1 2005/03/29 08:08:00 luetzkendorf Exp $
* $Revision: 1.1 $
* $Date: 2005/03/29 08:08:00 $
*
* ====================================================================
*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.index.lucene;
import java.util.Enumeration;
import org.apache.slide.authenticate.CredentialsToken;
import org.apache.slide.authenticate.SecurityToken;
import org.apache.slide.common.Domain;
import org.apache.slide.common.Namespace;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.Scope;
import org.apache.slide.common.SlideToken;
import org.apache.slide.common.SlideTokenImpl;
import org.apache.slide.common.SlideTokenWrapper;
import org.apache.slide.common.Uri;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.content.RevisionContentNotFoundException;
import org.apache.slide.content.RevisionDescriptorNotFoundException;
import org.apache.slide.content.RevisionNotFoundException;
import org.apache.slide.event.DomainAdapter;
import org.apache.slide.event.DomainEvent;
import org.apache.slide.search.IndexException;
import org.apache.slide.store.AbstractStore;
import org.apache.slide.store.Store;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.StructureIterator;
import org.apache.slide.util.logger.Logger;
/**
* Initializer used to index all existing documents in a store. This is
* created and registered as en event listener by {@link LucenePropertiesIndexer}
* or {@link LuceneContentIndexer} if there is existing index so we are
* sure that all documents are to be to be indexed.
*/
public class IndexInitializer extends DomainAdapter
{
static final int CONTENT = 1;
static final int PROPERTIES = 2;
private Scope scope;
private int indexType;
private Logger logger;
IndexInitializer(Scope scope, int indexType, Logger logger) {
this.scope = scope;
this.indexType = indexType;
this.logger = logger;
}
public void namespaceInitialized(DomainEvent event)
{
Namespace namespace = event.getNamespace();
NamespaceAccessToken nsa = Domain.accessNamespace(new SecurityToken(""),
namespace.getName());
Content content = nsa.getContentHelper();
Store indexedStore = namespace.getStore(this.scope);
SlideToken slideToken = new SlideTokenImpl(new CredentialsToken(""));
slideToken = new SlideTokenWrapper(slideToken);
slideToken.setForceStoreEnlistment(true);
slideToken.setForceSecurity(false);
String logChannel = getClass().getName();
try {
nsa.begin();
StructureIterator i = new StructureIterator(nsa.getStructureHelper(),
slideToken, this.scope.toString());
logger.log("Init " + (indexType == CONTENT ? "content" : "properties" )
+ " index for scope " + this.scope, logChannel, Logger.INFO);
while (i.hasNext()) {
ObjectNode node = i.nextNode();
NodeRevisionDescriptors nrds = content.retrieve(slideToken, node.getUri());
for(Enumeration e = nrds.enumerateRevisionNumbers(); e.hasMoreElements();) {
Uri uri = nsa.getUri(slideToken, node.getUri());
Store store = uri.getStore();
NodeRevisionNumber nrn = (NodeRevisionNumber)e.nextElement();
if(store == indexedStore && store instanceof AbstractStore) {
NodeRevisionDescriptor nrd = null;
try {
nrd = content.retrieve(slideToken, nrds, nrn);
if (indexType == PROPERTIES) {
((AbstractStore)store).createPropertiesIndex(uri, nrd, null);
logger.log(node.getUri() + " props: " + nrn, logChannel, Logger.DEBUG);
}
} catch (RevisionDescriptorNotFoundException ex) {
continue;
} catch(IndexException ex) {
logger.log("Error while initalizing properties index for "
+ uri + " (" + nrn + ")", ex, logChannel, Logger.ERROR);
}
try {
if (indexType == CONTENT) {
NodeRevisionContent nrc = content.retrieve(slideToken, nrds, nrd);
((AbstractStore)store).createContentIndex(uri, nrd, nrc);
logger.log(node.getUri() + " content: " + nrn, logChannel, Logger.DEBUG);
}
} catch (RevisionNotFoundException ex) {
// ignore no content?
} catch (RevisionContentNotFoundException ex) {
// ignore not content
} catch (IndexException ex) {
logger.log("Error while initalizing content index for "
+ uri + " (" + nrn + ")", ex, logChannel, Logger.ERROR);
}
}
}
}
logger.log("Init " + (indexType == CONTENT ? "content" : "properties" )
+ " index for scope " + this.scope + " done", logChannel, Logger.INFO);
} catch (Exception e) {
Domain.error("Error while initializing " +
(indexType == CONTENT ? "content" : "properties" )+ " index for scope " +
this.scope, e);
} finally {
try {
nsa.commit();
} catch (Exception e) {
Domain.error("Error while commiting initialized " +
(indexType == CONTENT ? "content" : "properties" )+ " index for scope " +
this.scope, e);
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org