PageRenderTime 91ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/src/java/org/infoglue/cms/controllers/kernel/impl/simple/LuceneController.java

http://github.com/bogeblad/infoglue
Java | 2561 lines | 1961 code | 360 blank | 240 comment | 301 complexity | c06b35b1e91eb53d9083d79c8d6754eb MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /* ===============================================================================
  2. *
  3. * Part of the InfoGlue Content Management Platform (www.infoglue.org)
  4. *
  5. * ===============================================================================
  6. *
  7. * Copyright (C)
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU General Public License version 2, as published by the
  11. * Free Software Foundation. See the file LICENSE.html for more information.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
  19. * Place, Suite 330 / Boston, MA 02111-1307 / USA.
  20. *
  21. * ===============================================================================
  22. */
  23. package org.infoglue.cms.controllers.kernel.impl.simple;
  24. import java.io.ByteArrayOutputStream;
  25. import java.io.File;
  26. import java.io.FileInputStream;
  27. import java.io.IOException;
  28. import java.io.InputStream;
  29. import java.io.OutputStreamWriter;
  30. import java.io.StringReader;
  31. import java.io.Writer;
  32. import java.nio.channels.OverlappingFileLockException;
  33. import java.util.ArrayList;
  34. import java.util.Calendar;
  35. import java.util.Collection;
  36. import java.util.Date;
  37. import java.util.HashMap;
  38. import java.util.HashSet;
  39. import java.util.Iterator;
  40. import java.util.List;
  41. import java.util.Map;
  42. import java.util.Set;
  43. import java.util.concurrent.atomic.AtomicBoolean;
  44. import org.apache.log4j.Level;
  45. import org.apache.log4j.Logger;
  46. import org.apache.lucene.analysis.Analyzer;
  47. import org.apache.lucene.analysis.standard.StandardAnalyzer;
  48. import org.apache.lucene.document.DateTools;
  49. import org.apache.lucene.document.Document;
  50. import org.apache.lucene.document.Field;
  51. import org.apache.lucene.document.NumericField;
  52. import org.apache.lucene.index.IndexReader;
  53. import org.apache.lucene.index.IndexWriter;
  54. import org.apache.lucene.index.IndexWriterConfig;
  55. import org.apache.lucene.index.Term;
  56. import org.apache.lucene.queryParser.MultiFieldQueryParser;
  57. import org.apache.lucene.queryParser.QueryParser;
  58. import org.apache.lucene.search.BooleanClause;
  59. import org.apache.lucene.search.IndexSearcher;
  60. import org.apache.lucene.search.Query;
  61. import org.apache.lucene.search.ScoreDoc;
  62. import org.apache.lucene.search.Sort;
  63. import org.apache.lucene.search.TermQuery;
  64. import org.apache.lucene.search.TopDocs;
  65. import org.apache.lucene.store.Directory;
  66. import org.apache.lucene.store.NIOFSDirectory;
  67. import org.apache.lucene.store.SingleInstanceLockFactory;
  68. import org.apache.lucene.util.Version;
  69. import org.apache.poi.hwpf.HWPFDocument;
  70. import org.apache.poi.hwpf.extractor.WordExtractor;
  71. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  72. import org.exolab.castor.jdo.Database;
  73. import org.exolab.castor.jdo.OQLQuery;
  74. import org.exolab.castor.jdo.QueryResults;
  75. import org.infoglue.cms.applications.databeans.ProcessBean;
  76. import org.infoglue.cms.entities.content.Content;
  77. import org.infoglue.cms.entities.content.ContentCategory;
  78. import org.infoglue.cms.entities.content.ContentVO;
  79. import org.infoglue.cms.entities.content.ContentVersion;
  80. import org.infoglue.cms.entities.content.ContentVersionVO;
  81. import org.infoglue.cms.entities.content.DigitalAsset;
  82. import org.infoglue.cms.entities.content.DigitalAssetVO;
  83. import org.infoglue.cms.entities.content.SmallestContentVersionVO;
  84. import org.infoglue.cms.entities.content.impl.simple.ContentImpl;
  85. import org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl;
  86. import org.infoglue.cms.entities.content.impl.simple.DigitalAssetImpl;
  87. import org.infoglue.cms.entities.content.impl.simple.MediumDigitalAssetImpl;
  88. import org.infoglue.cms.entities.content.impl.simple.SmallestContentVersionImpl;
  89. import org.infoglue.cms.entities.kernel.BaseEntityVO;
  90. import org.infoglue.cms.entities.management.CategoryAttribute;
  91. import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
  92. import org.infoglue.cms.entities.management.LanguageVO;
  93. import org.infoglue.cms.entities.structure.SiteNode;
  94. import org.infoglue.cms.entities.structure.SiteNodeVO;
  95. import org.infoglue.cms.entities.structure.SiteNodeVersion;
  96. import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
  97. import org.infoglue.cms.entities.structure.impl.simple.PureSiteNodeImpl;
  98. import org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl;
  99. import org.infoglue.cms.entities.structure.impl.simple.SiteNodeVersionImpl;
  100. import org.infoglue.cms.entities.structure.impl.simple.SmallSiteNodeImpl;
  101. import org.infoglue.cms.exception.SystemException;
  102. import org.infoglue.cms.util.CmsPropertyHandler;
  103. import org.infoglue.cms.util.NotificationListener;
  104. import org.infoglue.cms.util.NotificationMessage;
  105. import org.infoglue.deliver.util.CacheController;
  106. import org.infoglue.deliver.util.RequestAnalyser;
  107. import org.infoglue.deliver.util.Timer;
  108. import org.pdfbox.pdmodel.PDDocument;
  109. import org.pdfbox.util.PDFTextStripper;
  110. public class LuceneController extends BaseController implements NotificationListener
  111. {
  112. private static Directory directory = null;
  113. private static IndexWriter writer = null;
  114. private static IndexReader indexReader = null;
  115. private static int reopened = 0;
  116. private final static Logger logger = Logger.getLogger(LuceneController.class.getName());
  117. private static int indexedDocumentsSinceLastOptimize = 0;
  118. private Integer lastCommitedContentVersionId = -1;
  119. private static Integer numberOfVersionToIndexInBatch = 1000;
  120. private static AtomicBoolean indexingInitialized = new AtomicBoolean(false);
  121. private static AtomicBoolean stopIndexing = new AtomicBoolean(false);
  122. private static AtomicBoolean deleteIndexOnStop = new AtomicBoolean(false);
  123. public static void setNumberOfVersionToIndexInBatch(Integer numberOfVersionToIndexInBatch)
  124. {
  125. numberOfVersionToIndexInBatch = numberOfVersionToIndexInBatch;
  126. }
  127. public static void stopIndexing()
  128. {
  129. stopIndexing.set(true);
  130. }
  131. /**
  132. * Default Constructor
  133. */
  134. public static LuceneController getController()
  135. {
  136. return new LuceneController();
  137. }
  138. private static List<NotificationMessage> qeuedMessages = new ArrayList<NotificationMessage>();
  139. private static List<NotificationMessage> maturedQeuedMessages = new ArrayList<NotificationMessage>();
  140. private StandardAnalyzer getStandardAnalyzer() throws Exception
  141. {
  142. return new StandardAnalyzer(Version.LUCENE_34);
  143. }
  144. private Directory getDirectory() throws Exception
  145. {
  146. if(LuceneController.directory != null)
  147. return directory;
  148. String index = CmsPropertyHandler.getContextDiskPath() + File.separator + "lucene" + File.separator + "index";
  149. index = index.replaceAll("//", "/");
  150. //System.out.println("index:" + index);
  151. File INDEX_DIR = new File(index);
  152. directory = new NIOFSDirectory(INDEX_DIR);
  153. directory.setLockFactory(new SingleInstanceLockFactory());
  154. boolean indexExists = IndexReader.indexExists(directory);
  155. if(!indexExists)
  156. {
  157. createIndex(directory);
  158. }
  159. return directory;
  160. }
  161. private void createIndex(Directory directory) throws Exception
  162. {
  163. IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_34, getStandardAnalyzer());
  164. IndexWriter indexWriter = new IndexWriter(directory, config);
  165. indexWriter.deleteDocuments(new Term("initializer", "true"));
  166. indexWriter.close(true);
  167. }
  168. private IndexWriter getIndexWriter() throws Exception
  169. {
  170. //Singleton returns
  171. if(writer != null)
  172. return writer;
  173. Timer t = new Timer();
  174. Directory directory = getDirectory();
  175. StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
  176. IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_34, analyzer);
  177. if(getIsIndexedLocked(true))
  178. {
  179. logger.warn("Directory is locked - leaving the messages in the qeuedMessages list...");
  180. throw new Exception("Lock not granted");
  181. }
  182. else
  183. {
  184. writer = new IndexWriter(directory, config);
  185. return writer;
  186. }
  187. }
  188. private IndexReader getIndexReader() throws Exception
  189. {
  190. if(indexReader == null)
  191. {
  192. indexReader = IndexReader.open(getDirectory(), true);
  193. }
  194. synchronized (indexReader)
  195. {
  196. if(!indexReader.isCurrent())
  197. {
  198. reopened++;
  199. indexReader.close();
  200. indexReader = IndexReader.open(getDirectory(), true);
  201. //indexReader = IndexReader.openIfChanged(indexReader, true);
  202. logger.info("reopened:" + reopened);
  203. }
  204. }
  205. return indexReader;
  206. }
  207. private IndexSearcher getIndexSearcher() throws Exception
  208. {
  209. return new IndexSearcher(getIndexReader());
  210. }
  211. private Boolean getIsIndexedLocked() throws Exception
  212. {
  213. return getIsIndexedLocked(false);
  214. }
  215. private Boolean getIsIndexedLocked(boolean returnIfFileLockException) throws Exception
  216. {
  217. Directory directory = getDirectory();
  218. try
  219. {
  220. return IndexWriter.isLocked(directory);
  221. }
  222. catch (OverlappingFileLockException e)
  223. {
  224. return returnIfFileLockException;
  225. }
  226. }
  227. private void unlockIndex() throws Exception
  228. {
  229. Directory directory = getDirectory();
  230. IndexWriter.unlock(directory);
  231. }
  232. public Map<String,Object> getIndexInformation() throws Exception
  233. {
  234. Map<String,Object> info = new HashMap<String,Object>();
  235. try
  236. {
  237. Directory directory = getDirectory();
  238. IndexReader reader = getIndexReader();
  239. int maxDoc = reader.maxDoc();
  240. int numDoc = reader.numDocs();
  241. long lastModified = getIndexReader().lastModified(directory);
  242. info.put("maxDoc", new Integer(maxDoc));
  243. info.put("numDoc", new Integer(numDoc));
  244. info.put("lastModified", new Date(lastModified));
  245. info.put("lastCommitedContentVersionId", getLastCommitedContentVersionId());
  246. List<LanguageVO> languageVOList = LanguageController.getController().getLanguageVOList();
  247. Iterator<LanguageVO> languageVOListIterator = languageVOList.iterator();
  248. outer:while(languageVOListIterator.hasNext())
  249. {
  250. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  251. info.put("indexAllLastCommittedContentVersionId_" + languageVO.getId(), getIndexAllLastCommittedContentVersionId(languageVO.getId()));
  252. info.put("indexAllLastCommittedMetaContentVersionId_" + languageVO.getId(), getIndexAllLastCommittedMetaContentVersionId(languageVO.getId()));
  253. }
  254. //reader.close();
  255. //directory.close();
  256. }
  257. catch (Exception e)
  258. {
  259. logger.error("Error creating index:" + e.getMessage(), e);
  260. throw e;
  261. }
  262. return info;
  263. }
  264. public Integer getIndexAllLastCommittedContentVersionId(Integer languageId) throws Exception
  265. {
  266. Integer indexAllLastCommittedContentVersionId = null;
  267. try
  268. {
  269. Document indexAllDocumentMetaData = getIndexAllStatusDocument();
  270. if(indexAllDocumentMetaData != null && indexAllDocumentMetaData.get("lastCommitedContentVersionId_" + languageId) != null && !indexAllDocumentMetaData.get("lastCommitedContentVersionId_" + languageId).equals("null"))
  271. indexAllLastCommittedContentVersionId = new Integer(indexAllDocumentMetaData.get("lastCommitedContentVersionId_" + languageId));
  272. }
  273. catch (Exception e)
  274. {
  275. logger.error("Error creating index:" + e.getMessage(), e);
  276. throw e;
  277. }
  278. return indexAllLastCommittedContentVersionId;
  279. }
  280. public Integer getIndexAllLastCommittedMetaContentVersionId(Integer languageId) throws Exception
  281. {
  282. Integer indexAllLastCommittedSiteNodeVersionId = null;
  283. try
  284. {
  285. Document indexAllDocumentMetaData = getIndexAllStatusDocument();
  286. if(indexAllDocumentMetaData != null && indexAllDocumentMetaData.get("lastCommitedMetaContentVersionId_" + languageId) != null && !indexAllDocumentMetaData.get("lastCommitedMetaContentVersionId_" + languageId).equals("null"))
  287. indexAllLastCommittedSiteNodeVersionId = new Integer(indexAllDocumentMetaData.get("lastCommitedMetaContentVersionId_" + languageId));
  288. }
  289. catch (Exception e)
  290. {
  291. logger.error("Error creating index:" + e.getMessage(), e);
  292. throw e;
  293. }
  294. return indexAllLastCommittedSiteNodeVersionId;
  295. }
  296. public Document createStatusDocument(Integer lastCommitedContentVersionId) throws Exception
  297. {
  298. Document doc = new Document();
  299. doc.add(new Field("lastCommitedContentVersionId", "" + lastCommitedContentVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  300. doc.add(new Field("lastCommitedModifiedDate", "" + new Date().getTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  301. doc.add(new Field("meta", new StringReader("lastCommitedContentVersionId")));
  302. return doc;
  303. }
  304. public Document getStatusDocument() throws Exception
  305. {
  306. List<Document> docs = queryDocuments("meta", "lastCommitedContentVersionId", 5);
  307. logger.info(docs.size() + " total matching documents for 'lastCommitedContentVersionId'");
  308. return (docs != null && docs.size() > 0 ? docs.get(0) : null);
  309. }
  310. public Document getIndexAllStatusDocument() throws Exception
  311. {
  312. List<Document> docs = queryDocuments(new Term("meta", "indexAllRunning"), 5);
  313. logger.info(docs.size() + " total matching documents for 'indexAllRunning'");
  314. return (docs != null && docs.size() > 0 ? docs.get(0) : null);
  315. }
  316. public Integer getLastCommitedContentVersionId() throws Exception
  317. {
  318. Integer lastCommitedContentVersionId = -1;
  319. Document doc = getStatusDocument();
  320. logger.info("STATUS doc:" + doc);
  321. if(doc != null)
  322. {
  323. String lastCommitedContentVersionIdString = doc.get("lastCommitedContentVersionId");
  324. logger.info("doc:" + doc);
  325. logger.info("lastCommitedContentVersionId:" + lastCommitedContentVersionIdString);
  326. lastCommitedContentVersionId = Integer.parseInt(lastCommitedContentVersionIdString);
  327. }
  328. return lastCommitedContentVersionId;
  329. }
  330. private void setLastCommitedContentVersionId(IndexWriter writer, Integer lastCommitedContentVersionId) throws Exception
  331. {
  332. Integer prevLastCommitedContentVersionId = getLastCommitedContentVersionId();
  333. logger.info("prevLastCommitedContentVersionId:" + prevLastCommitedContentVersionId);
  334. logger.info("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  335. if(lastCommitedContentVersionId == -1 || prevLastCommitedContentVersionId > lastCommitedContentVersionId)
  336. return;
  337. logger.info("setLastCommitedContentVersionId:" + lastCommitedContentVersionId);
  338. Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("lastCommitedContentVersionId");
  339. writer.deleteDocuments(query);
  340. writer.addDocument(createStatusDocument(lastCommitedContentVersionId));
  341. }
  342. public Date getLastCommitedModifiedDate() throws Exception
  343. {
  344. Date lastCommitedModifiedDate = new Date(10000);
  345. Document doc = getStatusDocument();
  346. if(doc != null)
  347. {
  348. String lastCommitedModifiedDateString = doc.get("lastCommitedModifiedDate");
  349. logger.info("doc:" + doc);
  350. logger.info("lastCommitedModifiedDate:" + lastCommitedModifiedDateString);
  351. Date d = new Date();
  352. d.setTime(Long.parseLong(lastCommitedModifiedDateString));
  353. lastCommitedModifiedDate = d;
  354. }
  355. return lastCommitedModifiedDate;
  356. }
  357. private void registerIndexAllProcessOngoing(Integer lastCommitedContentVersionId, Integer lastCommitedSiteNodeVersionId, Integer languageId) throws Exception
  358. {
  359. //Document doc = new Document();
  360. IndexWriter writer = getIndexWriter();
  361. IndexSearcher searcher = getIndexSearcher();
  362. Term term = new Term("meta", "indexAllRunning");
  363. TermQuery query = new TermQuery(term);
  364. //Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("indexAllRunning");
  365. TopDocs hits = searcher.search(query, 50);
  366. //System.out.println("hits:" + hits);
  367. //System.out.println("hits.scoreDocs.length:" + hits.scoreDocs.length);
  368. if(hits.scoreDocs.length > 1)
  369. System.out.println("Must be wrong - should only be one of these docs:" + hits.scoreDocs.length);
  370. if(hits.scoreDocs.length > 0)
  371. {
  372. for(ScoreDoc scoreDoc : hits.scoreDocs)
  373. {
  374. org.apache.lucene.document.Document docExisting = searcher.doc(scoreDoc.doc);
  375. //System.out.println("Updating doc...:" + docExisting);
  376. //System.out.println("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  377. //System.out.println("lastCommitedSiteNodeVersionId:" + lastCommitedSiteNodeVersionId);
  378. //System.out.println("languageId:" + languageId);
  379. if(lastCommitedContentVersionId != null && lastCommitedContentVersionId != -1)
  380. {
  381. docExisting.removeFields("lastCommitedContentVersionId_" + languageId);
  382. docExisting.add(new Field("lastCommitedContentVersionId_" + languageId, "" + lastCommitedContentVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  383. }
  384. if(lastCommitedSiteNodeVersionId != null && lastCommitedSiteNodeVersionId != -1)
  385. {
  386. docExisting.removeFields("lastCommitedMetaContentVersionId_" + languageId);
  387. docExisting.add(new Field("lastCommitedMetaContentVersionId_" + languageId, "" + lastCommitedSiteNodeVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  388. }
  389. docExisting.removeFields("lastCommitedModifiedDate");
  390. docExisting.add(new Field("lastCommitedModifiedDate", "" + new Date().getTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  391. //docExisting.add(new Field("meta", new StringReader("indexAllRunning")));
  392. //docExisting.add(new Field("meta", "indexAllRunning", Field.Store.YES, Field.Index.NOT_ANALYZED));
  393. writer.updateDocument(term, docExisting);
  394. //System.out.println("Updating doc...:" + docExisting);
  395. //Term t = new Term("meta", "indexAllRunning");
  396. break;
  397. }
  398. }
  399. else
  400. {
  401. Document docExisting = new Document();
  402. //System.out.println("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  403. //System.out.println("lastCommitedSiteNodeVersionId:" + lastCommitedSiteNodeVersionId);
  404. //System.out.println("languageId:" + languageId);
  405. if(lastCommitedContentVersionId != null)
  406. docExisting.add(new Field("lastCommitedContentVersionId_" + languageId, "" + lastCommitedContentVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  407. if(lastCommitedSiteNodeVersionId != null)
  408. docExisting.add(new Field("lastCommitedMetaContentVersionId_" + languageId, "" + lastCommitedSiteNodeVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  409. docExisting.add(new Field("lastCommitedModifiedDate", "" + new Date().getTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  410. //docExisting.add(new Field("meta", new StringReader("indexAllRunning")));
  411. docExisting.add(new Field("meta", "indexAllRunning", Field.Store.YES, Field.Index.NOT_ANALYZED));
  412. writer.addDocument(docExisting);
  413. }
  414. searcher.close();
  415. //Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("indexAllRunning");
  416. //writer.deleteDocuments(query);
  417. //writer.updateDocument(term, doc);
  418. //writer.addDocument(doc);
  419. //writer.close(true);
  420. writer.commit();
  421. }
  422. private void registerIndexAllProcessDone() throws Exception
  423. {
  424. IndexWriter writer = getIndexWriter();
  425. //Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("indexAllRunning");
  426. Term term = new Term("meta", "indexAllRunning");
  427. TermQuery query = new TermQuery(term);
  428. writer.deleteDocuments(query);
  429. writer.commit();
  430. }
  431. public void clearIndex() throws Exception
  432. {
  433. if (indexingInitialized.compareAndSet(false, true))
  434. {
  435. logger.warn("Clearing index..");
  436. try
  437. {
  438. logger.info("NumDocs:" + getIndexReader().numDocs());
  439. IndexWriter writer = getIndexWriter();
  440. writer.deleteAll();
  441. //writer.close(true);
  442. writer.commit();
  443. logger.info("NumDocs after delete:" + getIndexReader().numDocs());
  444. }
  445. catch (Exception e)
  446. {
  447. stopIndexing.set(true);
  448. deleteIndexOnStop.set(true);
  449. logger.error("Error clearing index:" + e.getMessage(), e);
  450. }
  451. finally
  452. {
  453. logger.info("Releasing indexing flag");
  454. this.indexingInitialized.set(false);
  455. stopIndexing.set(false);
  456. }
  457. }
  458. else
  459. {
  460. stopIndexing.set(true);
  461. deleteIndexOnStop.set(true);
  462. logger.error("Could not delete index while indexing. Queueing it....");
  463. }
  464. }
  465. public TopDocs query(String text, Integer numberOfHits) throws Exception
  466. {
  467. return query("contents", text, numberOfHits);
  468. }
  469. public TopDocs query(String field, String text, Integer numberOfHits) throws Exception
  470. {
  471. IndexSearcher searcher = getIndexSearcher();
  472. Query query = new QueryParser(Version.LUCENE_34, "contents", getStandardAnalyzer()).parse(text);
  473. TopDocs hits = searcher.search(query, numberOfHits);
  474. logger.info(hits.totalHits + " total matching documents for '" + text + "'");
  475. return hits;
  476. }
  477. public List<Document> queryDocuments(Term term, Integer numberOfHits) throws Exception
  478. {
  479. IndexSearcher searcher = getIndexSearcher();
  480. Query query = new TermQuery(term);
  481. TopDocs hits = searcher.search(query, numberOfHits);
  482. logger.info(hits.totalHits + " total matching documents for '" + term.field() + ":" + term.text() + "'");
  483. List<Document> docs = new ArrayList<Document>();
  484. for(ScoreDoc scoreDoc : hits.scoreDocs)
  485. {
  486. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  487. docs.add(doc);
  488. }
  489. searcher.close();
  490. return docs;
  491. }
  492. public List<Document> queryDocuments(String field, String text, Integer numberOfHits) throws Exception
  493. {
  494. IndexSearcher searcher = getIndexSearcher();
  495. Query query = new QueryParser(Version.LUCENE_34, field, getStandardAnalyzer()).parse(text);
  496. logger.info("query:" + query);
  497. TopDocs hits = searcher.search(query, numberOfHits);
  498. logger.info(hits.totalHits + " total matching documents for '" + field + ":" + text + "'");
  499. List<Document> docs = new ArrayList<Document>();
  500. for(ScoreDoc scoreDoc : hits.scoreDocs)
  501. {
  502. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  503. docs.add(doc);
  504. }
  505. searcher.close();
  506. return docs;
  507. }
  508. public TopDocs query(String[] fields, BooleanClause.Occur[] flags, String[] queries, Sort sort, Integer numberOfHits) throws Exception
  509. {
  510. IndexSearcher searcher = getIndexSearcher();
  511. Query query = MultiFieldQueryParser.parse(Version.LUCENE_34, queries, fields, flags, getStandardAnalyzer());
  512. //Query query = new QueryParser(Version.LUCENE_34, "contents", getStandardAnalyzer()).parse(text);
  513. TopDocs hits = searcher.search(query, numberOfHits);
  514. logger.info(hits.totalHits + " total matching documents for '" + queries + "'");
  515. return hits;
  516. }
  517. public List<Document> queryDocuments(String[] fields, BooleanClause.Occur[] flags, String[] queries, Sort sort, Integer numberOfHits, Map searchMetaData) throws Exception
  518. {
  519. IndexSearcher searcher = getIndexSearcher();
  520. Query query = MultiFieldQueryParser.parse(Version.LUCENE_34, queries, fields, flags, getStandardAnalyzer());
  521. logger.info("query:" + query);
  522. //Query query = new QueryParser(Version.LUCENE_34, "contents", getStandardAnalyzer()).parse(text);
  523. TopDocs hits = searcher.search(query, numberOfHits);
  524. searchMetaData.put("totalHits", hits.totalHits);
  525. logger.info(hits.totalHits + " total matching documents for '" + query + "'");
  526. //System.out.println(hits.totalHits + " total matching documents for '" + queries + "'");
  527. List<Document> docs = new ArrayList<Document>();
  528. for(ScoreDoc scoreDoc : hits.scoreDocs)
  529. {
  530. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  531. docs.add(doc);
  532. }
  533. searcher.close();
  534. return docs;
  535. }
  536. private void query(IndexSearcher searcher, Analyzer analyzer, String text) throws Exception
  537. {
  538. Query query = new QueryParser(Version.LUCENE_34, "contents", analyzer).parse(text);
  539. TopDocs hits = searcher.search(query, 50);
  540. logger.info(hits.totalHits + " total matching documents for '" + text + "'");
  541. for(ScoreDoc scoreDoc : hits.scoreDocs)
  542. {
  543. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  544. String cvId = doc.get("contentVersionId");
  545. logger.info("cvId: " + cvId);
  546. }
  547. }
  548. public boolean indexAll() throws Exception
  549. {
  550. if(!CmsPropertyHandler.getInternalSearchEngine().equalsIgnoreCase("lucene"))
  551. return false;
  552. logger.warn("INDEXING ALL - correct: " + indexingInitialized + "/" + deleteIndexOnStop + "/" + stopIndexing + "?");
  553. Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  554. if(deleteIndexOnStop.get())
  555. {
  556. clearIndex();
  557. deleteIndexOnStop.set(false);
  558. stopIndexing.set(false);
  559. }
  560. else
  561. {
  562. stopIndexing.set(false);
  563. }
  564. logger.warn("Resetting stopIndexing to false....");
  565. logger.warn("------------------------------Got indexAll directive....");
  566. if (indexingInitialized.compareAndSet(false, true))
  567. {
  568. //createTestIndex();
  569. //indexingInitialized.set(false);
  570. //if(true)
  571. // return true;
  572. try
  573. {
  574. Timer t = new Timer();
  575. Timer t2 = new Timer();
  576. //Indexing all normal contents now
  577. logger.info("Indexing all normal contents: " + CmsPropertyHandler.getContextDiskPath());
  578. List<LanguageVO> languageVOList = LanguageController.getController().getLanguageVOList();
  579. Iterator<LanguageVO> languageVOListIterator = languageVOList.iterator();
  580. outer:while(languageVOListIterator.hasNext())
  581. {
  582. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  583. logger.info("Getting notification messages for " + languageVO.getName());
  584. Integer previousIndexAllLastContentVersionId = getIndexAllLastCommittedContentVersionId(languageVO.getId());
  585. int startID = 0;
  586. if(previousIndexAllLastContentVersionId != null)
  587. startID = previousIndexAllLastContentVersionId;
  588. logger.info("Starting from " + startID);
  589. int newLastContentVersionId = getContentNotificationMessages(languageVO, startID);
  590. logger.info("newLastContentVersionId: " + newLastContentVersionId + " on " + languageVO.getName());
  591. registerIndexAllProcessOngoing(newLastContentVersionId, null, languageVO.getId());
  592. //previousIndexAllLastContentVersionId = newLastContentVersionId;
  593. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessages", t.getElapsedTime());
  594. logger.info("newLastContentVersionId " + newLastContentVersionId);
  595. while(newLastContentVersionId != -1)
  596. {
  597. logger.info("stopIndexing.get():" + stopIndexing.get());
  598. if(stopIndexing.get())
  599. break outer;
  600. Thread.sleep(5000);
  601. newLastContentVersionId = getContentNotificationMessages(languageVO, newLastContentVersionId);
  602. logger.info("newLastContentVersionId: " + newLastContentVersionId + " on " + languageVO.getName());
  603. registerIndexAllProcessOngoing(newLastContentVersionId, null, languageVO.getId());
  604. //previousIndexAllLastContentVersionId = newLastContentVersionId;
  605. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessages 2", t.getElapsedTime());
  606. logger.info("newLastContentVersionId " + newLastContentVersionId);
  607. }
  608. }
  609. languageVOList = LanguageController.getController().getLanguageVOList();
  610. languageVOListIterator = languageVOList.iterator();
  611. outer:while(languageVOListIterator.hasNext())
  612. {
  613. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  614. logger.info("languageVO from " + languageVO);
  615. List<NotificationMessage> notificationMessages = new ArrayList<NotificationMessage>();
  616. Integer previousIndexAllLastMetaContentVersionId = getIndexAllLastCommittedMetaContentVersionId(languageVO.getId());
  617. logger.info("previousIndexAllLastMetaContentVersionId: " + previousIndexAllLastMetaContentVersionId);
  618. int startID = 0;
  619. if(previousIndexAllLastMetaContentVersionId != null)
  620. startID = previousIndexAllLastMetaContentVersionId;
  621. logger.info("Starting from " + startID);
  622. int newLastMetaContentVersionId = getPageNotificationMessages(notificationMessages, languageVO, startID);
  623. logger.info("newLastSiteNodeVersionId " + newLastMetaContentVersionId + " on " + languageVO.getName());
  624. logger.info("notificationMessages: " + notificationMessages.size());
  625. registerIndexAllProcessOngoing(null, newLastMetaContentVersionId, languageVO.getId());
  626. //previousIndexAllLastMetaContentVersionId = newLastMetaContentVersionId;
  627. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessagesForStructure", t.getElapsedTime());
  628. logger.info("newLastMetaContentVersionId " + newLastMetaContentVersionId);
  629. while(newLastMetaContentVersionId != -1)
  630. {
  631. logger.info("stopIndexing.get():" + stopIndexing.get());
  632. if(stopIndexing.get())
  633. break outer;
  634. Thread.sleep(5000);
  635. newLastMetaContentVersionId = getPageNotificationMessages(notificationMessages, languageVO, newLastMetaContentVersionId);
  636. logger.info("newLastMetaContentVersionId " + newLastMetaContentVersionId + " on " + languageVO.getName());
  637. logger.info("notificationMessages: " + notificationMessages.size());
  638. registerIndexAllProcessOngoing(null, newLastMetaContentVersionId, languageVO.getId());
  639. //previousIndexAllLastMetaContentVersionId = newLastMetaContentVersionId;
  640. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessages 2", t.getElapsedTime());
  641. logger.info("newLastMetaContentVersionId " + newLastMetaContentVersionId);
  642. }
  643. }
  644. registerIndexAllProcessDone();
  645. t2.printElapsedTime("All indexing took");
  646. }
  647. catch (Exception e)
  648. {
  649. logger.error("Error indexing notifications:" + e.getMessage(), e);
  650. }
  651. finally
  652. {
  653. logger.error("Releasing indexing flag");
  654. this.indexingInitialized.set(false);
  655. }
  656. }
  657. else
  658. {
  659. logger.warn("-------------------: Allready running index all...");
  660. return false;
  661. }
  662. return true;
  663. }
  664. private void createTestIndex()
  665. {
  666. System.out.println("STARTING TEST");
  667. try
  668. {
  669. clearIndex();
  670. IndexWriter writer = getIndexWriter();
  671. for(int i=0; i<10000; i++)
  672. {
  673. // make a new, empty document
  674. Document doc = new Document();
  675. doc.add(new NumericField("publishDateTime", Field.Store.YES, true).setLongValue(23423423423L));
  676. doc.add(new NumericField("modificationDateTime", Field.Store.YES, true).setLongValue(23423423423L));
  677. doc.add(new Field("modified", DateTools.timeToString(23423423423L, DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  678. doc.add(new Field("contentVersionId", "324234234", Field.Store.YES, Field.Index.NOT_ANALYZED));
  679. doc.add(new Field("contentId", "324234234", Field.Store.YES, Field.Index.NOT_ANALYZED));
  680. doc.add(new Field("contentTypeDefinitionId", "344", Field.Store.YES, Field.Index.NOT_ANALYZED));
  681. doc.add(new Field("languageId", "33", Field.Store.YES, Field.Index.NOT_ANALYZED));
  682. doc.add(new Field("repositoryId", "22", Field.Store.YES, Field.Index.NOT_ANALYZED));
  683. doc.add(new Field("lastModifier", "Mattias Bogeblad", Field.Store.YES, Field.Index.NOT_ANALYZED));
  684. doc.add(new Field("stateId", "3", Field.Store.YES, Field.Index.NOT_ANALYZED));
  685. doc.add(new Field("isAsset", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  686. doc.add(new Field("contents", new StringReader(i + " fwe foweif oiwejfoijweoifiweuhfi uehwiufh weiuhfiuwehfiew iufiuwehfi ewiufh iuwehfiuehwiufiweuhfiu ehwifhw eifew efiwehfiuwe" +
  687. "ff wehfiuehwiufiuwehfiuehw iufhwei uhfiehwiufweiuhf iwefihw eifiuwe ifhwe ifihew iufi weuhfiuwe" +
  688. "dfbsdjfsjdjfjksdf s f jdsjkfs dkjfh ksdfk sdkfhkds fksd " +
  689. "fjsd fsdhf uiweo p fiieowhf iehwiufiewhfiewfhw efn ewfowe ifioewf owehfowe")));
  690. doc.add(new Field("uid", "" + i, Field.Store.NO, Field.Index.NOT_ANALYZED));
  691. writer.addDocument(doc);
  692. if(i == 1000 || i == 2000 ||i == 3000 ||i == 4000 ||i == 5000 ||i == 6000 ||i == 7000 ||i == 8000 ||i == 9000)
  693. {
  694. //writer.optimize();
  695. //writer.optimize(true);
  696. logger.info("Sleeping...:" + getIndexInformation().get("numDoc"));
  697. Thread.sleep(5000);
  698. }
  699. }
  700. //writer.close(true);
  701. writer.commit();
  702. }
  703. catch (Exception e)
  704. {
  705. e.printStackTrace();
  706. }
  707. }
  708. /**
  709. * This method gets called when a new notification has come.
  710. * It then iterates through the listeners and notifies them.
  711. */
  712. public void addNotificationMessage(NotificationMessage notificationMessage)
  713. {
  714. if(notificationMessage.getClassName().equals(ContentImpl.class.getName()) ||
  715. notificationMessage.getClassName().equals(ContentVersionImpl.class.getName()) ||
  716. notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) ||
  717. notificationMessage.getClassName().equals(PureSiteNodeImpl.class.getName()) ||
  718. notificationMessage.getClassName().equals(SmallSiteNodeImpl.class.getName()) ||
  719. notificationMessage.getClassName().equals(SiteNodeVersionImpl.class.getName()) ||
  720. notificationMessage.getClassName().equals(DigitalAssetImpl.class.getName()) ||
  721. notificationMessage.getClassName().equals(MediumDigitalAssetImpl.class.getName()))
  722. {
  723. if(qeuedMessages.size() == 1000)
  724. {
  725. logger.warn("qeuedMessages went over 1000 - seems wrong");
  726. //Thread.dumpStack();
  727. }
  728. synchronized (qeuedMessages)
  729. {
  730. qeuedMessages.add(notificationMessage);
  731. }
  732. }
  733. else
  734. {
  735. logger.info("Skipping indexing:" + notificationMessage.getClassName());
  736. }
  737. }
  738. /**
  739. * This method gets called when a new NotificationMessage is available.
  740. * The writer just calls the transactionHistoryController which stores it.
  741. */
  742. public void notify(NotificationMessage notificationMessage)
  743. {
  744. try
  745. {
  746. if(logger.isInfoEnabled())
  747. logger.info("Indexing:" + notificationMessage.getName() + ":" + notificationMessage.getType() + ":" + notificationMessage.getObjectId() + ":" + notificationMessage.getObjectName());
  748. addNotificationMessage(notificationMessage);
  749. }
  750. catch(Exception e)
  751. {
  752. logger.error("Error notifying: " + e.getMessage());
  753. }
  754. }
  755. public void process() throws Exception
  756. {
  757. logger.info("Process inside LuceneController");
  758. notifyListeners(false, true);
  759. }
  760. public void notifyListeners(boolean forceVersionIndexing, boolean checkForIndexingJobs) throws IOException, Exception
  761. {
  762. if(!CmsPropertyHandler.getInternalSearchEngine().equalsIgnoreCase("lucene") || CmsPropertyHandler.getContextDiskPath().contains("@deploy.dir"))
  763. return;
  764. boolean initDoneLocally = false;
  765. boolean finishDoneLocally = false;
  766. logger.info("------------------------------->notifyListeners before check in " + CmsPropertyHandler.getContextRootPath() + "/" + deleteIndexOnStop.get() + "/" + stopIndexing.get());
  767. if(deleteIndexOnStop.get())
  768. {
  769. clearIndex();
  770. deleteIndexOnStop.set(false);
  771. stopIndexing.set(false);
  772. }
  773. else
  774. {
  775. stopIndexing.set(false);
  776. }
  777. if (!checkForIndexingJobs || indexingInitialized.compareAndSet(false, true))
  778. {
  779. if(checkForIndexingJobs)
  780. initDoneLocally = true;
  781. List<NotificationMessage> internalMessageList = new ArrayList<NotificationMessage>();
  782. List<NotificationMessage> revisitedInternalMessageList = new ArrayList<NotificationMessage>();
  783. synchronized (qeuedMessages)
  784. {
  785. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  786. internalMessageList.addAll(qeuedMessages);
  787. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  788. qeuedMessages.clear();
  789. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  790. }
  791. synchronized (maturedQeuedMessages)
  792. {
  793. logger.info("maturedQeuedMessages:" + maturedQeuedMessages.size());
  794. if(maturedQeuedMessages.size() > 0)
  795. {
  796. logger.info("Was a matured message - let's take it also");
  797. internalMessageList.addAll(maturedQeuedMessages);
  798. revisitedInternalMessageList.addAll(maturedQeuedMessages);
  799. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  800. maturedQeuedMessages.clear();
  801. }
  802. }
  803. //Should implement equals on NotificationMessage later
  804. List<NotificationMessage> baseEntitiesToIndexMessageList = new ArrayList<NotificationMessage>();
  805. List<String> existingSignatures = new ArrayList<String>();
  806. logger.info("Before AAAAA:" + internalMessageList.size() + ":" + existingSignatures.size());
  807. Iterator<NotificationMessage> cleanupInternalMessageListIterator = internalMessageList.iterator();
  808. while(cleanupInternalMessageListIterator.hasNext())
  809. {
  810. NotificationMessage notificationMessage = cleanupInternalMessageListIterator.next();
  811. logger.info("Indexing........:" + notificationMessage.getClassName());
  812. if(notificationMessage.getClassName().equals(ContentImpl.class.getName()) || notificationMessage.getClassName().equals(Content.class.getName()))
  813. {
  814. ContentVO contentVO = ContentController.getContentController().getLocklessContentVOWithId((Integer)notificationMessage.getObjectId());
  815. //ContentVO contentVO = ContentController.getContentController().getContentVOWithId((Integer)notificationMessage.getObjectId());
  816. if(contentVO != null)
  817. {
  818. ContentTypeDefinitionVO ctdVO = null;
  819. try
  820. {
  821. ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId());
  822. }
  823. catch (SystemException sex)
  824. {
  825. logger.warn("Failed to get the content type definition for content with Id: " + contentVO.getContentId() + ". The content will not be indexed. Message: " + sex.getMessage());
  826. logger.info("Failed to get the content type definition for content with Id: " + contentVO.getContentId(), sex);
  827. }
  828. if(ctdVO != null && ctdVO.getName().equals("Meta info"))
  829. {
  830. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithMetaInfoContentId(contentVO.getContentId());
  831. if(siteNodeVO != null && notificationMessage != null)
  832. {
  833. NotificationMessage newNotificationMessage = new NotificationMessage("" + siteNodeVO.getName(), SiteNodeImpl.class.getName(), "SYSTEM", notificationMessage.getType(), siteNodeVO.getId(), "" + siteNodeVO.getName());
  834. String key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + "_" + newNotificationMessage.getType();
  835. if(!existingSignatures.contains(key))
  836. {
  837. logger.info("++++++++++++++Got an META PAGE notification - just adding it AS A PAGE instead: " + newNotificationMessage.getObjectId());
  838. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  839. existingSignatures.add(key);
  840. }
  841. else
  842. {
  843. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  844. }
  845. }
  846. }
  847. else
  848. {
  849. String key = "" + notificationMessage.getClassName() + "_" + notificationMessage.getObjectId() + "_" + "_" + notificationMessage.getType();
  850. if(!existingSignatures.contains(key))
  851. {
  852. logger.info("++++++++++++++Got an Content notification - just adding it: " + notificationMessage.getObjectId());
  853. baseEntitiesToIndexMessageList.add(notificationMessage);
  854. existingSignatures.add(key);
  855. }
  856. else
  857. {
  858. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  859. }
  860. }
  861. }
  862. else
  863. {
  864. logger.info("The content seems to be missing from the database. A guess is that it's new or deleted. Let's try later.");
  865. if(!revisitedInternalMessageList.contains(notificationMessage))
  866. maturedQeuedMessages.add(notificationMessage);
  867. else
  868. logger.info("No - allready tried it again.. skipping.");
  869. }
  870. }
  871. else if(notificationMessage.getClassName().equals(ContentVersionImpl.class.getName()) || notificationMessage.getClassName().equals(ContentVersion.class.getName()))
  872. {
  873. logger.info("++++++++++++++Got an ContentVersion notification - focus on content: " + notificationMessage.getObjectId());
  874. //ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId((Integer)notificationMessage.getObjectId());
  875. ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLocklessContentVersionVOWithId((Integer)notificationMessage.getObjectId());
  876. if(contentVersionVO != null)
  877. {
  878. ContentVO contentVO = ContentController.getContentController().getLocklessContentVOWithId(contentVersionVO.getContentId());
  879. if(contentVO.getContentTypeDefinitionId() != null)
  880. {
  881. ContentTypeDefinitionVO ctdVO = null;
  882. try
  883. {
  884. ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId());
  885. }
  886. catch (SystemException sex)
  887. {
  888. logger.warn("Failed to get the content type definition for content with Id: " + contentVO.getContentId() + ". The content version will not be indexed. Message: " + sex.getMessage());
  889. logger.info("Failed to get the content type definition for content with Id: " + contentVO.getContentId(), sex);
  890. }
  891. if(ctdVO != null && ctdVO.getName().equals("Meta info"))
  892. {
  893. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithMetaInfoContentId(contentVO.getContentId());
  894. if (siteNodeVO == null)
  895. {
  896. logger.warn("Got meta info notification but could not find a page for the Content-id. Content.id: " + contentVO.getContentId());
  897. }
  898. else
  899. {
  900. NotificationMessage newNotificationMessage = new NotificationMessage("" + siteNodeVO.getName(), SiteNodeImpl.class.getName(), "SYSTEM", notificationMessage.getType(), siteNodeVO.getId(), "" + siteNodeVO.getName());
  901. String key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + newNotificationMessage.getType();
  902. if(!existingSignatures.contains(key))
  903. {
  904. logger.info("++++++++++++++Got an META PAGE notification - just adding it AS A PAGE instead: " + newNotificationMessage.getObjectId());
  905. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  906. existingSignatures.add(key);
  907. }
  908. else
  909. {
  910. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  911. }
  912. }
  913. }
  914. else
  915. {
  916. NotificationMessage newNotificationMessage = new NotificationMessage("" + contentVersionVO.getContentName(), ContentImpl.class.getName(), "SYSTEM", notificationMessage.getType(), contentVersionVO.getContentId(), "" + contentVersionVO.getContentName());
  917. String key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + newNotificationMessage.getType();
  918. if(!existingSignatures.contains(key))
  919. {
  920. logger.info("++++++++++++++Got an Content notification - just adding it: " + newNotificationMessage.getObjectId());
  921. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  922. existingSignatures.add(key);
  923. }
  924. else
  925. {
  926. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  927. }
  928. }
  929. }
  930. }
  931. else
  932. {
  933. logger.info("The content version seems to be missing from the database. A guess is that it's new or deleted. Let's try later.");
  934. if(!revisitedInternalMessageList.contains(notificationMessage))
  935. maturedQeuedMessages.add(notificationMessage);
  936. else
  937. logger.info("No - allready tried it again.. skipping.");
  938. }
  939. }
  940. else if(notificationMessage.getClassName().equals(DigitalAssetImpl.class.getName()) ||
  941. notificationMessage.getClassName().equals(MediumDigitalAssetImpl.class.getName()) ||
  942. notificationMessage.getClassName().equals(DigitalAsset.class.getName()) ||
  943. notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) ||
  944. notificationMessage.getClassName().equals(SmallSiteNodeImpl.class.getName()) ||
  945. notificationMessage.getClassName().equals(PureSiteNodeImpl.class.getName()) ||
  946. notificationMessage.getClassName().equals(SiteNode.class.getName()) ||
  947. notificationMessage.getClassName().equals(SiteNodeVersionImpl.class.getName()) ||
  948. notificationMessage.getClassName().equals(SiteNodeVersion.class.getName()))
  949. {
  950. logger.info("notificationMessage.getClassName():" + notificationMessage.getClassName());
  951. String key = "" + notificationMessage.getClassName() + "_" + notificationMessage.getObjectId() + "_" + "_" + notificationMessage.getType();
  952. if(notificationMessage.getClassName().equals(SiteNodeVersionImpl.class.getName()) || notificationMessage.getClassName().equals(SiteNodeVersion.class.getName()))
  953. {
  954. logger.info("PPPPPPPPPPPPPPPPPPPPPPPPPP:" + notificationMessage.getObjectId());
  955. try
  956. {
  957. SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId((Integer)notificationMessage.getObjectId());
  958. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeVersionVO.getSiteNodeId());
  959. NotificationMessage newNotificationMessage = new NotificationMessage("" + siteNodeVO.getName(), SiteNodeImpl.class.getName(), "SYSTEM", notificationMessage.getType(), siteNodeVO.getId(), "" + siteNodeVO.getName());
  960. key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + newNotificationMessage.getType();
  961. if(!existingSignatures.contains(key))
  962. {
  963. logger.info("++++++++++++++Got an SiteNodeVersionImpl notification - just adding it as SiteNodeImpl: " + newNotificationMessage.getClassName() + ":" + newNotificationMessage.getObjectId());
  964. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  965. existingSignatures.add(key);
  966. }
  967. else
  968. {
  969. logger.info("++++++++++++++Skipping notification - duplicate existed: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  970. }
  971. }
  972. catch(Exception e)
  973. {
  974. logger.warn("Got an error handling SiteNodeVersion with ID: " + notificationMessage.getObjectId() + ":" + e.getMessage());
  975. }
  976. }
  977. else if(notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) || notificationMessage.getClassName().equals(SiteNode.class.getName()) || notificationMessage.getClassName().equals(SmallSiteNodeImpl.class.getName()) || notificationMessage.getClassName().equals(PureSiteNodeImpl.class.getName()))
  978. {
  979. if(!existingSignatures.contains(key))
  980. {
  981. logger.info("++++++++++++++Got an Page notification - just adding it: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  982. baseEntitiesToIndexMessageList.add(notificationMessage);
  983. existingSignatures.add(key);
  984. }
  985. else
  986. {
  987. logger.info("++++++++++++++Skipping notification - duplicate existed: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  988. }
  989. }
  990. else
  991. {
  992. NotificationMessage newNotificationMessage = new NotificationMessage("" + notificationMessage.getName(), DigitalAssetImpl.class.getName(), "SYSTEM", notificationMessage.getType(), notificationMessage.getObjectId(), "" + notificationMessage.getName());
  993. key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + "_" + newNotificationMessage.getType();
  994. if(!existingSignatures.contains(key))
  995. {
  996. logger.info("++++++++++++++Got an Content notification - just adding it: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  997. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  998. existingSignatures.add(key);
  999. }
  1000. else
  1001. {
  1002. logger.info("++++++++++++++Skipping notification - duplicate existed: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  1003. }
  1004. }
  1005. }
  1006. }
  1007. internalMessageList = baseEntitiesToIndexMessageList;
  1008. logger.info("After in [" + CmsPropertyHandler.getContextRootPath() + "]:" + internalMessageList.size() + ":" + existingSignatures.size());
  1009. try
  1010. {
  1011. logger.info("notifyListeners actually running");
  1012. if(getIsIndexedLocked())
  1013. {
  1014. logger.warn("The index should not be locked as no indexing is registered to be carried out. Lets unlock it as it may be the result of a crash.");
  1015. unlockIndex();
  1016. }
  1017. //logger.error("Starting indexin of " + qeuedMessages.size());
  1018. Timer t = new Timer();
  1019. IndexWriter writer = getIndexWriter();
  1020. //t.printElapsedTime("Creating writer took");
  1021. Database db = CastorDatabaseService.getDatabase();
  1022. beginTransaction(db);
  1023. try
  1024. {
  1025. int numberOfMessages = internalMessageList.size();
  1026. Iterator internalMessageListIterator = internalMessageList.iterator();
  1027. while(internalMessageListIterator.hasNext())
  1028. {
  1029. NotificationMessage notificationMessage = (NotificationMessage)internalMessageListIterator.next();
  1030. try
  1031. {
  1032. if(logger.isInfoEnabled())
  1033. logger.info("Starting indexin of " + notificationMessage);
  1034. indexInformation(notificationMessage, writer, internalMessageList, forceVersionIndexing, db);
  1035. internalMessageListIterator.remove();
  1036. }
  1037. catch (Exception e)
  1038. {
  1039. e.printStackTrace();
  1040. }
  1041. }
  1042. //t.printElapsedTime("Indexing " + numberOfMessages + " documents took");
  1043. //Map<String,String> commitUserDat…

Large files files are truncated, but you can click here to view the full file