1 17 package org.alfresco.repo.node.index; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; 23 import org.alfresco.repo.transaction.TransactionUtil; 24 import org.alfresco.repo.transaction.TransactionUtil.TransactionWork; 25 import org.alfresco.service.cmr.repository.NodeService; 26 import org.alfresco.service.cmr.repository.StoreRef; 27 import org.alfresco.service.cmr.search.SearchService; 28 import org.alfresco.service.transaction.TransactionService; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 41 public class FtsIndexRecoveryComponent implements IndexRecovery 42 { 43 private static Log logger = LogFactory.getLog(FtsIndexRecoveryComponent.class); 44 45 46 private TransactionService transactionService; 47 48 private FullTextSearchIndexer ftsIndexer; 49 50 private SearchService searcher; 51 52 private NodeService nodeService; 53 54 private List <StoreRef> storeRefs; 55 56 public FtsIndexRecoveryComponent() 57 { 58 this.storeRefs = new ArrayList <StoreRef>(2); 59 } 60 61 64 public void setTransactionService(TransactionService transactionService) 65 { 66 this.transactionService = transactionService; 67 } 68 69 72 public void setFtsIndexer(FullTextSearchIndexer ftsIndexer) 73 { 74 this.ftsIndexer = ftsIndexer; 75 } 76 77 80 public void setNodeService(NodeService nodeService) 81 { 82 this.nodeService = nodeService; 83 } 84 85 90 public void setStores(List <String > storeRefStrings) 91 { 92 storeRefs.clear(); 93 for (String storeRefStr : storeRefStrings) 94 { 95 StoreRef storeRef = new StoreRef(storeRefStr); 96 storeRefs.add(storeRef); 97 } 98 } 99 100 103 public void reindex() 104 { 105 TransactionWork<Object > reindexWork = new TransactionWork<Object >() 106 { 107 public Object doWork() 108 { 109 for (StoreRef storeRef : storeRefs) 111 { 112 if (!nodeService.exists(storeRef)) 114 { 115 if (logger.isDebugEnabled()) 117 { 118 logger.debug("Skipping reindex of non-existent store: " + storeRef); 119 } 120 continue; 121 } 122 123 ftsIndexer.requiresIndex(storeRef); 125 } 126 return null; 128 } 129 }; 130 TransactionUtil.executeInUserTransaction(transactionService, reindexWork); 131 if (logger.isDebugEnabled()) 133 { 134 logger.debug("Prompted FTS index on stores: " + storeRefs); 135 } 136 } 137 } | Popular Tags |