mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Index deletions by string ID (not NodeRef)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5468 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,7 +29,6 @@ import java.util.BitSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.lucene.document.Document;
|
||||
@@ -52,7 +51,7 @@ public class FilterIndexReaderByNodeRefs2 extends FilterIndexReader
|
||||
|
||||
private String id;
|
||||
|
||||
public FilterIndexReaderByNodeRefs2(String id, IndexReader reader, Set<NodeRef> deletions, boolean deleteNodesOnly)
|
||||
public FilterIndexReaderByNodeRefs2(String id, IndexReader reader, Set<String> deletions, boolean deleteNodesOnly)
|
||||
{
|
||||
super(reader);
|
||||
this.id = id;
|
||||
@@ -68,9 +67,9 @@ public class FilterIndexReaderByNodeRefs2 extends FilterIndexReader
|
||||
{
|
||||
if (!deleteNodesOnly)
|
||||
{
|
||||
for (NodeRef nodeRef : deletions)
|
||||
for (String stringRef : deletions)
|
||||
{
|
||||
TermDocs td = reader.termDocs(new Term("ID", nodeRef.toString()));
|
||||
TermDocs td = reader.termDocs(new Term("ID", stringRef));
|
||||
while (td.next())
|
||||
{
|
||||
deletedDocuments.set(td.doc(), true);
|
||||
@@ -81,9 +80,9 @@ public class FilterIndexReaderByNodeRefs2 extends FilterIndexReader
|
||||
{
|
||||
|
||||
Searcher searcher = new IndexSearcher(reader);
|
||||
for (NodeRef nodeRef : deletions)
|
||||
for (String stringRef : deletions)
|
||||
{
|
||||
TermQuery query = new TermQuery(new Term("ID", nodeRef.toString()));
|
||||
TermQuery query = new TermQuery(new Term("ID", stringRef));
|
||||
Hits hits = searcher.search(query);
|
||||
if (hits.length() > 0)
|
||||
{
|
||||
|
@@ -246,7 +246,7 @@ public abstract class LuceneBase2
|
||||
closeDeltaWriter();
|
||||
}
|
||||
|
||||
protected void setInfo(long docs, Set<NodeRef> deletions, boolean deleteNodesOnly) throws IOException
|
||||
protected void setInfo(long docs, Set<String> deletions, boolean deleteNodesOnly) throws IOException
|
||||
{
|
||||
indexInfo.setPreparedState(deltaId, deletions, docs, deleteNodesOnly);
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ public interface LuceneIndexer2 extends IndexerSPI
|
||||
|
||||
public String getDeltaId();
|
||||
public void flushPending() throws LuceneIndexException;
|
||||
public Set<NodeRef> getDeletions();
|
||||
public Set<String> getDeletions();
|
||||
public boolean getDeleteOnlyNodes();
|
||||
|
||||
public <R> R doWithWriteLock(IndexInfo.LockWork <R> lockWork);
|
||||
|
@@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -546,7 +547,7 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
|
||||
// }
|
||||
// Merge
|
||||
// mergeDeltaIntoMain(terms);
|
||||
setInfo(docs, deletions, false);
|
||||
setInfo(docs, getDeletions(), false);
|
||||
luceneFullTextSearchIndexer.requiresIndex(store);
|
||||
}
|
||||
}
|
||||
@@ -674,7 +675,7 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
|
||||
}
|
||||
}
|
||||
|
||||
setInfo(docs, deletions, true);
|
||||
setInfo(docs, getDeletions(), true);
|
||||
// mergeDeltaIntoMain(new LinkedHashSet<Term>());
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -2134,9 +2135,14 @@ public class LuceneIndexerImpl2 extends LuceneBase2 implements LuceneIndexer2
|
||||
this.luceneFullTextSearchIndexer = luceneFullTextSearchIndexer;
|
||||
}
|
||||
|
||||
public Set<NodeRef> getDeletions()
|
||||
public Set<String> getDeletions()
|
||||
{
|
||||
return Collections.unmodifiableSet(deletions);
|
||||
HashSet<String> deletedRefAsString = new HashSet<String>(deletions.size());
|
||||
for(NodeRef ref : deletions)
|
||||
{
|
||||
deletedRefAsString.add(ref.toString());
|
||||
}
|
||||
return deletedRefAsString;
|
||||
}
|
||||
|
||||
public boolean getDeleteOnlyNodes()
|
||||
|
@@ -1107,7 +1107,7 @@ public class LuceneTest2 extends TestCase
|
||||
for (int j = 0; j < i; j++)
|
||||
{
|
||||
ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("{namespace}test"), testSuperType);
|
||||
QName.createQName("{namespace}test_" + getName() + "_" + i + "_" +j), testSuperType);
|
||||
refs.add(test);
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,6 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.search.IndexerException;
|
||||
import org.alfresco.repo.search.impl.lucene.FilterIndexReaderByNodeRefs2;
|
||||
import org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -814,14 +813,14 @@ public class IndexInfo
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public Set<NodeRef> getDeletions(String id) throws IOException
|
||||
public Set<String> getDeletions(String id) throws IOException
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IndexerException("\"null\" is not a valid identifier for a transaction");
|
||||
}
|
||||
// Check state
|
||||
Set<NodeRef> deletions = new HashSet<NodeRef>();
|
||||
Set<String> deletions = new HashSet<String>();
|
||||
File location = new File(indexDirectory, id).getCanonicalFile();
|
||||
File file = new File(location, INDEX_INFO_DELETIONS).getCanonicalFile();
|
||||
if (!file.exists())
|
||||
@@ -830,14 +829,14 @@ public class IndexInfo
|
||||
{
|
||||
s_logger.debug("No deletions for " + id);
|
||||
}
|
||||
return Collections.<NodeRef> emptySet();
|
||||
return Collections.<String> emptySet();
|
||||
}
|
||||
DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
|
||||
int size = is.readInt();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
String ref = is.readUTF();
|
||||
deletions.add(new NodeRef(ref));
|
||||
deletions.add(ref);
|
||||
}
|
||||
is.close();
|
||||
if (s_logger.isDebugEnabled())
|
||||
@@ -861,7 +860,7 @@ public class IndexInfo
|
||||
* should deletions on apply to nodes (ie not to containers)
|
||||
* @throws IOException
|
||||
*/
|
||||
public void setPreparedState(String id, Set<NodeRef> toDelete, long documents, boolean deleteNodesOnly)
|
||||
public void setPreparedState(String id, Set<String> toDelete, long documents, boolean deleteNodesOnly)
|
||||
throws IOException
|
||||
{
|
||||
if (id == null)
|
||||
@@ -883,9 +882,9 @@ public class IndexInfo
|
||||
DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(location,
|
||||
INDEX_INFO_DELETIONS).getCanonicalFile())));
|
||||
os.writeInt(toDelete.size());
|
||||
for (NodeRef ref : toDelete)
|
||||
for (String ref : toDelete)
|
||||
{
|
||||
os.writeUTF(ref.toString());
|
||||
os.writeUTF(ref);
|
||||
}
|
||||
os.flush();
|
||||
os.close();
|
||||
@@ -993,7 +992,7 @@ public class IndexInfo
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public IndexReader getMainIndexReferenceCountingReadOnlyIndexReader(String id, Set<NodeRef> deletions,
|
||||
public IndexReader getMainIndexReferenceCountingReadOnlyIndexReader(String id, Set<String> deletions,
|
||||
boolean deleteOnlyNodes) throws IOException
|
||||
{
|
||||
if (id == null)
|
||||
@@ -2534,17 +2533,17 @@ public class IndexInfo
|
||||
|
||||
for (IndexEntry currentDelete : toDelete.values())
|
||||
{
|
||||
Set<NodeRef> deletions = getDeletions(currentDelete.getName());
|
||||
Set<String> deletions = getDeletions(currentDelete.getName());
|
||||
for (String key : readers.keySet())
|
||||
{
|
||||
IndexReader reader = readers.get(key);
|
||||
for (NodeRef nodeRef : deletions)
|
||||
for (String stringRef : deletions)
|
||||
{
|
||||
if (currentDelete.isDeletOnlyNodes())
|
||||
{
|
||||
Searcher searcher = new IndexSearcher(reader);
|
||||
|
||||
TermQuery query = new TermQuery(new Term("ID", nodeRef.toString()));
|
||||
TermQuery query = new TermQuery(new Term("ID", stringRef));
|
||||
Hits hits = searcher.search(query);
|
||||
if (hits.length() > 0)
|
||||
{
|
||||
@@ -2569,7 +2568,7 @@ public class IndexInfo
|
||||
int deletedCount = 0;
|
||||
try
|
||||
{
|
||||
deletedCount = reader.deleteDocuments(new Term("ID", nodeRef.toString()));
|
||||
deletedCount = reader.deleteDocuments(new Term("ID", stringRef));
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
@@ -2584,7 +2583,7 @@ public class IndexInfo
|
||||
if (s_logger.isDebugEnabled())
|
||||
{
|
||||
s_logger.debug("Deleted "
|
||||
+ deletedCount + " from " + key + " for id " + nodeRef.toString()
|
||||
+ deletedCount + " from " + key + " for id " + stringRef
|
||||
+ " remaining docs " + reader.numDocs());
|
||||
}
|
||||
invalidIndexes.add(key);
|
||||
|
@@ -29,11 +29,13 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
@@ -41,8 +43,6 @@ import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.TermDocs;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class IndexInfoTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -84,10 +84,10 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
System.setProperty("disableLuceneLocks", "true");
|
||||
|
||||
// no deletions - create only
|
||||
HashSet<NodeRef> deletions = new HashSet<NodeRef>();
|
||||
HashSet<String> deletions = new HashSet<String>();
|
||||
for (int i = 0; i < 0; i++)
|
||||
{
|
||||
deletions.add(new NodeRef(new StoreRef("woof", "bingle"), GUID.generate()));
|
||||
deletions.add(new NodeRef(new StoreRef("woof", "bingle"), GUID.generate()).toString());
|
||||
}
|
||||
|
||||
File tempLocation = TempFileProvider.getTempDir();
|
||||
@@ -217,7 +217,7 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
ii.closeDeltaIndexWriter(guid);
|
||||
|
||||
ii.setStatus(guid, TransactionStatus.PREPARING, null, null);
|
||||
ii.setPreparedState(guid, new HashSet<NodeRef>(), 1, false);
|
||||
ii.setPreparedState(guid, new HashSet<String>(), 1, false);
|
||||
ii.getDeletions(guid);
|
||||
ii.setStatus(guid, TransactionStatus.PREPARED, null, null);
|
||||
|
||||
@@ -238,7 +238,7 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
}
|
||||
reader.close();
|
||||
|
||||
reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, new HashSet<NodeRef>(), false);
|
||||
reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, new HashSet<String>(), false);
|
||||
assertEquals(reader.numDocs(), i + 1);
|
||||
for (int j = 0; j < CREATE_LIST.length; j++)
|
||||
{
|
||||
@@ -279,8 +279,8 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
|
||||
for (int i = 0; i < CREATE_LIST.length; i++)
|
||||
{
|
||||
HashSet<NodeRef> deletions = new HashSet<NodeRef>();
|
||||
deletions.add(nodeRefs.get(i));
|
||||
HashSet<String> deletions = new HashSet<String>();
|
||||
deletions.add(nodeRefs.get(i).toString());
|
||||
|
||||
IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader();
|
||||
assertEquals(reader.numDocs(), CREATE_LIST.length - i);
|
||||
@@ -406,7 +406,7 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
|
||||
ii.closeDeltaIndexWriter(guid);
|
||||
ii.setStatus(guid, TransactionStatus.PREPARING, null, null);
|
||||
ii.setPreparedState(guid, new HashSet<NodeRef>(), 1, false);
|
||||
ii.setPreparedState(guid, new HashSet<String>(), 1, false);
|
||||
ii.getDeletions(guid);
|
||||
ii.setStatus(guid, TransactionStatus.PREPARED, null, null);
|
||||
|
||||
@@ -427,7 +427,7 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
}
|
||||
reader.close();
|
||||
|
||||
reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, new HashSet<NodeRef>(), false);
|
||||
reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, new HashSet<String>(), false);
|
||||
assertEquals(reader.numDocs(), i + 1);
|
||||
for (int j = 0; j < CREATE_LIST.length; j++)
|
||||
{
|
||||
@@ -468,8 +468,8 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
|
||||
for (int i = 0; i < UPDATE_LIST.length; i++)
|
||||
{
|
||||
HashSet<NodeRef> deletions = new HashSet<NodeRef>();
|
||||
deletions.add(nodeRefs.get(i));
|
||||
HashSet<String> deletions = new HashSet<String>();
|
||||
deletions.add(nodeRefs.get(i).toString());
|
||||
|
||||
IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader();
|
||||
assertEquals(reader.numDocs(), UPDATE_LIST.length);
|
||||
@@ -672,7 +672,7 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
|
||||
ii.closeDeltaIndexWriter(guid);
|
||||
ii.setStatus(guid, TransactionStatus.PREPARING, null, null);
|
||||
ii.setPreparedState(guid, new HashSet<NodeRef>(), 1, false);
|
||||
ii.setPreparedState(guid, new HashSet<String>(), 1, false);
|
||||
ii.getDeletions(guid);
|
||||
ii.setStatus(guid, TransactionStatus.PREPARED, null, null);
|
||||
|
||||
@@ -696,7 +696,7 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
}
|
||||
reader.close();
|
||||
|
||||
reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, new HashSet<NodeRef>(), false);
|
||||
reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, new HashSet<String>(), false);
|
||||
lastDoc = -1;
|
||||
for (int j = 0; j < create.length; j++)
|
||||
{
|
||||
@@ -739,8 +739,8 @@ public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "
|
||||
|
||||
for (int i = 0; i < update.length; i++)
|
||||
{
|
||||
HashSet<NodeRef> deletions = new HashSet<NodeRef>();
|
||||
deletions.add(nodeRefs.get(i));
|
||||
HashSet<String> deletions = new HashSet<String>();
|
||||
deletions.add(nodeRefs.get(i).toString());
|
||||
|
||||
IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader();
|
||||
|
||||
|
Reference in New Issue
Block a user