- add TenantService hooks to ADM Searcher & Indexer

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6401 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka 2007-08-02 14:22:48 +00:00
parent 65f660c26c
commit dbdbb003f1
8 changed files with 135 additions and 20 deletions

View File

@ -347,6 +347,9 @@
<property name="nodeService">
<ref bean="mlAwareNodeService" />
</property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>
@ -464,6 +467,9 @@
<property name="nodeService">
<ref bean="nodeService" />
</property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
<property name="dictionaryService">
<ref bean="dictionaryService" />
</property>

View File

@ -96,8 +96,11 @@ public class ADMLuceneIndexerAndSearcherFactory extends AbstractLuceneIndexerAnd
protected LuceneIndexer createIndexer(StoreRef storeRef, String deltaId)
{
storeRef = tenantService.getName(storeRef);
ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(storeRef, deltaId, this);
indexer.setNodeService(nodeService);
indexer.setTenantService(tenantService);
indexer.setDictionaryService(dictionaryService);
// indexer.setLuceneIndexLock(luceneIndexLock);
indexer.setFullTextSearchIndexer(fullTextSearchIndexer);
@ -108,10 +111,13 @@ public class ADMLuceneIndexerAndSearcherFactory extends AbstractLuceneIndexerAnd
protected LuceneSearcher getSearcher(StoreRef storeRef, LuceneIndexer indexer) throws SearcherException
{
storeRef = tenantService.getName(storeRef);
ADMLuceneSearcherImpl searcher = ADMLuceneSearcherImpl.getSearcher(storeRef, indexer, this);
searcher.setNamespacePrefixResolver(nameSpaceService);
// searcher.setLuceneIndexLock(luceneIndexLock);
searcher.setNodeService(nodeService);
searcher.setTenantService(tenantService);
searcher.setDictionaryService(dictionaryService);
searcher.setQueryRegister(getQueryRegister());
return searcher;

View File

@ -48,6 +48,7 @@ import org.alfresco.repo.content.transform.ContentTransformer;
import org.alfresco.repo.search.IndexerException;
import org.alfresco.repo.search.impl.lucene.fts.FTSIndexerAware;
import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
@ -98,6 +99,11 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
*/
NodeService nodeService;
/**
* The tenant service we use for multi-tenancy
*/
TenantService tenantService;
/**
* Content service to get content for indexing.
*/
@ -127,25 +133,35 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
}
/**
* IOC setting of dictionary service
* IOC setting of the dictionary service
*
* @param dictionaryService
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
super.setDictionaryService(dictionaryService);
}
/**
* Setter for getting the node service via IOC Used in the Spring container
* IOC setting of the node service
*
* @param nodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* IOC setting of the tenant service
*
* @param tenantService
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* IOC setting of the content service
*
@ -171,7 +187,8 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
{
NodeRef childRef = relationshipRef.getChildRef();
// If we have the root node we delete all other root nodes first
if ((relationshipRef.getParentRef() == null) && childRef.equals(nodeService.getRootNode(childRef.getStoreRef())))
if ((relationshipRef.getParentRef() == null)
&& tenantService.getBaseName(childRef).equals(nodeService.getRootNode(childRef.getStoreRef())))
{
addRootNodesToDeletionList();
s_logger.warn("Detected root node addition: deleting all nodes from the index");
@ -226,6 +243,8 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
public void updateNode(NodeRef nodeRef) throws LuceneIndexException
{
nodeRef = tenantService.getName(nodeRef);
if (s_logger.isDebugEnabled())
{
s_logger.debug("Update node " + nodeRef);
@ -547,7 +566,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
}
}
boolean isRoot = nodeRef.equals(nodeService.getRootNode(nodeRef.getStoreRef()));
boolean isRoot = nodeRef.equals(tenantService.getName(nodeService.getRootNode(nodeRef.getStoreRef())));
StringBuilder qNameBuffer = new StringBuilder(64);
@ -588,7 +607,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
qNameBuffer.append(";/");
}
qNameBuffer.append(ISO9075.getXPathName(qNameRef.getQName()));
xdoc.add(new Field("PARENT", qNameRef.getParentRef().toString(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
xdoc.add(new Field("PARENT", tenantService.getName(qNameRef.getParentRef()).toString(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
xdoc.add(new Field("ASSOCTYPEQNAME", ISO9075.getXPathName(qNameRef.getTypeQName()), Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
xdoc.add(new Field("LINKASPECT", (pair.getSecond() == null) ? "" : ISO9075.getXPathName(pair.getSecond()), Field.Store.YES, Field.Index.UN_TOKENIZED,
Field.TermVector.NO));
@ -613,7 +632,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
directoryEntry.add(new Field("PATH", pathString, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
for (NodeRef parent : getParents(pair.getFirst()))
{
directoryEntry.add(new Field("ANCESTOR", parent.toString(), Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
directoryEntry.add(new Field("ANCESTOR", tenantService.getName(parent).toString(), Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
}
directoryEntry.add(new Field("ISCONTAINER", "T", Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
@ -650,7 +669,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
// true));
ChildAssociationRef primary = nodeService.getPrimaryParent(nodeRef);
xdoc.add(new Field("PRIMARYPARENT", primary.getParentRef().toString(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
xdoc.add(new Field("PRIMARYPARENT", tenantService.getName(primary.getParentRef()).toString(), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO));
xdoc.add(new Field("PRIMARYASSOCTYPEQNAME", ISO9075.getXPathName(primary.getTypeQName()), Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
QName typeQName = nodeService.getType(nodeRef);
@ -1061,6 +1080,9 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl<NodeRef> imp
{
if (catRef != null)
{
// can be running in context of System user, hence use input nodeRef
catRef = tenantService.getName(nodeRef, catRef);
try
{
for (Path path : nodeService.getPaths(catRef, false))

View File

@ -40,6 +40,7 @@ import org.alfresco.repo.search.QueryRegisterComponent;
import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.impl.NodeSearcher;
import org.alfresco.repo.search.impl.lucene.QueryParser.Operator;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
@ -86,6 +87,8 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
private NodeService nodeService;
private TenantService tenantService;
private DictionaryService dictionaryService;
private QueryRegisterComponent queryRegister;
@ -148,6 +151,11 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
this.nodeService = nodeService;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
@ -165,6 +173,8 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
public ResultSet query(StoreRef store, String language, String queryString, Path[] queryOptions,
QueryParameterDefinition[] queryParameterDefinitions) throws SearcherException
{
store = tenantService.getName(store);
SearchParameters sp = new SearchParameters();
sp.addStore(store);
sp.setLanguage(language);
@ -195,6 +205,9 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
throw new IllegalStateException("Only one store can be searched at present");
}
ArrayList<StoreRef> stores = searchParameters.getStores();
stores.set(0, tenantService.getName(searchParameters.getStores().get(0)));
String parameterisedQueryString;
if (searchParameters.getQueryParameterDefinitions().size() > 0)
{
@ -227,8 +240,10 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
defaultOperator = LuceneQueryParser.OR_OPERATOR;
}
Query query = LuceneQueryParser.parse(parameterisedQueryString, DEFAULT_FIELD, new LuceneAnalyser(
dictionaryService, searchParameters.getMlAnalaysisMode() == null ? getLuceneConfig().getDefaultMLSearchAnalysisMode() : searchParameters.getMlAnalaysisMode()), namespacePrefixResolver, dictionaryService, defaultOperator, searchParameters, getLuceneConfig());
Query query = LuceneQueryParser.parse(parameterisedQueryString, DEFAULT_FIELD,
new LuceneAnalyser(dictionaryService, searchParameters.getMlAnalaysisMode() == null ? getLuceneConfig().getDefaultMLSearchAnalysisMode() : searchParameters.getMlAnalaysisMode()),
namespacePrefixResolver, dictionaryService, tenantService, defaultOperator, searchParameters, getLuceneConfig());
ClosingIndexSearcher searcher = getSearcher(indexer);
if (searcher == null)
{
@ -277,6 +292,7 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
hits,
searcher,
nodeService,
tenantService,
paths,
searchParameters);
@ -312,7 +328,7 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
return new EmptyResultSet();
}
Hits hits = searcher.search(query);
return new LuceneResultSet(hits, searcher, nodeService, searchParameters.getAttributePaths().toArray(
return new LuceneResultSet(hits, searcher, nodeService, tenantService, searchParameters.getAttributePaths().toArray(
new Path[0]), searchParameters);
}
catch (SAXPathException e)
@ -536,6 +552,9 @@ public class ADMLuceneSearcherImpl extends AbstractLuceneBase implements LuceneS
throws InvalidNodeRefException, XPathException
{
NodeSearcher nodeSearcher = new NodeSearcher(nodeService, dictionaryService, this);
contextNodeRef = tenantService.getName(contextNodeRef);
return nodeSearcher.selectNodes(contextNodeRef, xpath, parameters, namespacePrefixResolver,
followAllParentLinks, language);
}

View File

@ -45,6 +45,7 @@ import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.impl.lucene.index.IndexInfo;
import org.alfresco.repo.search.transaction.SimpleTransaction;
import org.alfresco.repo.search.transaction.SimpleTransactionManager;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.NodeService;
@ -106,9 +107,7 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI
*/
private static final int DEFAULT_TIMEOUT = 600000;
/**
* The node service we use to get information about nodes
*/
protected TenantService tenantService;
private String indexRootLocation;
@ -149,6 +148,16 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI
this.indexRootLocation = indexRootLocation;
}
/**
* Set the tenant service
*
* @param tenantService
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Set the query register
*
@ -235,6 +244,8 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI
*/
public LuceneIndexer getIndexer(StoreRef storeRef) throws IndexerException
{
storeRef = tenantService.getName(storeRef);
// register to receive txn callbacks
// TODO: make this conditional on whether the XA stuff is being used
// directly on not
@ -346,6 +357,8 @@ public abstract class AbstractLuceneIndexerAndSearcherFactory implements LuceneI
*/
public LuceneSearcher getSearcher(StoreRef storeRef, boolean searchDelta) throws SearcherException
{
storeRef = tenantService.getName(storeRef);
String deltaId = null;
LuceneIndexer indexer = null;
if (searchDelta)

View File

@ -37,6 +37,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.search.IndexerAndSearcher;
import org.alfresco.repo.search.IndexerException;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
@ -60,6 +61,8 @@ public class LuceneCategoryServiceImpl implements CategoryService
{
private NodeService nodeService;
private TenantService tenantService;
private NamespacePrefixResolver namespacePrefixResolver;
private DictionaryService dictionaryService;
@ -85,6 +88,15 @@ public class LuceneCategoryServiceImpl implements CategoryService
this.nodeService = nodeService;
}
/**
* Set the tenant service
* @param tenantService
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Set the service to map prefixes to uris
* @param namespacePrefixResolver
@ -118,6 +130,9 @@ public class LuceneCategoryServiceImpl implements CategoryService
{
return Collections.<ChildAssociationRef> emptyList();
}
categoryRef = tenantService.getName(categoryRef);
ResultSet resultSet = null;
try
{
@ -244,6 +259,8 @@ public class LuceneCategoryServiceImpl implements CategoryService
private Set<NodeRef> getClassificationNodes(StoreRef storeRef, QName qname)
{
storeRef = tenantService.getName(storeRef);
ResultSet resultSet = null;
try
{
@ -269,6 +286,8 @@ public class LuceneCategoryServiceImpl implements CategoryService
public Collection<ChildAssociationRef> getClassifications(StoreRef storeRef)
{
storeRef = tenantService.getName(storeRef);
ResultSet resultSet = null;
try
{

View File

@ -40,11 +40,14 @@ import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.impl.lucene.analysis.MLTokenDuplicator;
import org.alfresco.repo.search.impl.lucene.analysis.VerbatimAnalyser;
import org.alfresco.repo.search.impl.lucene.query.PathQuery;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.alfresco.service.namespace.QName;
@ -70,6 +73,8 @@ public class LuceneQueryParser extends QueryParser
private DictionaryService dictionaryService;
private TenantService tenantService;
private SearchParameters searchParameters;
private LuceneConfig config;
@ -88,7 +93,7 @@ public class LuceneQueryParser extends QueryParser
* if the parsing fails
*/
static public Query parse(String query, String field, Analyzer analyzer,
NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService,
NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, TenantService tenantService,
Operator defaultOperator, SearchParameters searchParameters, LuceneConfig config) throws ParseException
{
if (s_logger.isDebugEnabled())
@ -99,6 +104,7 @@ public class LuceneQueryParser extends QueryParser
parser.setDefaultOperator(defaultOperator);
parser.setNamespacePrefixResolver(namespacePrefixResolver);
parser.setDictionaryService(dictionaryService);
parser.setTenantService(tenantService);
parser.setSearchParameters(searchParameters);
parser.setLuceneConfig(config);
// TODO: Apply locale contstraints at the top level if required for the non ML doc types.
@ -125,6 +131,11 @@ public class LuceneQueryParser extends QueryParser
this.namespacePrefixResolver = namespacePrefixResolver;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public LuceneQueryParser(String arg0, Analyzer arg1)
{
super(arg0, arg1);
@ -212,6 +223,11 @@ public class LuceneQueryParser extends QueryParser
}
else if (field.equals("ID"))
{
if (tenantService.isTenantUser() && (queryText.contains(StoreRef.URI_FILLER)))
{
// assume NodeRef, since it contains StorRef URI filler
queryText = tenantService.getName(new NodeRef(queryText)).toString();
}
TermQuery termQuery = new TermQuery(new Term(field, queryText));
return termQuery;
}
@ -237,11 +253,21 @@ public class LuceneQueryParser extends QueryParser
}
else if (field.equals("PARENT"))
{
if (tenantService.isTenantUser() && (queryText.contains(StoreRef.URI_FILLER)))
{
// assume NodeRef, since it contains StoreRef URI filler
queryText = tenantService.getName(new NodeRef(queryText)).toString();
}
TermQuery termQuery = new TermQuery(new Term(field, queryText));
return termQuery;
}
else if (field.equals("PRIMARYPARENT"))
{
if (tenantService.isTenantUser() && (queryText.contains(StoreRef.URI_FILLER)))
{
// assume NodeRef, since it contains StoreRef URI filler
queryText = tenantService.getName(new NodeRef(queryText)).toString();
}
TermQuery termQuery = new TermQuery(new Term(field, queryText));
return termQuery;
}

View File

@ -30,6 +30,7 @@ import org.alfresco.repo.search.AbstractResultSet;
import org.alfresco.repo.search.ResultSetRowIterator;
import org.alfresco.repo.search.SearcherException;
import org.alfresco.repo.search.SimpleResultSetMetaData;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@ -60,6 +61,8 @@ public class LuceneResultSet extends AbstractResultSet
private NodeService nodeService;
private TenantService tenantService;
SearchParameters searchParameters;
/**
@ -68,12 +71,13 @@ public class LuceneResultSet extends AbstractResultSet
* @param storeRef
* @param hits
*/
public LuceneResultSet(Hits hits, Searcher searcher, NodeService nodeService, Path[]propertyPaths, SearchParameters searchParameters)
public LuceneResultSet(Hits hits, Searcher searcher, NodeService nodeService, TenantService tenantService, Path[]propertyPaths, SearchParameters searchParameters)
{
super(propertyPaths);
this.hits = hits;
this.searcher = searcher;
this.nodeService = nodeService;
this.tenantService = tenantService;
this.searchParameters = searchParameters;
}
@ -99,7 +103,7 @@ public class LuceneResultSet extends AbstractResultSet
// It is possible the store ref is also stored in the index
Document doc = hits.doc(n);
String id = doc.get("ID");
return new NodeRef(id);
return tenantService.getBaseName(new NodeRef(id));
}
catch (IOException e)
{