PageRenderTime 78ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/aboutyang/infoglue
Java | 2484 lines | 1885 code | 359 blank | 240 comment | 276 complexity | baa8a06ae9012cabef157e4c29ebfcab MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0
  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.entities.content.Content;
  76. import org.infoglue.cms.entities.content.ContentCategory;
  77. import org.infoglue.cms.entities.content.ContentVO;
  78. import org.infoglue.cms.entities.content.ContentVersion;
  79. import org.infoglue.cms.entities.content.ContentVersionVO;
  80. import org.infoglue.cms.entities.content.DigitalAsset;
  81. import org.infoglue.cms.entities.content.DigitalAssetVO;
  82. import org.infoglue.cms.entities.content.SmallestContentVersionVO;
  83. import org.infoglue.cms.entities.content.impl.simple.ContentImpl;
  84. import org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl;
  85. import org.infoglue.cms.entities.content.impl.simple.DigitalAssetImpl;
  86. import org.infoglue.cms.entities.content.impl.simple.MediumDigitalAssetImpl;
  87. import org.infoglue.cms.entities.content.impl.simple.SmallestContentVersionImpl;
  88. import org.infoglue.cms.entities.kernel.BaseEntityVO;
  89. import org.infoglue.cms.entities.management.CategoryAttribute;
  90. import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
  91. import org.infoglue.cms.entities.management.LanguageVO;
  92. import org.infoglue.cms.entities.structure.SiteNode;
  93. import org.infoglue.cms.entities.structure.SiteNodeVO;
  94. import org.infoglue.cms.entities.structure.SiteNodeVersion;
  95. import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
  96. import org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl;
  97. import org.infoglue.cms.entities.structure.impl.simple.SiteNodeVersionImpl;
  98. import org.infoglue.cms.exception.Bug;
  99. import org.infoglue.cms.exception.SystemException;
  100. import org.infoglue.cms.util.CmsPropertyHandler;
  101. import org.infoglue.cms.util.NotificationListener;
  102. import org.infoglue.cms.util.NotificationMessage;
  103. import org.infoglue.deliver.util.CacheController;
  104. import org.infoglue.deliver.util.RequestAnalyser;
  105. import org.infoglue.deliver.util.Timer;
  106. import org.pdfbox.pdmodel.PDDocument;
  107. import org.pdfbox.util.PDFTextStripper;
  108. public class LuceneController extends BaseController implements NotificationListener
  109. {
  110. private static Directory directory = null;
  111. private static IndexWriter writer = null;
  112. private static IndexReader indexReader = null;
  113. private static int reopened = 0;
  114. private final static Logger logger = Logger.getLogger(LuceneController.class.getName());
  115. private static int indexedDocumentsSinceLastOptimize = 0;
  116. private Integer lastCommitedContentVersionId = -1;
  117. private static Integer numberOfVersionToIndexInBatch = 1000;
  118. private static AtomicBoolean indexingInitialized = new AtomicBoolean(false);
  119. private static AtomicBoolean stopIndexing = new AtomicBoolean(false);
  120. private static AtomicBoolean deleteIndexOnStop = new AtomicBoolean(false);
  121. public static void setNumberOfVersionToIndexInBatch(Integer numberOfVersionToIndexInBatch)
  122. {
  123. numberOfVersionToIndexInBatch = numberOfVersionToIndexInBatch;
  124. }
  125. public static void stopIndexing()
  126. {
  127. stopIndexing.set(true);
  128. }
  129. /**
  130. * Default Constructor
  131. */
  132. public static LuceneController getController()
  133. {
  134. return new LuceneController();
  135. }
  136. private static List<NotificationMessage> qeuedMessages = new ArrayList<NotificationMessage>();
  137. private StandardAnalyzer getStandardAnalyzer() throws Exception
  138. {
  139. return new StandardAnalyzer(Version.LUCENE_34);
  140. }
  141. private Directory getDirectory() throws Exception
  142. {
  143. if(LuceneController.directory != null)
  144. return directory;
  145. String index = CmsPropertyHandler.getContextDiskPath() + File.separator + "lucene" + File.separator + "index";
  146. index = index.replaceAll("//", "/");
  147. //System.out.println("index:" + index);
  148. File INDEX_DIR = new File(index);
  149. directory = new NIOFSDirectory(INDEX_DIR);
  150. directory.setLockFactory(new SingleInstanceLockFactory());
  151. boolean indexExists = IndexReader.indexExists(directory);
  152. if(!indexExists)
  153. {
  154. createIndex(directory);
  155. }
  156. return directory;
  157. }
  158. private void createIndex(Directory directory) throws Exception
  159. {
  160. IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_34, getStandardAnalyzer());
  161. IndexWriter indexWriter = new IndexWriter(directory, config);
  162. indexWriter.deleteDocuments(new Term("initializer", "true"));
  163. indexWriter.close(true);
  164. }
  165. private IndexWriter getIndexWriter() throws Exception
  166. {
  167. //Singleton returns
  168. if(writer != null)
  169. return writer;
  170. Timer t = new Timer();
  171. Directory directory = getDirectory();
  172. StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
  173. IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_34, analyzer);
  174. if(getIsIndexedLocked(true))
  175. {
  176. logger.warn("Directory is locked - leaving the messages in the qeuedMessages list...");
  177. throw new Exception("Lock not granted");
  178. }
  179. else
  180. {
  181. writer = new IndexWriter(directory, config);
  182. return writer;
  183. }
  184. }
  185. private IndexReader getIndexReader() throws Exception
  186. {
  187. if(indexReader == null)
  188. {
  189. indexReader = IndexReader.open(getDirectory(), true);
  190. }
  191. synchronized (indexReader)
  192. {
  193. if(!indexReader.isCurrent())
  194. {
  195. reopened++;
  196. indexReader.close();
  197. indexReader = IndexReader.open(getDirectory(), true);
  198. //indexReader = IndexReader.openIfChanged(indexReader, true);
  199. logger.info("reopened:" + reopened);
  200. }
  201. }
  202. return indexReader;
  203. }
  204. private IndexSearcher getIndexSearcher() throws Exception
  205. {
  206. return new IndexSearcher(getIndexReader());
  207. }
  208. private Boolean getIsIndexedLocked() throws Exception
  209. {
  210. return getIsIndexedLocked(false);
  211. }
  212. private Boolean getIsIndexedLocked(boolean returnIfFileLockException) throws Exception
  213. {
  214. Directory directory = getDirectory();
  215. try
  216. {
  217. return IndexWriter.isLocked(directory);
  218. }
  219. catch (OverlappingFileLockException e)
  220. {
  221. return returnIfFileLockException;
  222. }
  223. }
  224. private void unlockIndex() throws Exception
  225. {
  226. Directory directory = getDirectory();
  227. IndexWriter.unlock(directory);
  228. }
  229. public Map<String,Object> getIndexInformation() throws Exception
  230. {
  231. Map<String,Object> info = new HashMap<String,Object>();
  232. try
  233. {
  234. Directory directory = getDirectory();
  235. IndexReader reader = getIndexReader();
  236. int maxDoc = reader.maxDoc();
  237. int numDoc = reader.numDocs();
  238. long lastModified = getIndexReader().lastModified(directory);
  239. info.put("maxDoc", new Integer(maxDoc));
  240. info.put("numDoc", new Integer(numDoc));
  241. info.put("lastModified", new Date(lastModified));
  242. info.put("lastCommitedContentVersionId", getLastCommitedContentVersionId());
  243. List<LanguageVO> languageVOList = LanguageController.getController().getLanguageVOList();
  244. Iterator<LanguageVO> languageVOListIterator = languageVOList.iterator();
  245. outer:while(languageVOListIterator.hasNext())
  246. {
  247. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  248. info.put("indexAllLastCommittedContentVersionId_" + languageVO.getId(), getIndexAllLastCommittedContentVersionId(languageVO.getId()));
  249. info.put("indexAllLastCommittedMetaContentVersionId_" + languageVO.getId(), getIndexAllLastCommittedMetaContentVersionId(languageVO.getId()));
  250. }
  251. //reader.close();
  252. //directory.close();
  253. }
  254. catch (Exception e)
  255. {
  256. logger.error("Error creating index:" + e.getMessage(), e);
  257. throw e;
  258. }
  259. return info;
  260. }
  261. public Integer getIndexAllLastCommittedContentVersionId(Integer languageId) throws Exception
  262. {
  263. Integer indexAllLastCommittedContentVersionId = null;
  264. try
  265. {
  266. Document indexAllDocumentMetaData = getIndexAllStatusDocument();
  267. if(indexAllDocumentMetaData != null && indexAllDocumentMetaData.get("lastCommitedContentVersionId_" + languageId) != null && !indexAllDocumentMetaData.get("lastCommitedContentVersionId_" + languageId).equals("null"))
  268. indexAllLastCommittedContentVersionId = new Integer(indexAllDocumentMetaData.get("lastCommitedContentVersionId_" + languageId));
  269. }
  270. catch (Exception e)
  271. {
  272. logger.error("Error creating index:" + e.getMessage(), e);
  273. throw e;
  274. }
  275. return indexAllLastCommittedContentVersionId;
  276. }
  277. public Integer getIndexAllLastCommittedMetaContentVersionId(Integer languageId) throws Exception
  278. {
  279. Integer indexAllLastCommittedSiteNodeVersionId = null;
  280. try
  281. {
  282. Document indexAllDocumentMetaData = getIndexAllStatusDocument();
  283. if(indexAllDocumentMetaData != null && indexAllDocumentMetaData.get("lastCommitedMetaContentVersionId_" + languageId) != null && !indexAllDocumentMetaData.get("lastCommitedMetaContentVersionId_" + languageId).equals("null"))
  284. indexAllLastCommittedSiteNodeVersionId = new Integer(indexAllDocumentMetaData.get("lastCommitedMetaContentVersionId_" + languageId));
  285. }
  286. catch (Exception e)
  287. {
  288. logger.error("Error creating index:" + e.getMessage(), e);
  289. throw e;
  290. }
  291. return indexAllLastCommittedSiteNodeVersionId;
  292. }
  293. public Document createStatusDocument(Integer lastCommitedContentVersionId) throws Exception
  294. {
  295. Document doc = new Document();
  296. doc.add(new Field("lastCommitedContentVersionId", "" + lastCommitedContentVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  297. doc.add(new Field("lastCommitedModifiedDate", "" + new Date().getTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  298. doc.add(new Field("meta", new StringReader("lastCommitedContentVersionId")));
  299. return doc;
  300. }
  301. public Document getStatusDocument() throws Exception
  302. {
  303. List<Document> docs = queryDocuments("meta", "lastCommitedContentVersionId", 5);
  304. logger.info(docs.size() + " total matching documents for 'lastCommitedContentVersionId'");
  305. return (docs != null && docs.size() > 0 ? docs.get(0) : null);
  306. }
  307. public Document getIndexAllStatusDocument() throws Exception
  308. {
  309. List<Document> docs = queryDocuments(new Term("meta", "indexAllRunning"), 5);
  310. logger.info(docs.size() + " total matching documents for 'indexAllRunning'");
  311. return (docs != null && docs.size() > 0 ? docs.get(0) : null);
  312. }
  313. public Integer getLastCommitedContentVersionId() throws Exception
  314. {
  315. Integer lastCommitedContentVersionId = -1;
  316. Document doc = getStatusDocument();
  317. logger.info("STATUS doc:" + doc);
  318. if(doc != null)
  319. {
  320. String lastCommitedContentVersionIdString = doc.get("lastCommitedContentVersionId");
  321. logger.info("doc:" + doc);
  322. logger.info("lastCommitedContentVersionId:" + lastCommitedContentVersionIdString);
  323. lastCommitedContentVersionId = Integer.parseInt(lastCommitedContentVersionIdString);
  324. }
  325. return lastCommitedContentVersionId;
  326. }
  327. private void setLastCommitedContentVersionId(IndexWriter writer, Integer lastCommitedContentVersionId) throws Exception
  328. {
  329. Integer prevLastCommitedContentVersionId = getLastCommitedContentVersionId();
  330. logger.info("prevLastCommitedContentVersionId:" + prevLastCommitedContentVersionId);
  331. logger.info("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  332. if(lastCommitedContentVersionId == -1 || prevLastCommitedContentVersionId > lastCommitedContentVersionId)
  333. return;
  334. logger.info("setLastCommitedContentVersionId:" + lastCommitedContentVersionId);
  335. Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("lastCommitedContentVersionId");
  336. writer.deleteDocuments(query);
  337. writer.addDocument(createStatusDocument(lastCommitedContentVersionId));
  338. }
  339. public Date getLastCommitedModifiedDate() throws Exception
  340. {
  341. Date lastCommitedModifiedDate = new Date(10000);
  342. Document doc = getStatusDocument();
  343. if(doc != null)
  344. {
  345. String lastCommitedModifiedDateString = doc.get("lastCommitedModifiedDate");
  346. logger.info("doc:" + doc);
  347. logger.info("lastCommitedModifiedDate:" + lastCommitedModifiedDateString);
  348. Date d = new Date();
  349. d.setTime(Long.parseLong(lastCommitedModifiedDateString));
  350. lastCommitedModifiedDate = d;
  351. }
  352. return lastCommitedModifiedDate;
  353. }
  354. private void registerIndexAllProcessOngoing(Integer lastCommitedContentVersionId, Integer lastCommitedSiteNodeVersionId, Integer languageId) throws Exception
  355. {
  356. //M�ste skrivas om f�r att uppdatera b�ttre....
  357. //Document doc = new Document();
  358. IndexWriter writer = getIndexWriter();
  359. IndexSearcher searcher = getIndexSearcher();
  360. Term term = new Term("meta", "indexAllRunning");
  361. TermQuery query = new TermQuery(term);
  362. //Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("indexAllRunning");
  363. TopDocs hits = searcher.search(query, 50);
  364. //System.out.println("hits:" + hits);
  365. //System.out.println("hits.scoreDocs.length:" + hits.scoreDocs.length);
  366. if(hits.scoreDocs.length > 1)
  367. System.out.println("Must be wrong - should only be one of these docs:" + hits.scoreDocs.length);
  368. if(hits.scoreDocs.length > 0)
  369. {
  370. for(ScoreDoc scoreDoc : hits.scoreDocs)
  371. {
  372. org.apache.lucene.document.Document docExisting = searcher.doc(scoreDoc.doc);
  373. //System.out.println("Updating doc...:" + docExisting);
  374. //System.out.println("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  375. //System.out.println("lastCommitedSiteNodeVersionId:" + lastCommitedSiteNodeVersionId);
  376. //System.out.println("languageId:" + languageId);
  377. if(lastCommitedContentVersionId != null && lastCommitedContentVersionId != -1)
  378. {
  379. docExisting.removeFields("lastCommitedContentVersionId_" + languageId);
  380. docExisting.add(new Field("lastCommitedContentVersionId_" + languageId, "" + lastCommitedContentVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  381. }
  382. if(lastCommitedSiteNodeVersionId != null && lastCommitedSiteNodeVersionId != -1)
  383. {
  384. docExisting.removeFields("lastCommitedMetaContentVersionId_" + languageId);
  385. docExisting.add(new Field("lastCommitedMetaContentVersionId_" + languageId, "" + lastCommitedSiteNodeVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  386. }
  387. docExisting.removeFields("lastCommitedModifiedDate");
  388. docExisting.add(new Field("lastCommitedModifiedDate", "" + new Date().getTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  389. //docExisting.add(new Field("meta", new StringReader("indexAllRunning")));
  390. //docExisting.add(new Field("meta", "indexAllRunning", Field.Store.YES, Field.Index.NOT_ANALYZED));
  391. writer.updateDocument(term, docExisting);
  392. //System.out.println("Updating doc...:" + docExisting);
  393. //Term t = new Term("meta", "indexAllRunning");
  394. break;
  395. }
  396. }
  397. else
  398. {
  399. Document docExisting = new Document();
  400. //System.out.println("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  401. //System.out.println("lastCommitedSiteNodeVersionId:" + lastCommitedSiteNodeVersionId);
  402. //System.out.println("languageId:" + languageId);
  403. if(lastCommitedContentVersionId != null)
  404. docExisting.add(new Field("lastCommitedContentVersionId_" + languageId, "" + lastCommitedContentVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  405. if(lastCommitedSiteNodeVersionId != null)
  406. docExisting.add(new Field("lastCommitedMetaContentVersionId_" + languageId, "" + lastCommitedSiteNodeVersionId, Field.Store.YES, Field.Index.NOT_ANALYZED));
  407. docExisting.add(new Field("lastCommitedModifiedDate", "" + new Date().getTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  408. //docExisting.add(new Field("meta", new StringReader("indexAllRunning")));
  409. docExisting.add(new Field("meta", "indexAllRunning", Field.Store.YES, Field.Index.NOT_ANALYZED));
  410. writer.addDocument(docExisting);
  411. }
  412. searcher.close();
  413. //Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("indexAllRunning");
  414. //writer.deleteDocuments(query);
  415. //writer.updateDocument(term, doc);
  416. //writer.addDocument(doc);
  417. //writer.close(true);
  418. writer.commit();
  419. }
  420. private void registerIndexAllProcessDone() throws Exception
  421. {
  422. IndexWriter writer = getIndexWriter();
  423. //Query query = new QueryParser(Version.LUCENE_34, "meta", getStandardAnalyzer()).parse("indexAllRunning");
  424. Term term = new Term("meta", "indexAllRunning");
  425. TermQuery query = new TermQuery(term);
  426. writer.deleteDocuments(query);
  427. writer.commit();
  428. }
  429. public void clearIndex() throws Exception
  430. {
  431. if (indexingInitialized.compareAndSet(false, true))
  432. {
  433. logger.warn("Clearing index..");
  434. try
  435. {
  436. logger.info("NumDocs:" + getIndexReader().numDocs());
  437. IndexWriter writer = getIndexWriter();
  438. writer.deleteAll();
  439. //writer.close(true);
  440. writer.commit();
  441. logger.info("NumDocs after delete:" + getIndexReader().numDocs());
  442. }
  443. catch (Exception e)
  444. {
  445. stopIndexing.set(true);
  446. deleteIndexOnStop.set(true);
  447. logger.error("Error clearing index:" + e.getMessage(), e);
  448. }
  449. finally
  450. {
  451. logger.info("Releasing indexing flag");
  452. this.indexingInitialized.set(false);
  453. stopIndexing.set(false);
  454. }
  455. }
  456. else
  457. {
  458. stopIndexing.set(true);
  459. deleteIndexOnStop.set(true);
  460. logger.error("Could not delete index while indexing. Queueing it....");
  461. }
  462. }
  463. public TopDocs query(String text, Integer numberOfHits) throws Exception
  464. {
  465. return query("contents", text, numberOfHits);
  466. }
  467. public TopDocs query(String field, String text, Integer numberOfHits) throws Exception
  468. {
  469. IndexSearcher searcher = getIndexSearcher();
  470. Query query = new QueryParser(Version.LUCENE_34, "contents", getStandardAnalyzer()).parse(text);
  471. TopDocs hits = searcher.search(query, numberOfHits);
  472. logger.info(hits.totalHits + " total matching documents for '" + text + "'");
  473. return hits;
  474. }
  475. public List<Document> queryDocuments(Term term, Integer numberOfHits) throws Exception
  476. {
  477. IndexSearcher searcher = getIndexSearcher();
  478. Query query = new TermQuery(term);
  479. TopDocs hits = searcher.search(query, numberOfHits);
  480. logger.info(hits.totalHits + " total matching documents for '" + term.field() + ":" + term.text() + "'");
  481. List<Document> docs = new ArrayList<Document>();
  482. for(ScoreDoc scoreDoc : hits.scoreDocs)
  483. {
  484. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  485. docs.add(doc);
  486. }
  487. searcher.close();
  488. return docs;
  489. }
  490. public List<Document> queryDocuments(String field, String text, Integer numberOfHits) throws Exception
  491. {
  492. IndexSearcher searcher = getIndexSearcher();
  493. Query query = new QueryParser(Version.LUCENE_34, field, getStandardAnalyzer()).parse(text);
  494. logger.info("query:" + query);
  495. TopDocs hits = searcher.search(query, numberOfHits);
  496. logger.info(hits.totalHits + " total matching documents for '" + field + ":" + text + "'");
  497. List<Document> docs = new ArrayList<Document>();
  498. for(ScoreDoc scoreDoc : hits.scoreDocs)
  499. {
  500. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  501. docs.add(doc);
  502. }
  503. searcher.close();
  504. return docs;
  505. }
  506. public TopDocs query(String[] fields, BooleanClause.Occur[] flags, String[] queries, Sort sort, Integer numberOfHits) throws Exception
  507. {
  508. IndexSearcher searcher = getIndexSearcher();
  509. Query query = MultiFieldQueryParser.parse(Version.LUCENE_34, queries, fields, flags, getStandardAnalyzer());
  510. //Query query = new QueryParser(Version.LUCENE_34, "contents", getStandardAnalyzer()).parse(text);
  511. TopDocs hits = searcher.search(query, numberOfHits);
  512. logger.info(hits.totalHits + " total matching documents for '" + queries + "'");
  513. return hits;
  514. }
  515. public List<Document> queryDocuments(String[] fields, BooleanClause.Occur[] flags, String[] queries, Sort sort, Integer numberOfHits, Map searchMetaData) throws Exception
  516. {
  517. IndexSearcher searcher = getIndexSearcher();
  518. Query query = MultiFieldQueryParser.parse(Version.LUCENE_34, queries, fields, flags, getStandardAnalyzer());
  519. logger.info("query:" + query);
  520. //Query query = new QueryParser(Version.LUCENE_34, "contents", getStandardAnalyzer()).parse(text);
  521. TopDocs hits = searcher.search(query, numberOfHits);
  522. searchMetaData.put("totalHits", hits.totalHits);
  523. logger.info(hits.totalHits + " total matching documents for '" + query + "'");
  524. //System.out.println(hits.totalHits + " total matching documents for '" + queries + "'");
  525. List<Document> docs = new ArrayList<Document>();
  526. for(ScoreDoc scoreDoc : hits.scoreDocs)
  527. {
  528. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  529. docs.add(doc);
  530. }
  531. searcher.close();
  532. return docs;
  533. }
  534. private void query(IndexSearcher searcher, Analyzer analyzer, String text) throws Exception
  535. {
  536. Query query = new QueryParser(Version.LUCENE_34, "contents", analyzer).parse(text);
  537. TopDocs hits = searcher.search(query, 50);
  538. logger.info(hits.totalHits + " total matching documents for '" + text + "'");
  539. for(ScoreDoc scoreDoc : hits.scoreDocs)
  540. {
  541. org.apache.lucene.document.Document doc = searcher.doc(scoreDoc.doc);
  542. String cvId = doc.get("contentVersionId");
  543. logger.info("cvId: " + cvId);
  544. }
  545. }
  546. public boolean indexAll() throws Exception
  547. {
  548. if(!CmsPropertyHandler.getInternalSearchEngine().equalsIgnoreCase("lucene"))
  549. return false;
  550. logger.warn("INDEXING ALL - correct: " + indexingInitialized + "/" + deleteIndexOnStop + "/" + stopIndexing + "?");
  551. Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  552. if(deleteIndexOnStop.get())
  553. {
  554. clearIndex();
  555. deleteIndexOnStop.set(false);
  556. stopIndexing.set(false);
  557. }
  558. else
  559. {
  560. stopIndexing.set(false);
  561. }
  562. logger.warn("Resetting stopIndexing to false....");
  563. logger.warn("------------------------------Got indexAll directive....");
  564. if (indexingInitialized.compareAndSet(false, true))
  565. {
  566. //createTestIndex();
  567. //indexingInitialized.set(false);
  568. //if(true)
  569. // return true;
  570. try
  571. {
  572. Timer t = new Timer();
  573. Timer t2 = new Timer();
  574. //Indexing all normal contents now
  575. logger.info("Indexing all normal contents: " + CmsPropertyHandler.getContextDiskPath());
  576. List<LanguageVO> languageVOList = LanguageController.getController().getLanguageVOList();
  577. Iterator<LanguageVO> languageVOListIterator = languageVOList.iterator();
  578. outer:while(languageVOListIterator.hasNext())
  579. {
  580. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  581. logger.info("Getting notification messages for " + languageVO.getName());
  582. Integer previousIndexAllLastContentVersionId = getIndexAllLastCommittedContentVersionId(languageVO.getId());
  583. int startID = 0;
  584. if(previousIndexAllLastContentVersionId != null)
  585. startID = previousIndexAllLastContentVersionId;
  586. logger.info("Starting from " + startID);
  587. int newLastContentVersionId = getContentNotificationMessages(languageVO, startID);
  588. logger.info("newLastContentVersionId: " + newLastContentVersionId + " on " + languageVO.getName());
  589. registerIndexAllProcessOngoing(newLastContentVersionId, null, languageVO.getId());
  590. //previousIndexAllLastContentVersionId = newLastContentVersionId;
  591. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessages", t.getElapsedTime());
  592. logger.info("newLastContentVersionId " + newLastContentVersionId);
  593. while(newLastContentVersionId != -1)
  594. {
  595. logger.info("stopIndexing.get():" + stopIndexing.get());
  596. if(stopIndexing.get())
  597. break outer;
  598. Thread.sleep(5000);
  599. newLastContentVersionId = getContentNotificationMessages(languageVO, newLastContentVersionId);
  600. logger.info("newLastContentVersionId: " + newLastContentVersionId + " on " + languageVO.getName());
  601. registerIndexAllProcessOngoing(newLastContentVersionId, null, languageVO.getId());
  602. //previousIndexAllLastContentVersionId = newLastContentVersionId;
  603. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessages 2", t.getElapsedTime());
  604. logger.info("newLastContentVersionId " + newLastContentVersionId);
  605. }
  606. }
  607. languageVOList = LanguageController.getController().getLanguageVOList();
  608. languageVOListIterator = languageVOList.iterator();
  609. outer:while(languageVOListIterator.hasNext())
  610. {
  611. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  612. logger.info("languageVO from " + languageVO);
  613. List<NotificationMessage> notificationMessages = new ArrayList<NotificationMessage>();
  614. Integer previousIndexAllLastMetaContentVersionId = getIndexAllLastCommittedMetaContentVersionId(languageVO.getId());
  615. logger.info("previousIndexAllLastMetaContentVersionId: " + previousIndexAllLastMetaContentVersionId);
  616. int startID = 0;
  617. if(previousIndexAllLastMetaContentVersionId != null)
  618. startID = previousIndexAllLastMetaContentVersionId;
  619. logger.info("Starting from " + startID);
  620. int newLastMetaContentVersionId = getPageNotificationMessages(notificationMessages, languageVO, startID);
  621. logger.info("newLastSiteNodeVersionId " + newLastMetaContentVersionId + " on " + languageVO.getName());
  622. logger.info("notificationMessages: " + notificationMessages.size());
  623. registerIndexAllProcessOngoing(null, newLastMetaContentVersionId, languageVO.getId());
  624. //previousIndexAllLastMetaContentVersionId = newLastMetaContentVersionId;
  625. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessagesForStructure", t.getElapsedTime());
  626. logger.info("newLastMetaContentVersionId " + newLastMetaContentVersionId);
  627. while(newLastMetaContentVersionId != -1)
  628. {
  629. logger.info("stopIndexing.get():" + stopIndexing.get());
  630. if(stopIndexing.get())
  631. break outer;
  632. Thread.sleep(5000);
  633. newLastMetaContentVersionId = getPageNotificationMessages(notificationMessages, languageVO, newLastMetaContentVersionId);
  634. logger.info("newLastMetaContentVersionId " + newLastMetaContentVersionId + " on " + languageVO.getName());
  635. logger.info("notificationMessages: " + notificationMessages.size());
  636. registerIndexAllProcessOngoing(null, newLastMetaContentVersionId, languageVO.getId());
  637. //previousIndexAllLastMetaContentVersionId = newLastMetaContentVersionId;
  638. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getNotificationMessages 2", t.getElapsedTime());
  639. logger.info("newLastMetaContentVersionId " + newLastMetaContentVersionId);
  640. }
  641. }
  642. registerIndexAllProcessDone();
  643. t2.printElapsedTime("All indexing took");
  644. }
  645. catch (Exception e)
  646. {
  647. logger.error("Error indexing notifications:" + e.getMessage(), e);
  648. }
  649. finally
  650. {
  651. logger.error("Releasing indexing flag");
  652. this.indexingInitialized.set(false);
  653. }
  654. }
  655. else
  656. {
  657. logger.warn("-------------------: Allready running index all...");
  658. return false;
  659. }
  660. return true;
  661. }
  662. private void createTestIndex()
  663. {
  664. System.out.println("STARTING TEST");
  665. try
  666. {
  667. clearIndex();
  668. IndexWriter writer = getIndexWriter();
  669. for(int i=0; i<10000; i++)
  670. {
  671. // make a new, empty document
  672. Document doc = new Document();
  673. doc.add(new NumericField("publishDateTime", Field.Store.YES, true).setLongValue(23423423423L));
  674. doc.add(new NumericField("modificationDateTime", Field.Store.YES, true).setLongValue(23423423423L));
  675. doc.add(new Field("modified", DateTools.timeToString(23423423423L, DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  676. doc.add(new Field("contentVersionId", "324234234", Field.Store.YES, Field.Index.NOT_ANALYZED));
  677. doc.add(new Field("contentId", "324234234", Field.Store.YES, Field.Index.NOT_ANALYZED));
  678. doc.add(new Field("contentTypeDefinitionId", "344", Field.Store.YES, Field.Index.NOT_ANALYZED));
  679. doc.add(new Field("languageId", "33", Field.Store.YES, Field.Index.NOT_ANALYZED));
  680. doc.add(new Field("repositoryId", "22", Field.Store.YES, Field.Index.NOT_ANALYZED));
  681. doc.add(new Field("lastModifier", "Mattias Bogeblad", Field.Store.YES, Field.Index.NOT_ANALYZED));
  682. doc.add(new Field("stateId", "3", Field.Store.YES, Field.Index.NOT_ANALYZED));
  683. doc.add(new Field("isAsset", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  684. doc.add(new Field("contents", new StringReader(i + " fwe foweif oiwejfoijweoifiweuhfi uehwiufh weiuhfiuwehfiew iufiuwehfi ewiufh iuwehfiuehwiufiweuhfiu ehwifhw eifew efiwehfiuwe" +
  685. "ff wehfiuehwiufiuwehfiuehw iufhwei uhfiehwiufweiuhf iwefihw eifiuwe ifhwe ifihew iufi weuhfiuwe" +
  686. "dfbsdjfsjdjfjksdf s f jdsjkfs dkjfh ksdfk sdkfhkds fksd " +
  687. "fjsd fsdhf uiweo p fiieowhf iehwiufiewhfiewfhw efn ewfowe ifioewf owehfowe")));
  688. doc.add(new Field("uid", "" + i, Field.Store.NO, Field.Index.NOT_ANALYZED));
  689. writer.addDocument(doc);
  690. if(i == 1000 || i == 2000 ||i == 3000 ||i == 4000 ||i == 5000 ||i == 6000 ||i == 7000 ||i == 8000 ||i == 9000)
  691. {
  692. //writer.optimize();
  693. //writer.optimize(true);
  694. logger.info("Sleeping...:" + getIndexInformation().get("numDoc"));
  695. Thread.sleep(5000);
  696. }
  697. }
  698. //writer.close(true);
  699. writer.commit();
  700. }
  701. catch (Exception e)
  702. {
  703. e.printStackTrace();
  704. }
  705. }
  706. /**
  707. * This method gets called when a new notification has come.
  708. * It then iterates through the listeners and notifies them.
  709. */
  710. public void addNotificationMessage(NotificationMessage notificationMessage)
  711. {
  712. if(notificationMessage.getClassName().equals(ContentImpl.class.getName()) ||
  713. notificationMessage.getClassName().equals(ContentVersionImpl.class.getName()) ||
  714. notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) ||
  715. notificationMessage.getClassName().equals(SiteNodeVersionImpl.class.getName()) ||
  716. notificationMessage.getClassName().equals(DigitalAssetImpl.class.getName()) ||
  717. notificationMessage.getClassName().equals(MediumDigitalAssetImpl.class.getName()))
  718. {
  719. if(qeuedMessages.size() == 1000)
  720. {
  721. logger.warn("qeuedMessages went over 1000 - seems wrong");
  722. Thread.dumpStack();
  723. }
  724. synchronized (qeuedMessages)
  725. {
  726. qeuedMessages.add(notificationMessage);
  727. }
  728. }
  729. else
  730. {
  731. logger.info("Skipping indexing:" + notificationMessage.getClassName());
  732. }
  733. }
  734. /**
  735. * This method gets called when a new NotificationMessage is available.
  736. * The writer just calls the transactionHistoryController which stores it.
  737. */
  738. public void notify(NotificationMessage notificationMessage)
  739. {
  740. try
  741. {
  742. if(logger.isInfoEnabled())
  743. logger.info("Indexing:" + notificationMessage.getName() + ":" + notificationMessage.getType() + ":" + notificationMessage.getObjectId() + ":" + notificationMessage.getObjectName());
  744. addNotificationMessage(notificationMessage);
  745. }
  746. catch(Exception e)
  747. {
  748. logger.error("Error notifying: " + e.getMessage());
  749. }
  750. }
  751. public void process() throws Exception
  752. {
  753. logger.info("Process inside LuceneController");
  754. notifyListeners(false, true);
  755. }
  756. public void notifyListeners(boolean forceVersionIndexing, boolean checkForIndexingJobs) throws IOException, Exception
  757. {
  758. if(!CmsPropertyHandler.getInternalSearchEngine().equalsIgnoreCase("lucene") || CmsPropertyHandler.getContextDiskPath().contains("@deploy.dir"))
  759. return;
  760. boolean initDoneLocally = false;
  761. boolean finishDoneLocally = false;
  762. logger.info("------------------------------->notifyListeners before check in " + CmsPropertyHandler.getContextRootPath() + "/" + deleteIndexOnStop.get() + "/" + stopIndexing.get());
  763. if(deleteIndexOnStop.get())
  764. {
  765. clearIndex();
  766. deleteIndexOnStop.set(false);
  767. stopIndexing.set(false);
  768. }
  769. else
  770. {
  771. stopIndexing.set(false);
  772. }
  773. if (!checkForIndexingJobs || indexingInitialized.compareAndSet(false, true))
  774. {
  775. if(checkForIndexingJobs)
  776. initDoneLocally = true;
  777. List<NotificationMessage> internalMessageList = new ArrayList<NotificationMessage>();
  778. synchronized (qeuedMessages)
  779. {
  780. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  781. internalMessageList.addAll(qeuedMessages);
  782. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  783. qeuedMessages.clear();
  784. //logger.error("internalMessageList: " + internalMessageList.size() + "/" + qeuedMessages.size());
  785. }
  786. //Should implement equals on NotificationMessage later
  787. List<NotificationMessage> baseEntitiesToIndexMessageList = new ArrayList<NotificationMessage>();
  788. List<String> existingSignatures = new ArrayList<String>();
  789. logger.info("Before AAAAA:" + internalMessageList.size() + ":" + existingSignatures.size());
  790. Iterator<NotificationMessage> cleanupInternalMessageListIterator = internalMessageList.iterator();
  791. while(cleanupInternalMessageListIterator.hasNext())
  792. {
  793. NotificationMessage notificationMessage = cleanupInternalMessageListIterator.next();
  794. logger.info("Indexing........:" + notificationMessage.getClassName());
  795. if(notificationMessage.getClassName().equals(ContentImpl.class.getName()) || notificationMessage.getClassName().equals(Content.class.getName()))
  796. {
  797. ContentVO contentVO = ContentController.getContentController().getContentVOWithId((Integer)notificationMessage.getObjectId());
  798. ContentTypeDefinitionVO ctdVO = null;
  799. try
  800. {
  801. ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId());
  802. }
  803. catch (SystemException sex)
  804. {
  805. logger.warn("Failed to get the content type definition for content with Id: " + contentVO.getContentId() + ". The content will not be indexed. Message: " + sex.getMessage());
  806. logger.info("Failed to get the content type definition for content with Id: " + contentVO.getContentId(), sex);
  807. }
  808. if(ctdVO != null && ctdVO.getName().equals("Meta info"))
  809. {
  810. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithMetaInfoContentId(contentVO.getContentId());
  811. NotificationMessage newNotificationMessage = new NotificationMessage("" + siteNodeVO.getName(), SiteNodeImpl.class.getName(), "SYSTEM", notificationMessage.getType(), siteNodeVO.getId(), "" + siteNodeVO.getName());
  812. String key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + "_" + newNotificationMessage.getType();
  813. if(!existingSignatures.contains(key))
  814. {
  815. logger.info("++++++++++++++Got an META PAGE notification - just adding it AS A PAGE instead: " + newNotificationMessage.getObjectId());
  816. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  817. existingSignatures.add(key);
  818. }
  819. else
  820. {
  821. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  822. }
  823. }
  824. else
  825. {
  826. String key = "" + notificationMessage.getClassName() + "_" + notificationMessage.getObjectId() + "_" + "_" + notificationMessage.getType();
  827. if(!existingSignatures.contains(key))
  828. {
  829. logger.info("++++++++++++++Got an Content notification - just adding it: " + notificationMessage.getObjectId());
  830. baseEntitiesToIndexMessageList.add(notificationMessage);
  831. existingSignatures.add(key);
  832. }
  833. else
  834. {
  835. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  836. }
  837. }
  838. }
  839. else if(notificationMessage.getClassName().equals(ContentVersionImpl.class.getName()) || notificationMessage.getClassName().equals(ContentVersion.class.getName()))
  840. {
  841. logger.info("++++++++++++++Got an ContentVersion notification - focus on content: " + notificationMessage.getObjectId());
  842. ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId((Integer)notificationMessage.getObjectId());
  843. ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId());
  844. if(contentVO.getContentTypeDefinitionId() != null)
  845. {
  846. ContentTypeDefinitionVO ctdVO = null;
  847. try
  848. {
  849. ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId());
  850. }
  851. catch (SystemException sex)
  852. {
  853. 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());
  854. logger.info("Failed to get the content type definition for content with Id: " + contentVO.getContentId(), sex);
  855. }
  856. if(ctdVO != null && ctdVO.getName().equals("Meta info"))
  857. {
  858. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithMetaInfoContentId(contentVO.getContentId());
  859. if (siteNodeVO == null)
  860. {
  861. logger.warn("Got meta info notification but could not find a page for the Content-id. Content.id: " + contentVO.getContentId());
  862. }
  863. else
  864. {
  865. NotificationMessage newNotificationMessage = new NotificationMessage("" + siteNodeVO.getName(), SiteNodeImpl.class.getName(), "SYSTEM", notificationMessage.getType(), siteNodeVO.getId(), "" + siteNodeVO.getName());
  866. String key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + newNotificationMessage.getType();
  867. if(!existingSignatures.contains(key))
  868. {
  869. logger.info("++++++++++++++Got an META PAGE notification - just adding it AS A PAGE instead: " + newNotificationMessage.getObjectId());
  870. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  871. existingSignatures.add(key);
  872. }
  873. else
  874. {
  875. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  876. }
  877. }
  878. }
  879. else
  880. {
  881. NotificationMessage newNotificationMessage = new NotificationMessage("" + contentVersionVO.getContentName(), ContentImpl.class.getName(), "SYSTEM", notificationMessage.getType(), contentVersionVO.getContentId(), "" + contentVersionVO.getContentName());
  882. String key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + newNotificationMessage.getType();
  883. if(!existingSignatures.contains(key))
  884. {
  885. logger.info("++++++++++++++Got an Content notification - just adding it: " + newNotificationMessage.getObjectId());
  886. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  887. existingSignatures.add(key);
  888. }
  889. else
  890. {
  891. logger.info("++++++++++++++Skipping Content notification - duplicate existed: " + notificationMessage.getObjectId());
  892. }
  893. }
  894. }
  895. }
  896. else if(notificationMessage.getClassName().equals(DigitalAssetImpl.class.getName()) ||
  897. notificationMessage.getClassName().equals(MediumDigitalAssetImpl.class.getName()) ||
  898. notificationMessage.getClassName().equals(DigitalAsset.class.getName()) ||
  899. notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) ||
  900. notificationMessage.getClassName().equals(SiteNode.class.getName()) ||
  901. notificationMessage.getClassName().equals(SiteNodeVersionImpl.class.getName()) ||
  902. notificationMessage.getClassName().equals(SiteNodeVersion.class.getName()))
  903. {
  904. logger.info("notificationMessage.getClassName():" + notificationMessage.getClassName());
  905. String key = "" + notificationMessage.getClassName() + "_" + notificationMessage.getObjectId() + "_" + "_" + notificationMessage.getType();
  906. if(notificationMessage.getClassName().equals(SiteNodeVersionImpl.class.getName()) || notificationMessage.getClassName().equals(SiteNodeVersion.class.getName()))
  907. {
  908. logger.info("PPPPPPPPPPPPPPPPPPPPPPPPPP:" + notificationMessage.getObjectId());
  909. SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId((Integer)notificationMessage.getObjectId());
  910. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeVersionVO.getSiteNodeId());
  911. NotificationMessage newNotificationMessage = new NotificationMessage("" + siteNodeVO.getName(), SiteNodeImpl.class.getName(), "SYSTEM", notificationMessage.getType(), siteNodeVO.getId(), "" + siteNodeVO.getName());
  912. key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + newNotificationMessage.getType();
  913. if(!existingSignatures.contains(key))
  914. {
  915. logger.info("++++++++++++++Got an SiteNodeVersionImpl notification - just adding it as SiteNodeImpl: " + newNotificationMessage.getClassName() + ":" + newNotificationMessage.getObjectId());
  916. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  917. existingSignatures.add(key);
  918. }
  919. else
  920. {
  921. logger.info("++++++++++++++Skipping notification - duplicate existed: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  922. }
  923. }
  924. else if(notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) || notificationMessage.getClassName().equals(SiteNode.class.getName()))
  925. {
  926. if(!existingSignatures.contains(key))
  927. {
  928. logger.info("++++++++++++++Got an Page notification - just adding it: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  929. baseEntitiesToIndexMessageList.add(notificationMessage);
  930. existingSignatures.add(key);
  931. }
  932. else
  933. {
  934. logger.info("++++++++++++++Skipping notification - duplicate existed: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  935. }
  936. }
  937. else
  938. {
  939. NotificationMessage newNotificationMessage = new NotificationMessage("" + notificationMessage.getName(), DigitalAssetImpl.class.getName(), "SYSTEM", notificationMessage.getType(), notificationMessage.getObjectId(), "" + notificationMessage.getName());
  940. key = "" + newNotificationMessage.getClassName() + "_" + newNotificationMessage.getObjectId() + "_" + "_" + newNotificationMessage.getType();
  941. if(!existingSignatures.contains(key))
  942. {
  943. logger.info("++++++++++++++Got an Content notification - just adding it: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  944. baseEntitiesToIndexMessageList.add(newNotificationMessage);
  945. existingSignatures.add(key);
  946. }
  947. else
  948. {
  949. logger.info("++++++++++++++Skipping notification - duplicate existed: " + notificationMessage.getClassName() + ":" + notificationMessage.getObjectId());
  950. }
  951. }
  952. }
  953. }
  954. internalMessageList = baseEntitiesToIndexMessageList;
  955. logger.info("After in [" + CmsPropertyHandler.getContextRootPath() + "]:" + internalMessageList.size() + ":" + existingSignatures.size());
  956. try
  957. {
  958. logger.info("notifyListeners actually running");
  959. if(getIsIndexedLocked())
  960. {
  961. 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.");
  962. unlockIndex();
  963. }
  964. //logger.error("Starting indexin of " + qeuedMessages.size());
  965. Timer t = new Timer();
  966. IndexWriter writer = getIndexWriter();
  967. //t.printElapsedTime("Creating writer took");
  968. Database db = CastorDatabaseService.getDatabase();
  969. beginTransaction(db);
  970. try
  971. {
  972. int numberOfMessages = internalMessageList.size();
  973. Iterator internalMessageListIterator = internalMessageList.iterator();
  974. while(internalMessageListIterator.hasNext())
  975. {
  976. NotificationMessage notificationMessage = (NotificationMessage)internalMessageListIterator.next();
  977. try
  978. {
  979. if(logger.isInfoEnabled())
  980. logger.info("Starting indexin of " + notificationMessage);
  981. indexInformation(notificationMessage, writer, internalMessageList, forceVersionIndexing, db);
  982. internalMessageListIterator.remove();
  983. }
  984. catch (Exception e)
  985. {
  986. e.printStackTrace();
  987. }
  988. }
  989. //t.printElapsedTime("Indexing " + numberOfMessages + " documents took");
  990. //Map<String,String> commitUserData = new HashMap<String,String>();
  991. //internalMessageList.clear();
  992. //writer.commit(commitUserData);
  993. logger.info("##############lastCommitedContentVersionId before close:" + lastCommitedContentVersionId);
  994. if(lastCommitedContentVersionId > -1)
  995. {
  996. Integer previousLastCommittedContentVersionId = getLastCommitedContentVersionId();
  997. logger.info("##############previousLastCommittedContentVersionId before close:" + previousLastCommittedContentVersionId);
  998. if(previousLastCommittedContentVersionId < lastCommitedContentVersionId)
  999. {
  1000. try
  1001. {
  1002. logger.info("*************ADDING status doc " + lastCommitedContentVersionId + "**************");
  1003. setLastCommitedContentVersionId(writer, lastCommitedContentVersionId);
  1004. }
  1005. catch (Exception e)
  1006. {
  1007. logger.error("*************ERROR: ADDING status doc**************", e);
  1008. }
  1009. }
  1010. else
  1011. {
  1012. logger.warn("The content version was not a higher number than what was allready indexed - lets not add status....");
  1013. }
  1014. }
  1015. commitTransaction(db);
  1016. }
  1017. catch(Exception e)
  1018. {
  1019. logger.error("An error occurred so we should not complete the transaction:" + e.getMessage(), e);
  1020. rollbackTransaction(db);
  1021. }
  1022. finally
  1023. {
  1024. writer.commit();
  1025. //writer.close(true);
  1026. }
  1027. logger.info("OOOOOOOOOOOOOO:" + getLastCommitedContentVersionId());
  1028. }
  1029. catch (Exception e)
  1030. {
  1031. logger.error("Error indexing notifications:" + e.getMessage());
  1032. logger.warn("Error indexing notifications:" + e.getMessage(), e);
  1033. }
  1034. finally
  1035. {
  1036. logger.info("Releasing indexing flag");
  1037. try
  1038. {
  1039. if(internalMessageList.size() > 0)
  1040. {
  1041. synchronized (qeuedMessages)
  1042. {
  1043. logger.info("Returning internalMessageList:" + internalMessageList.size() + " to qeuedMessages as some failed.");
  1044. qeuedMessages.addAll(internalMessageList);
  1045. internalMessageList.clear();
  1046. }
  1047. }
  1048. }
  1049. catch (Exception e)
  1050. {
  1051. e.printStackTrace();
  1052. }
  1053. if(checkForIndexingJobs)
  1054. {
  1055. this.indexingInitialized.set(false);
  1056. finishDoneLocally = true;
  1057. }
  1058. }
  1059. if(initDoneLocally && !finishDoneLocally)
  1060. logger.error("EEEEEEEEEEEEEEERRRRRRRRRRRRRRROOOOOOOOOOOORRRRRRRR aaaaaaa");
  1061. logger.info("internalMessageList 1:" + internalMessageList.size() + " / " + qeuedMessages.size());
  1062. }
  1063. else
  1064. {
  1065. logger.info("------------------------------->Indexing job allready running... skipping in " + CmsPropertyHandler.getContextRootPath());
  1066. }
  1067. logger.info("queued messages 1:" + qeuedMessages.size());
  1068. }
  1069. public void index() throws Exception
  1070. {
  1071. if(!CmsPropertyHandler.getInternalSearchEngine().equalsIgnoreCase("lucene"))
  1072. return;
  1073. logger.info("Start index: " + CmsPropertyHandler.getContextRootPath() + "/" + deleteIndexOnStop.get() + "/" + stopIndexing.get());
  1074. if(deleteIndexOnStop.get())
  1075. {
  1076. clearIndex();
  1077. deleteIndexOnStop.set(false);
  1078. stopIndexing.set(false);
  1079. }
  1080. else
  1081. {
  1082. stopIndexing.set(false);
  1083. }
  1084. logger.info("################# starting index");
  1085. //if (indexStarted.compareAndSet(false, true))
  1086. //{
  1087. IndexReader indexReader = null;
  1088. try
  1089. {
  1090. Integer lastCommitedContentVersionId = getLastCommitedContentVersionId();
  1091. Document indexAllDocumentMetaData = getIndexAllStatusDocument();
  1092. //Integer previousIndexAllLastContentVersionId = getIndexAllLastCommittedContentVersionId();
  1093. logger.info("lastCommitedContentVersionId:" + lastCommitedContentVersionId);
  1094. Date lastCommitedModifiedDate = getLastCommitedModifiedDate();
  1095. Calendar yesterday = Calendar.getInstance();
  1096. yesterday.add(Calendar.HOUR_OF_DAY, -1);
  1097. logger.info("lastCommitedContentVersionId: " + lastCommitedContentVersionId);
  1098. logger.info("lastCommitedModifiedDate: " + lastCommitedModifiedDate);
  1099. indexReader = getIndexReader();
  1100. boolean didIndex = false;
  1101. if(lastCommitedContentVersionId == -1 || indexAllDocumentMetaData != null || indexReader.numDocs() < 100)
  1102. {
  1103. logger.info("indexAll as it seemed to be not ready.....");
  1104. logger.info("###########################IndexAll");
  1105. didIndex = indexAll();
  1106. }
  1107. else //Skipping indexing for now..
  1108. {
  1109. logger.info("###########################indexIncremental");
  1110. didIndex = indexIncremental(lastCommitedContentVersionId, yesterday.getTime());
  1111. }
  1112. if(didIndex)
  1113. {
  1114. CacheController.clearCache("pageCache");
  1115. CacheController.clearCache("pageCacheExtra");
  1116. }
  1117. }
  1118. catch (Exception e)
  1119. {
  1120. logger.error("Error indexing notifications:" + e.getMessage());
  1121. logger.warn("Error indexing notifications:" + e.getMessage(), e);
  1122. }
  1123. /*
  1124. }
  1125. else
  1126. {
  1127. logger.error("################# skipping index, was allready started");
  1128. }
  1129. */
  1130. }
  1131. public boolean indexIncremental(Integer lastCommitedContentVersionId, Date lastCommitedDateTime) throws Exception
  1132. {
  1133. if(!CmsPropertyHandler.getInternalSearchEngine().equalsIgnoreCase("lucene"))
  1134. return false;
  1135. Timer t = new Timer();
  1136. Timer t2 = new Timer();
  1137. logger.info("Indexing incremental:" + lastCommitedContentVersionId + "/" + lastCommitedDateTime);
  1138. //Map<String,String> lastCommitData = reader.getCommitUserData();
  1139. List<LanguageVO> languageVOList = LanguageController.getController().getLanguageVOList();
  1140. Iterator<LanguageVO> languageVOListIterator = languageVOList.iterator();
  1141. outer:while(languageVOListIterator.hasNext())
  1142. {
  1143. LanguageVO languageVO = (LanguageVO)languageVOListIterator.next();
  1144. List<NotificationMessage> notificationMessages = new ArrayList<NotificationMessage>();
  1145. //logger.error("Getting notification messages for " + languageVO.getName());
  1146. int newLastContentVersionId = getNotificationMessages(notificationMessages, languageVO, lastCommitedContentVersionId, lastCommitedDateTime, 1000);
  1147. while(newLastContentVersionId != -1)
  1148. {
  1149. Thread.sleep(5000);
  1150. if(stopIndexing.get())
  1151. break outer;
  1152. logger.info("Queueing " + notificationMessages.size() + " notificationMessages for indexing");
  1153. for(NotificationMessage notificationMessage : notificationMessages)
  1154. {
  1155. notify(notificationMessage);
  1156. }
  1157. notifyListeners(true, false);
  1158. notificationMessages.clear();
  1159. //t.printElapsedTime("Indexing size():" + notificationMessages.size() + " took");
  1160. Integer newLastContentVersionIdCandidate = getNotificationMessages(notificationMessages, languageVO, newLastContentVersionId, lastCommitedDateTime, 1000);
  1161. logger.info("newLastContentVersionIdCandidate:" + newLastContentVersionIdCandidate + "=" + newLastContentVersionId);
  1162. if(newLastContentVersionIdCandidate > newLastContentVersionId)
  1163. newLastContentVersionId = newLastContentVersionIdCandidate;
  1164. else
  1165. break;
  1166. //t.printElapsedTime("newLastContentVersionId:" + newLastContentVersionId + " took");
  1167. }
  1168. }
  1169. if(logger.isInfoEnabled())
  1170. t2.printElapsedTime("All indexing took");
  1171. return true;
  1172. }
  1173. private int getNotificationMessagesForStructure(List<NotificationMessage> notificationMessages, LanguageVO languageVO, int lastSiteNodeVersionId) throws Exception
  1174. {
  1175. Timer t = new Timer();
  1176. logger.info("getNotificationMessages:" + lastSiteNodeVersionId);
  1177. int newLastSiteNodeVersionId = -1;
  1178. Database db = CastorDatabaseService.getDatabase();
  1179. try
  1180. {
  1181. beginTransaction(db);
  1182. ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db);
  1183. ContentVersionVO lastContentVersionVO = ContentVersionController.getContentVersionController().getLatestContentVersionVO(languageVO.getId(), db);
  1184. Integer maxContentVersionId = (lastContentVersionVO == null ? 1000 : lastContentVersionVO.getId());
  1185. logger.info("maxContentVersionId:" + maxContentVersionId + " for " + languageVO.getName());
  1186. List<ContentVersionVO> versions = new ArrayList<ContentVersionVO>();
  1187. if(CmsPropertyHandler.getApplicationName().equalsIgnoreCase("cms"))
  1188. {
  1189. versions = ContentVersionController.getContentVersionController().getContentVersionVOList(contentTypeDefinitionVO.getId(), null, languageVO.getId(), false, 0, newLastSiteNodeVersionId, numberOfVersionToIndexInBatch, numberOfVersionToIndexInBatch*10, true, db, true, maxContentVersionId);
  1190. }
  1191. else
  1192. {
  1193. versions = ContentVersionController.getContentVersionController().getContentVersionVOList(contentTypeDefinitionVO.getId(), null, languageVO.getId(), false, Integer.parseInt(CmsPropertyHandler.getOperatingMode()), newLastSiteNodeVersionId, numberOfVersionToIndexInBatch, numberOfVersionToIndexInBatch*10, true, db, true, maxContentVersionId);
  1194. }
  1195. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Index all : getContentVersionVOList", t.getElapsedTime());
  1196. logger.info("versions in getNotificationMessagesForStructure:" + versions.size());
  1197. logger.info("Looping versions:" + versions.size());
  1198. for(ContentVersionVO version : versions)
  1199. {
  1200. NotificationMessage notificationMessage = new NotificationMessage("LuceneController", ContentVersionImpl.class.getName(), "SYSTEM", NotificationMessage.TRANS_UPDATE, version.getId(), "dummy");
  1201. notificationMessages.add(notificationMessage);
  1202. newLastSiteNodeVersionId = version.getId().intValue();
  1203. }
  1204. logger.info("Finished round 1:" + notificationMessages.size() + ":" + newLastSiteNodeVersionId);
  1205. }
  1206. catch ( Exception e )
  1207. {
  1208. rollbackTransaction(db);
  1209. throw new SystemException("An error occurred when we tried to fetch a list of users in this role. Reason:" + e.getMessage(), e);
  1210. }
  1211. commitTransaction(db);
  1212. return newLastSiteNodeVersionId;
  1213. }
  1214. private int getContentNotificationMessages(LanguageVO languageVO, int lastContentVersionId) throws Exception
  1215. {
  1216. Timer t = new Timer();
  1217. logger.info("getNotificationMessages:" + languageVO.getName() + " : " + lastContentVersionId);
  1218. logger.info("notifyListeners actually running");
  1219. if(getIsIndexedLocked())
  1220. {
  1221. logger.info("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.");
  1222. unlockIndex();
  1223. }
  1224. IndexWriter writer = getIndexWriter();
  1225. //t.printElapsedTime("Creating writer took");
  1226. int newLastContentVersionId = -1;
  1227. Database db = CastorDatabaseService.getDatabase();
  1228. try
  1229. {
  1230. beginTransaction(db);
  1231. logger.info("lastContentVersionId:" + lastContentVersionId);
  1232. if(lastContentVersionId < 1)
  1233. {
  1234. SmallestContentVersionVO firstContentVersionVO = ContentVersionController.getContentVersionController().getFirstContentVersionId(languageVO.getId(), db);
  1235. if(firstContentVersionVO != null)
  1236. lastContentVersionId = firstContentVersionVO.getId();
  1237. }
  1238. logger.info("lastContentVersionId 2:" + lastContentVersionId);
  1239. ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db);
  1240. ContentVersionVO lastContentVersionVO = ContentVersionController.getContentVersionController().getLatestContentVersionVO(languageVO.getId(), db);
  1241. Integer maxContentVersionId = (lastContentVersionVO == null ? 1000 : lastContentVersionVO.getId());
  1242. logger.info("maxContentVersionId 1:" + maxContentVersionId + " for " + languageVO.getName());
  1243. List<ContentVersionVO> versions = new ArrayList<ContentVersionVO>();
  1244. if(CmsPropertyHandler.getApplicationName().equalsIgnoreCase("cms"))
  1245. {
  1246. versions = ContentVersionController.getContentVersionController().getContentVersionVOList(null, contentTypeDefinitionVO.getId(), languageVO.getId(), false, 0, lastContentVersionId, numberOfVersionToIndexInBatch, numberOfVersionToIndexInBatch*10, true, db, false, maxContentVersionId);
  1247. }
  1248. else
  1249. {
  1250. versions = ContentVersionController.getContentVersionController().getContentVersionVOList(null, contentTypeDefinitionVO.getId(), languageVO.getId(), false, Integer.parseInt(CmsPropertyHandler.getOperatingMode()), lastContentVersionId, numberOfVersionToIndexInBatch, numberOfVersionToIndexInBatch*10, true, db, false, maxContentVersionId);
  1251. }
  1252. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Index all : getContentVersionVOList", t.getElapsedTime());
  1253. logger.info("versions in getContentNotificationMessages:" + versions.size());
  1254. logger.info("Looping versions:" + versions.size());
  1255. for(ContentVersionVO version : versions)
  1256. {
  1257. if(stopIndexing.get())
  1258. return newLastContentVersionId;
  1259. Document document = getDocumentFromContentVersion(version, db);
  1260. String uid = document.get("uid");
  1261. logger.info("document: " + document);
  1262. writer.deleteDocuments(new Term("uid", "" + uid));
  1263. if(logger.isDebugEnabled())
  1264. logger.debug("Adding document with uid:" + uid + " - " + document);
  1265. if(document != null)
  1266. writer.addDocument(document);
  1267. logger.info("version assetCount:" + version.getAssetCount());
  1268. if(version.getAssetCount() == null || version.getAssetCount() > 0)
  1269. {
  1270. List digitalAssetVOList = DigitalAssetController.getDigitalAssetVOList(version.getId(), db);
  1271. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDigitalAssetVOList", (t.getElapsedTimeNanos() / 1000));
  1272. if(digitalAssetVOList.size() > 0)
  1273. {
  1274. logger.info("digitalAssetVOList:" + digitalAssetVOList.size());
  1275. Iterator digitalAssetVOListIterator = digitalAssetVOList.iterator();
  1276. while(digitalAssetVOListIterator.hasNext())
  1277. {
  1278. DigitalAssetVO assetVO = (DigitalAssetVO)digitalAssetVOListIterator.next();
  1279. Document assetDocument = getDocumentFromDigitalAsset(assetVO, version, db);
  1280. String assetUid = assetDocument.get("uid");
  1281. writer.deleteDocuments(new Term("uid", "" + assetUid));
  1282. if(logger.isDebugEnabled())
  1283. logger.debug("Adding document with assetUid:" + assetUid + " - " + assetDocument);
  1284. if(assetDocument != null)
  1285. writer.addDocument(assetDocument);
  1286. }
  1287. }
  1288. }
  1289. newLastContentVersionId = version.getId().intValue();
  1290. }
  1291. //logger.info("Finished round 2:" + notificationMessages.size() + ":" + newLastContentVersionId);
  1292. }
  1293. catch ( Exception e )
  1294. {
  1295. logger.error("Error in lucene indexing: " + e.getMessage(), e);
  1296. rollbackTransaction(db);
  1297. throw new SystemException("An error occurred when we tried to getContentNotificationMessages. Reason:" + e.getMessage(), e);
  1298. }
  1299. finally
  1300. {
  1301. try{setLastCommitedContentVersionId(writer, newLastContentVersionId); writer.commit(); /*writer.close(true);*/}catch (Exception e) {e.printStackTrace();}
  1302. }
  1303. commitTransaction(db);
  1304. return newLastContentVersionId;
  1305. }
  1306. private int getPageNotificationMessages(List notificationMessages, LanguageVO languageVO, int lastContentVersionId) throws Exception
  1307. {
  1308. Timer t = new Timer();
  1309. logger.info("getNotificationMessages:" + languageVO.getName() + " : " + lastContentVersionId);
  1310. logger.info("notifyListeners actually running");
  1311. if(getIsIndexedLocked())
  1312. {
  1313. logger.info("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.");
  1314. unlockIndex();
  1315. }
  1316. IndexWriter writer = getIndexWriter();
  1317. //t.printElapsedTime("Creating writer took");
  1318. int newLastContentVersionId = -1;
  1319. Database db = CastorDatabaseService.getDatabase();
  1320. try
  1321. {
  1322. beginTransaction(db);
  1323. ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db);
  1324. ContentVersionVO lastContentVersionVO = ContentVersionController.getContentVersionController().getLatestContentVersionVO(languageVO.getId(), db);
  1325. Integer maxContentVersionId = (lastContentVersionVO == null ? 1000 : lastContentVersionVO.getId());
  1326. logger.info("maxContentVersionId:" + maxContentVersionId + " for " + languageVO.getName());
  1327. List<ContentVersionVO> versions = new ArrayList<ContentVersionVO>();
  1328. if(CmsPropertyHandler.getApplicationName().equalsIgnoreCase("cms"))
  1329. {
  1330. versions = ContentVersionController.getContentVersionController().getContentVersionVOList(contentTypeDefinitionVO.getId(), null, languageVO.getId(), false, 0, lastContentVersionId, numberOfVersionToIndexInBatch, numberOfVersionToIndexInBatch*10, true, db, true, maxContentVersionId);
  1331. }
  1332. else
  1333. {
  1334. versions = ContentVersionController.getContentVersionController().getContentVersionVOList(contentTypeDefinitionVO.getId(), null, languageVO.getId(), false, Integer.parseInt(CmsPropertyHandler.getOperatingMode()), lastContentVersionId, numberOfVersionToIndexInBatch, numberOfVersionToIndexInBatch*10, true, db, true, maxContentVersionId);
  1335. }
  1336. logger.info("versions:" + versions.size());
  1337. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Index all : getContentVersionVOList", t.getElapsedTime());
  1338. logger.info("versions in getContentNotificationMessages:" + versions.size());
  1339. logger.info("Looping versions:" + versions.size());
  1340. for(ContentVersionVO version : versions)
  1341. {
  1342. if(stopIndexing.get())
  1343. return newLastContentVersionId;
  1344. Document documents = getSiteNodeDocument(version, writer, db);
  1345. if (documents != null)
  1346. {
  1347. String uid = documents.get("uid");
  1348. logger.debug("Regging doc: " + documents);
  1349. writer.deleteDocuments(new Term("uid", "" + uid));
  1350. if(logger.isDebugEnabled())
  1351. logger.debug("Adding document with uid:" + uid + " - " + documents);
  1352. writer.addDocument(documents);
  1353. }
  1354. else if(logger.isInfoEnabled())
  1355. {
  1356. logger.info("Failed to get document for SiteNode. Meta info content.id: " + version.getContentVersionId());
  1357. }
  1358. /*
  1359. logger.info("version assetCount:" + version.getAssetCount());
  1360. if(version.getAssetCount() == null || version.getAssetCount() > 0)
  1361. {
  1362. List digitalAssetVOList = DigitalAssetController.getDigitalAssetVOList(version.getId(), db);
  1363. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDigitalAssetVOList", (t.getElapsedTimeNanos() / 1000));
  1364. if(digitalAssetVOList.size() > 0)
  1365. {
  1366. logger.info("digitalAssetVOList:" + digitalAssetVOList.size());
  1367. Iterator digitalAssetVOListIterator = digitalAssetVOList.iterator();
  1368. while(digitalAssetVOListIterator.hasNext())
  1369. {
  1370. DigitalAssetVO assetVO = (DigitalAssetVO)digitalAssetVOListIterator.next();
  1371. NotificationMessage assetNotificationMessage = new NotificationMessage("LuceneController", DigitalAssetImpl.class.getName(), "SYSTEM", NotificationMessage.TRANS_UPDATE, assetVO.getId(), "dummy");
  1372. notificationMessages.add(assetNotificationMessage);
  1373. }
  1374. }
  1375. }
  1376. NotificationMessage notificationMessage = new NotificationMessage("LuceneController", ContentVersionImpl.class.getName(), "SYSTEM", NotificationMessage.TRANS_UPDATE, version.getId(), "dummy");
  1377. notificationMessages.add(notificationMessage);
  1378. */
  1379. newLastContentVersionId = version.getId().intValue();
  1380. }
  1381. logger.info("Finished round 3:" + notificationMessages.size() + ":" + newLastContentVersionId);
  1382. }
  1383. catch ( Exception e )
  1384. {
  1385. rollbackTransaction(db);
  1386. throw new SystemException("An error occurred when we tried to fetch a list of users in this role. Reason:" + e.getMessage(), e);
  1387. }
  1388. finally
  1389. {
  1390. try{setLastCommitedContentVersionId(writer, newLastContentVersionId); writer.commit(); /*writer.close(true);*/}catch (Exception e) {e.printStackTrace();}
  1391. }
  1392. commitTransaction(db);
  1393. return newLastContentVersionId;
  1394. }
  1395. public void testSQL()
  1396. {
  1397. try {
  1398. getNotificationMessages(new ArrayList(), LanguageController.getController().getLanguageVOWithCode("sv"), 100000, new Date(), 1000);
  1399. } catch (Exception e) {
  1400. // TODO Auto-generated catch block
  1401. e.printStackTrace();
  1402. logger.error("Errro:" + e.getMessage(), e);
  1403. }
  1404. }
  1405. private int getNotificationMessages(List notificationMessages, LanguageVO languageVO, int lastContentVersionId, Date lastCheckDateTime, int batchSize) throws Exception
  1406. {
  1407. Timer t = new Timer();
  1408. logger.info("getNotificationMessages:" + languageVO.getName() + " : " + lastContentVersionId + ":" + lastCheckDateTime);
  1409. int newLastContentVersionId = -1;
  1410. Database db = CastorDatabaseService.getDatabase();
  1411. try
  1412. {
  1413. beginTransaction(db);
  1414. logger.info("**************Getting contents start:" + t.getElapsedTime() + ":" + lastCheckDateTime);
  1415. Calendar date = Calendar.getInstance();
  1416. date.setTime(lastCheckDateTime);
  1417. date.add(Calendar.DAY_OF_YEAR, -1);
  1418. //String SQL = "select cv.contentVersionId, cv.stateId, cv.modifiedDateTime, cv.versionComment, cv.isCheckedOut, cv.isActive, cv.contentId, cv.languageId, cv.versionModifier FROM cmContentVersion cv where cv.languageId = $1 AND cv.isActive = $2 AND ((cv.contentVersionId > $3 AND cv.contentVersionId < $4) OR cv.modifiedDateTime > $5) ORDER BY cv.contentVersionId";
  1419. //if(CmsPropertyHandler.getUseShortTableNames() != null && CmsPropertyHandler.getUseShortTableNames().equalsIgnoreCase("true"))
  1420. // SQL = "select cv.contVerId, cv.stateId, cv.modifiedDateTime, cv.verComment, cv.isCheckedOut, cv.isActive, cv.contId, cv.languageId, cv.versionModifier FROM cmContVer cv where cv.languageId = $1 AND cv.isActive = $2 AND ((cv.contVerId > $3 AND cv.contVerId < $4) OR cv.modifiedDateTime > TO_DATE('2013-03-20','YYYY-MM-DD')) ORDER BY cv.contVerId";
  1421. //System.out.println("SQL:" + SQL);
  1422. //OQLQuery oql = db.getOQLQuery("CALL SQL " + SQL + " AS org.infoglue.cms.entities.content.impl.simple.SmallestContentVersionImpl");
  1423. //if(CmsPropertyHandler.getUseShortTableNames() != null && CmsPropertyHandler.getUseShortTableNames().equalsIgnoreCase("true"))
  1424. // oql = db.getOQLQuery("CALL SQL " + SQL + " AS org.infoglue.cms.entities.content.impl.simple.SmallestContentVersionImpl");
  1425. //oracle.sql.DATE oracleDate = new oracle.sql.DATE(new java.sql.Date(date.getTime().getTime()));
  1426. OQLQuery oql = db.getOQLQuery( "SELECT cv FROM " + SmallestContentVersionImpl.class.getName() + " cv WHERE cv.languageId = $1 AND cv.isActive = $2 AND ((cv.contentVersionId > $3 AND cv.contentVersionId < $4) OR cv.modifiedDateTime > $5) ORDER BY cv.contentVersionId limit $6");
  1427. //OQLQuery oql = db.getOQLQuery( "SELECT cv FROM " + SmallestContentVersionImpl.class.getName() + " cv WHERE cv.languageId = $1 AND cv.isActive = $2 AND ((cv.contentVersionId > $3 AND cv.contentVersionId < $4)) ORDER BY cv.contentVersionId limit $5");
  1428. oql.bind(languageVO.getId());
  1429. oql.bind(true);
  1430. oql.bind(lastContentVersionId);
  1431. oql.bind(lastContentVersionId+(batchSize*10));
  1432. //oql.bind(date.getTime());
  1433. oql.bind(date.getTime());
  1434. oql.bind(batchSize);
  1435. QueryResults results = oql.execute(Database.ReadOnly);
  1436. if(logger.isInfoEnabled())
  1437. logger.info("Getting contents took: " + t.getElapsedTime());
  1438. int processedItems = 0;
  1439. Integer previousContentId = null;
  1440. while (results.hasMore())
  1441. {
  1442. SmallestContentVersionImpl smallestContentVersionImpl = (SmallestContentVersionImpl)results.next();
  1443. if(previousContentId == null || !previousContentId.equals(smallestContentVersionImpl.getContentId()))
  1444. {
  1445. List digitalAssetVOList = DigitalAssetController.getDigitalAssetVOList(smallestContentVersionImpl.getId(), db);
  1446. if(digitalAssetVOList.size() > 0)
  1447. {
  1448. logger.info("digitalAssetVOList:" + digitalAssetVOList.size());
  1449. Iterator digitalAssetVOListIterator = digitalAssetVOList.iterator();
  1450. while(digitalAssetVOListIterator.hasNext())
  1451. {
  1452. DigitalAssetVO assetVO = (DigitalAssetVO)digitalAssetVOListIterator.next();
  1453. if(assetVO.getAssetFileSize() < 10000000) //Do not index large files
  1454. {
  1455. NotificationMessage assetNotificationMessage = new NotificationMessage("LuceneController", DigitalAssetImpl.class.getName(), "SYSTEM", NotificationMessage.TRANS_UPDATE, assetVO.getId(), "dummy");
  1456. notificationMessages.add(assetNotificationMessage);
  1457. }
  1458. }
  1459. }
  1460. NotificationMessage notificationMessage = new NotificationMessage("LuceneController", ContentVersionImpl.class.getName(), "SYSTEM", NotificationMessage.TRANS_UPDATE, smallestContentVersionImpl.getId(), "dummy");
  1461. notificationMessages.add(notificationMessage);
  1462. previousContentId = smallestContentVersionImpl.getContentId();
  1463. }
  1464. newLastContentVersionId = smallestContentVersionImpl.getId().intValue();
  1465. lastCommitedContentVersionId = newLastContentVersionId;
  1466. processedItems++;
  1467. logger.info("previousContentId:" + previousContentId + "/" + processedItems);
  1468. if(processedItems > batchSize)
  1469. {
  1470. System.out.println("Batch full...");
  1471. break;
  1472. }
  1473. }
  1474. results.close();
  1475. logger.info("Finished round 4:" + processedItems + ":" + newLastContentVersionId);
  1476. }
  1477. catch ( Exception e )
  1478. {
  1479. rollbackTransaction(db);
  1480. throw new SystemException("An error occurred when we tried to fetch a list of users in this role. Reason:" + e.getMessage(), e);
  1481. }
  1482. commitTransaction(db);
  1483. return newLastContentVersionId;
  1484. }
  1485. private void indexInformation(NotificationMessage notificationMessage, IndexWriter writer, List<NotificationMessage> internalMessageList, Boolean forceVersionIndexing, Database db)
  1486. {
  1487. Timer t = new Timer();
  1488. try
  1489. {
  1490. try
  1491. {
  1492. //writer.setMaxMergeDocs(500000);
  1493. if(logger.isInfoEnabled())
  1494. logger.info("Indexing to directory '" + writer.getDirectory().toString() + "'...");
  1495. List<Document> documents = getDocumentsForIncremental(notificationMessage, writer, forceVersionIndexing, db);
  1496. Iterator<Document> documentsIterator = documents.iterator();
  1497. while(documentsIterator.hasNext())
  1498. {
  1499. Document indexingDocument = documentsIterator.next();
  1500. String uid = indexingDocument.get("uid");
  1501. if(logger.isDebugEnabled())
  1502. logger.debug("Adding document with uid:" + uid + " - " + indexingDocument);
  1503. //logger.error("Adding document with uid:" + uid + " - " + indexingDocument);
  1504. if(indexingDocument != null)
  1505. writer.addDocument(indexingDocument);
  1506. }
  1507. }
  1508. catch (Exception e)
  1509. {
  1510. logger.error("Error indexing:" + e.getMessage(), e);
  1511. }
  1512. finally
  1513. {
  1514. indexedDocumentsSinceLastOptimize++;
  1515. if(indexedDocumentsSinceLastOptimize > 1000)
  1516. {
  1517. indexedDocumentsSinceLastOptimize = 0;
  1518. }
  1519. }
  1520. }
  1521. catch (Exception e)
  1522. {
  1523. logger.error("Error indexing:" + e.getMessage(), e);
  1524. }
  1525. }
  1526. private List<Document> getDocumentsForIncremental(NotificationMessage notificationMessage, IndexWriter writer, Boolean forceVersionIndexing, Database db) throws Exception
  1527. {
  1528. Timer t = new Timer();
  1529. List<Document> returnDocuments = new ArrayList<Document>();
  1530. logger.info("2222222222 notificationMessage.getClassName():" + notificationMessage.getClassName() + " in " + CmsPropertyHandler.getApplicationName());
  1531. Set<Integer> contentIdsToIndex = new HashSet<Integer>();
  1532. Set<Integer> siteNodeIdsToIndex = new HashSet<Integer>();
  1533. if(notificationMessage.getClassName().equals(ContentImpl.class.getName()) || notificationMessage.getClassName().equals(Content.class.getName()))
  1534. {
  1535. logger.info("++++++++++++++Got an Content notification: " + notificationMessage.getObjectId());
  1536. ContentVO contentVO = ContentController.getContentController().getContentVOWithId((Integer)notificationMessage.getObjectId(), db);
  1537. //ContentVO contentVO = ContentController.getContentController().getContentVOWithId((Integer)notificationMessage.getObjectId());
  1538. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVOWithId", (t.getElapsedTimeNanos() / 1000));
  1539. contentIdsToIndex.add(contentVO.getId());
  1540. }
  1541. else if(notificationMessage.getClassName().equals(ContentVersionImpl.class.getName()) || notificationMessage.getClassName().equals(ContentVersion.class.getName()))
  1542. {
  1543. logger.info("++++++++++++++Got an ContentVersion notification: " + notificationMessage.getObjectId());
  1544. ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId((Integer)notificationMessage.getObjectId(), db);
  1545. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVersionVOWithId", t.getElapsedTime());
  1546. contentIdsToIndex.add(contentVersionVO.getContentId());
  1547. }
  1548. else if(notificationMessage.getClassName().equals(DigitalAssetImpl.class.getName()) || notificationMessage.getClassName().equals(DigitalAsset.class.getName()))
  1549. {
  1550. logger.info("++++++++++++++Got an DigitalAssetImpl notification: " + notificationMessage.getObjectId());
  1551. Database db2 = CastorDatabaseService.getDatabase();
  1552. beginTransaction(db2);
  1553. try
  1554. {
  1555. DigitalAssetVO asset = DigitalAssetController.getSmallDigitalAssetVOWithId((Integer)notificationMessage.getObjectId(), db2);
  1556. //MediumDigitalAssetImpl asset = (MediumDigitalAssetImpl)DigitalAssetController.getMediumDigitalAssetWithIdReadOnly((Integer)notificationMessage.getObjectId(), db2);
  1557. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getMediumDigitalAssetWithIdReadOnly", t.getElapsedTime());
  1558. //Collection contentVersions = asset.getContentVersions();
  1559. List<SmallestContentVersionVO> contentVersionVOList = DigitalAssetController.getContentVersionVOListConnectedToAssetWithId((Integer)notificationMessage.getObjectId());
  1560. if(logger.isInfoEnabled())
  1561. logger.info("contentVersionVOList:" + contentVersionVOList.size());
  1562. Iterator<SmallestContentVersionVO> contentVersionsIterator = contentVersionVOList.iterator();
  1563. while(contentVersionsIterator.hasNext())
  1564. {
  1565. SmallestContentVersionVO version = contentVersionsIterator.next();
  1566. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("contentVersionsIterator", t.getElapsedTime());
  1567. ContentVersionVO cvVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(version.getId(), db2);
  1568. Document document = getDocumentFromDigitalAsset(asset, cvVO, db);
  1569. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDocumentFromDigitalAsset", t.getElapsedTime());
  1570. logger.info("00000000000000000: Adding asset document:" + document);
  1571. if(document != null)
  1572. returnDocuments.add(document);
  1573. }
  1574. commitTransaction(db2);
  1575. }
  1576. catch(Exception e)
  1577. {
  1578. logger.error("An error occurred so we should not complete the transaction:" + e, e);
  1579. rollbackTransaction(db2);
  1580. throw new SystemException(e.getMessage());
  1581. }
  1582. }
  1583. else if(notificationMessage.getClassName().equals(SiteNodeImpl.class.getName()) || notificationMessage.getClassName().equals(SiteNode.class.getName()))
  1584. {
  1585. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId((Integer)notificationMessage.getObjectId(), db);
  1586. if (siteNodeVO == null)
  1587. {
  1588. logger.warn("Could not find SiteNode with id: " + notificationMessage.getObjectId());
  1589. }
  1590. else
  1591. {
  1592. siteNodeIdsToIndex.add(siteNodeVO.getId());
  1593. }
  1594. }
  1595. logger.info("Indexing:" + siteNodeIdsToIndex.size());
  1596. for(Integer siteNodeId : siteNodeIdsToIndex)
  1597. {
  1598. //Deleting all info based on content
  1599. Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
  1600. logger.info("Deleting all info on:" + siteNodeId);
  1601. //TODO - Fixa sŒ inte assets tas med hŠr....
  1602. Query query = new QueryParser(Version.LUCENE_34, "siteNodeId", analyzer).parse("" + siteNodeId);
  1603. writer.deleteDocuments(query);
  1604. //End
  1605. logger.info("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ:" + notificationMessage.getObjectId());
  1606. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId((Integer)notificationMessage.getObjectId(), db);
  1607. logger.info("$$$$$$$$$$Getting doc for " + siteNodeVO.getName());
  1608. Document document = getDocumentFromSiteNode(siteNodeVO, writer, db);
  1609. logger.info("document " + document);
  1610. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDocumentFromSiteNode", t.getElapsedTime());
  1611. if(document != null)
  1612. returnDocuments.add(document);
  1613. }
  1614. logger.info("Indexing contentIdsToIndex:" + contentIdsToIndex.size());
  1615. for(Integer contentId : contentIdsToIndex)
  1616. {
  1617. //Deleting all info based on content
  1618. Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
  1619. logger.info("Deleting all info on:" + contentId);
  1620. //TODO - Fixa sŒ inte assets tas med hŠr....
  1621. String[] fields = new String[]{"isAsset","contentId"};
  1622. String[] queries = new String[]{"true","" + contentId};
  1623. BooleanClause.Occur[] flags = new BooleanClause.Occur[]{BooleanClause.Occur.MUST_NOT,BooleanClause.Occur.MUST};
  1624. Query query = MultiFieldQueryParser.parse(Version.LUCENE_34, queries, fields, flags, analyzer);
  1625. //Query query = new QueryParser(Version.LUCENE_34, "contentId", analyzer).parse("" + contentId);
  1626. writer.deleteDocuments(query);
  1627. //End
  1628. ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId, db);
  1629. Document document = getDocumentFromContent(contentVO, notificationMessage, writer, forceVersionIndexing, db);
  1630. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDocumentFromContent", (t.getElapsedTimeNanos() / 1000));
  1631. if(document != null)
  1632. {
  1633. returnDocuments.add(document);
  1634. logger.info("++++++++++++++Forcing cv indexing");
  1635. List<ContentVersionVO> versions = new ArrayList<ContentVersionVO>();
  1636. if(CmsPropertyHandler.getApplicationName().equalsIgnoreCase("cms"))
  1637. {
  1638. //List<LanguageVO> languages = LanguageController.getController().getLanguageVOList(contentVO.getRepositoryId());
  1639. List<LanguageVO> languages = LanguageController.getController().getLanguageVOList(contentVO.getRepositoryId(), db);
  1640. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getLanguageVOList", (t.getElapsedTimeNanos() / 1000));
  1641. for(LanguageVO language : languages)
  1642. {
  1643. ContentVersionVO latestVersion = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentVO.getId(), language.getId(), Integer.parseInt(CmsPropertyHandler.getOperatingMode()), db);
  1644. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getLatestActiveContentVersionVO", (t.getElapsedTimeNanos() / 1000));
  1645. if(latestVersion != null)
  1646. versions.add(latestVersion);
  1647. ContentVersionVO latestVersionPublishedVersion = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentVO.getId(), language.getId(), ContentVersionVO.PUBLISHED_STATE, db);
  1648. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getLatestActiveContentVersionVO", (t.getElapsedTimeNanos() / 1000));
  1649. if(latestVersionPublishedVersion != null && latestVersionPublishedVersion.getId().intValue() != latestVersion.getId().intValue())
  1650. versions.add(latestVersionPublishedVersion);
  1651. }
  1652. }
  1653. else
  1654. {
  1655. List<LanguageVO> languages = LanguageController.getController().getLanguageVOList(contentVO.getRepositoryId(), db);
  1656. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getLanguageVOList", (t.getElapsedTimeNanos() / 1000));
  1657. for(LanguageVO language : languages)
  1658. {
  1659. ContentVersionVO version = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentVO.getId(), language.getId(), Integer.parseInt(CmsPropertyHandler.getOperatingMode()), db);
  1660. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getLatestActiveContentVersionVO", (t.getElapsedTimeNanos() / 1000));
  1661. if(version != null)
  1662. versions.add(version);
  1663. }
  1664. }
  1665. logger.info("versions:" + versions.size());
  1666. for(ContentVersionVO version : versions)
  1667. {
  1668. logger.info("version:" + version.getId());
  1669. Document versionDocument = getDocumentFromContentVersion(version, db);
  1670. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDocumentFromContentVersion", t.getElapsedTime());
  1671. if(versionDocument != null)
  1672. returnDocuments.add(versionDocument);
  1673. if(version.getId() > this.lastCommitedContentVersionId)
  1674. lastCommitedContentVersionId = version.getId();
  1675. }
  1676. }
  1677. }
  1678. return returnDocuments;
  1679. }
  1680. private List<Document> getDocumentsForContentVersion(ContentVersionVO contentVersionVO, Database db) throws Exception
  1681. {
  1682. Timer t = new Timer();
  1683. List<Document> returnDocuments = new ArrayList<Document>();
  1684. //ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId(), db);
  1685. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVOWithId", (t.getElapsedTimeNanos() / 1000));
  1686. Document document = getDocumentFromContentVersion(contentVersionVO, db);
  1687. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDocumentFromContentVersion", t.getElapsedTime());
  1688. if(document != null)
  1689. returnDocuments.add(document);
  1690. return returnDocuments;
  1691. }
  1692. public Document getDocumentFromSiteNode(SiteNodeVO siteNodeVO, IndexWriter writer, Database db) throws Exception, InterruptedException
  1693. {
  1694. logger.info("getDocumentFromSiteNode:" + siteNodeVO.getName() + ":" + siteNodeVO.getIsDeleted());
  1695. if(siteNodeVO == null || siteNodeVO.getIsDeleted())
  1696. {
  1697. logger.info("Adding a delete directive to the indexer");
  1698. String uid = "siteNodeId_" + siteNodeVO.getId();
  1699. logger.info("Deleting documents:" + "uid=" + uid);
  1700. logger.info("Before delete:" + writer.numDocs());
  1701. //writer.deleteDocuments(new Term("uid", "" + uid));
  1702. Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
  1703. Query query = new QueryParser(Version.LUCENE_34, "siteNodeId", analyzer).parse("" + siteNodeVO.getId());
  1704. writer.deleteDocuments(query);
  1705. logger.info("Before delete:" + writer.numDocs());
  1706. return null;
  1707. }
  1708. // make a new, empty document
  1709. Document doc = new Document();
  1710. // Add the last modified date of the file a field named "modified".
  1711. // Use a field that is indexed (i.e. searchable), but don't tokenize
  1712. // the field into words.
  1713. doc.add(new NumericField("publishDateTime", Field.Store.YES, true).setLongValue(siteNodeVO.getPublishDateTime().getTime()));
  1714. doc.add(new Field("modified", DateTools.timeToString(new Date().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1715. doc.add(new Field("siteNodeId", "" + siteNodeVO.getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1716. doc.add(new Field("repositoryId", "" + siteNodeVO.getRepositoryId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1717. doc.add(new Field("lastModifier", "" + siteNodeVO.getCreatorName(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1718. doc.add(new Field("isAsset", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1719. doc.add(new Field("isSiteNode", "true", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1720. SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestActiveSiteNodeVersionVO(db, siteNodeVO.getId());
  1721. if(siteNodeVersionVO != null)
  1722. {
  1723. doc.add(new NumericField("modificationDateTime", Field.Store.YES, true).setLongValue(siteNodeVersionVO.getModifiedDateTime().getTime()));
  1724. doc.add(new Field("siteNodeVersionId", "" + siteNodeVersionVO.getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1725. doc.add(new Field("stateId", "" + siteNodeVersionVO.getStateId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1726. doc.add(new Field("path", "" + getSiteNodePath(siteNodeVO.getId(), db), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1727. }
  1728. // Add the uid as a field, so that index can be incrementally
  1729. // maintained.
  1730. // This field is not stored with document, it is indexed, but it is not
  1731. // tokenized prior to indexing.
  1732. doc.add(new Field("uid", "siteNodeId_" + siteNodeVO.getId(), Field.Store.NO, Field.Index.NOT_ANALYZED));
  1733. // Add the tag-stripped contents as a Reader-valued Text field so it
  1734. // will
  1735. // get tokenized and indexed.
  1736. doc.add(new Field("contents", new StringReader(siteNodeVO.getName())));
  1737. if(siteNodeVO.getMetaInfoContentId() != null && siteNodeVO.getMetaInfoContentId() > -1)
  1738. {
  1739. List<LanguageVO> languages = LanguageController.getController().getLanguageVOList(siteNodeVO.getRepositoryId(), db);
  1740. for(LanguageVO language : languages)
  1741. {
  1742. ContentVersionVO cvVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(siteNodeVO.getMetaInfoContentId(), language.getId(), Integer.parseInt(CmsPropertyHandler.getOperatingMode()), db);
  1743. if(cvVO != null)
  1744. doc.add(new Field("contents", new StringReader(cvVO.getVersionValue())));
  1745. }
  1746. }
  1747. // return the document
  1748. return doc;
  1749. }
  1750. public Document getSiteNodeDocument(ContentVersionVO contentVersionVO, IndexWriter writer, Database db) throws Exception, InterruptedException
  1751. {
  1752. Timer t = new Timer();
  1753. ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId(), db);
  1754. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVOWithId", (t.getElapsedTimeNanos() / 1000));
  1755. if(contentVO.getIsDeleted())
  1756. return null;
  1757. if (contentVersionVO.getSiteNodeId() == null || contentVersionVO.getSiteNodeName() == null)
  1758. {
  1759. logger.warn("Content version does not have a SiteNode connected. Will not index content version. ContentVersion.id: " + contentVersionVO.getContentVersionId());
  1760. return null;
  1761. }
  1762. // make a new, empty document
  1763. Document doc = new Document();
  1764. // Add the last modified date of the file a field named "modified".
  1765. // Use a field that is indexed (i.e. searchable), but don't tokenize
  1766. // the field into words.
  1767. doc.add(new NumericField("publishDateTime", Field.Store.YES, true).setLongValue(contentVersionVO.getModifiedDateTime().getTime()));
  1768. doc.add(new Field("modified", DateTools.timeToString(new Date().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1769. doc.add(new Field("siteNodeId", "" + contentVersionVO.getSiteNodeId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1770. doc.add(new Field("repositoryId", "" + contentVO.getRepositoryId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1771. doc.add(new Field("lastModifier", "" + contentVersionVO.getVersionModifier(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1772. doc.add(new Field("isAsset", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1773. doc.add(new Field("isSiteNode", "true", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1774. //doc.add(new Field("contentTypeDefinitionId", "" + ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db).getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1775. try
  1776. {
  1777. SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestActiveSiteNodeVersionVO(db, contentVersionVO.getSiteNodeId());
  1778. if(siteNodeVersionVO != null)
  1779. doc.add(new Field("siteNodeVersionId", "" + siteNodeVersionVO.getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1780. else
  1781. logger.warn("No site node version found on siteNode: " + contentVersionVO.getSiteNodeId());
  1782. }
  1783. catch (Exception e)
  1784. {
  1785. e.printStackTrace();
  1786. }
  1787. doc.add(new NumericField("modificationDateTime", Field.Store.YES, true).setLongValue(contentVersionVO.getModifiedDateTime().getTime()));
  1788. doc.add(new Field("stateId", "" + contentVersionVO.getStateId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1789. doc.add(new Field("path", "" + getSiteNodePath(contentVersionVO.getSiteNodeId(), db), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1790. // Add the uid as a field, so that index can be incrementally
  1791. // maintained.
  1792. // This field is not stored with document, it is indexed, but it is not
  1793. // tokenized prior to indexing.
  1794. doc.add(new Field("uid", "siteNodeId_" + contentVersionVO.getSiteNodeId(), Field.Store.NO, Field.Index.NOT_ANALYZED));
  1795. // Add the tag-stripped contents as a Reader-valued Text field so it
  1796. // will
  1797. // get tokenized and indexed.
  1798. String pageName = contentVersionVO.getSiteNodeName();
  1799. if(pageName == null)
  1800. {
  1801. logger.info("Have to read again...");
  1802. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(contentVersionVO.getSiteNodeId(), db);
  1803. pageName = siteNodeVO.getName();
  1804. }
  1805. String versionValue = contentVersionVO.getVersionValue();
  1806. if(versionValue == null)
  1807. {
  1808. logger.info("Have to read version again...");
  1809. ContentVersionVO cvVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(contentVersionVO.getContentVersionId(), db);
  1810. versionValue = cvVO.getVersionValue();
  1811. }
  1812. doc.add(new Field("contents", new StringReader(versionValue)));
  1813. doc.add(new Field("contents", new StringReader(pageName)));
  1814. // return the document
  1815. return doc;
  1816. }
  1817. public Document getDocumentFromContent(ContentVO contentVO, NotificationMessage message, IndexWriter writer, boolean indexVersions, Database db) throws Exception, InterruptedException
  1818. {
  1819. logger.info("getDocumentFromContent:" + contentVO.getName() + ":" + contentVO.getIsDeleted());
  1820. if(contentVO == null || contentVO.getIsDeleted())
  1821. {
  1822. //NotificationMessage notificationMessage = new NotificationMessage(message.getName(), message.getClassName(), message.getSystemUserName(), NotificationMessage.TRANS_DELETE, message.getObjectId(), message.getObjectName());
  1823. logger.info("Adding a delete directive to the indexer");
  1824. //internalMessageList.add(notificationMessage);
  1825. String uid = "contentId_" + contentVO.getId();
  1826. logger.info("Deleting documents:" + "uid=" + uid);
  1827. logger.info("Before delete:" + writer.numDocs());
  1828. //writer.deleteDocuments(new Term("uid", "" + uid));
  1829. Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
  1830. Query query = new QueryParser(Version.LUCENE_34, "contentId", analyzer).parse("" + contentVO.getId());
  1831. writer.deleteDocuments(query);
  1832. logger.info("Before delete:" + writer.numDocs());
  1833. return null;
  1834. }
  1835. // make a new, empty document
  1836. Document doc = new Document();
  1837. // Add the last modified date of the file a field named "modified".
  1838. // Use a field that is indexed (i.e. searchable), but don't tokenize
  1839. // the field into words.
  1840. doc.add(new NumericField("publishDateTime", Field.Store.YES, true).setLongValue(contentVO.getPublishDateTime().getTime()));
  1841. doc.add(new Field("modified", DateTools.timeToString(new Date().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1842. doc.add(new Field("contentId", "" + contentVO.getContentId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1843. doc.add(new Field("contentTypeDefinitionId", "" + contentVO.getContentTypeDefinitionId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1844. doc.add(new Field("repositoryId", "" + contentVO.getRepositoryId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1845. doc.add(new Field("lastModifier", "" + contentVO.getCreatorName(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1846. doc.add(new Field("isAsset", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1847. doc.add(new Field("path", "" + getContentPath(contentVO.getId(), db), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1848. // Add the uid as a field, so that index can be incrementally
  1849. // maintained.
  1850. // This field is not stored with document, it is indexed, but it is not
  1851. // tokenized prior to indexing.
  1852. doc.add(new Field("uid", "contentId_" + contentVO.getId(), Field.Store.NO, Field.Index.NOT_ANALYZED));
  1853. // Add the tag-stripped contents as a Reader-valued Text field so it
  1854. // will
  1855. // get tokenized and indexed.
  1856. doc.add(new Field("contents", new StringReader(contentVO.getName())));
  1857. // return the document
  1858. return doc;
  1859. }
  1860. public Document getDocumentFromContentVersion(ContentVersionVO contentVersionVO, Database db) throws Exception, InterruptedException
  1861. {
  1862. logger.info("getting document from content version:" + contentVersionVO.getContentName());
  1863. Timer t = new Timer();
  1864. //ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId());
  1865. ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId(), db);
  1866. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVOWithId", (t.getElapsedTimeNanos() / 1000));
  1867. if(contentVO.getIsDeleted())
  1868. return null;
  1869. // make a new, empty document
  1870. Document doc = new Document();
  1871. // Add the last modified date of the file a field named "modified".
  1872. // Use a field that is indexed (i.e. searchable), but don't tokenize
  1873. // the field into words.
  1874. logger.info("contentVersionVO:" + contentVersionVO.getContentName());
  1875. doc.add(new NumericField("publishDateTime", Field.Store.YES, true).setLongValue(contentVO.getPublishDateTime().getTime()));
  1876. doc.add(new NumericField("modificationDateTime", Field.Store.YES, true).setLongValue(contentVersionVO.getModifiedDateTime().getTime()));
  1877. doc.add(new Field("modified", DateTools.timeToString(contentVersionVO.getModifiedDateTime().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1878. doc.add(new Field("contentVersionId", "" + contentVersionVO.getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1879. doc.add(new Field("contentId", "" + contentVersionVO.getContentId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1880. doc.add(new Field("contentTypeDefinitionId", "" + contentVO.getContentTypeDefinitionId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1881. doc.add(new Field("languageId", "" + contentVersionVO.getLanguageId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1882. doc.add(new Field("repositoryId", "" + contentVO.getRepositoryId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1883. doc.add(new Field("lastModifier", "" + contentVersionVO.getVersionModifier(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1884. doc.add(new Field("stateId", "" + contentVersionVO.getStateId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1885. doc.add(new Field("isAsset", "false", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1886. doc.add(new Field("path", "" + getContentPath(contentVO.getId(), db), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1887. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Indexing normalFields", (t.getElapsedTimeNanos() / 1000));
  1888. //Testing adding the categories for this version
  1889. try
  1890. {
  1891. if(contentVO.getContentTypeDefinitionId() != null)
  1892. {
  1893. ContentTypeDefinitionVO ctdVO = null;
  1894. try
  1895. {
  1896. ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId(), db);
  1897. }
  1898. catch (SystemException sex)
  1899. {
  1900. logger.warn("Failed to get the content type definition for content with Id: " + contentVO.getContentId() + ". The categories for the content will not be indexed. Message: " + sex.getMessage());
  1901. logger.info("Failed to get the content type definition for content with Id: " + contentVO.getContentId(), sex);
  1902. }
  1903. if (ctdVO != null)
  1904. {
  1905. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentTypeDefinitionVOWithId", (t.getElapsedTimeNanos() / 1000));
  1906. List<CategoryAttribute> categoryKeys = ContentTypeDefinitionController.getController().getDefinedCategoryKeys(ctdVO, true);
  1907. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getDefinedCategoryKeys", (t.getElapsedTimeNanos() / 1000));
  1908. for(CategoryAttribute categoryKey : categoryKeys)
  1909. {
  1910. logger.info("categoryKey:" + categoryKey.getValue() + " for content:" + contentVO.getName());
  1911. //List<ContentCategoryVO> contentCategoryVOList = ContentCategoryController.getController().findByContentVersionAttribute(categoryKey.getValue(), contentVersionVO.getId());
  1912. List<ContentCategory> contentCategoryVOList = ContentCategoryController.getController().findByContentVersionAttribute(categoryKey.getValue(), contentVersionVO.getId(), db, true);
  1913. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Indexing categories", (t.getElapsedTimeNanos() / 1000));
  1914. logger.info("contentCategoryVOList:" + contentCategoryVOList.size());
  1915. for(ContentCategory contentCategory : contentCategoryVOList)
  1916. {
  1917. doc.add(new Field("categories", "" + contentCategory.getAttributeName().replaceAll(" ", "_").toLowerCase() + "eq" + contentCategory.getCategory().getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1918. doc.add(new Field("categories", "" + contentCategory.getAttributeName() + "=" + contentCategory.getCategory().getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1919. doc.add(new Field("" + contentCategory.getAttributeName() + "_categoryId", "" + contentCategory.getCategory().getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. catch (Exception e)
  1926. {
  1927. logger.error("Problem indexing categories for contentVO: " + contentVO.getName() + "(" + contentVO.getId() + "): " + e.getMessage(), e);
  1928. }
  1929. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Indexing categories", (t.getElapsedTimeNanos() / 1000));
  1930. //End test
  1931. // Add the uid as a field, so that index can be incrementally
  1932. // maintained.
  1933. // This field is not stored with document, it is indexed, but it is not
  1934. // tokenized prior to indexing.
  1935. doc.add(new Field("uid", "contentVersionId_" + contentVersionVO.getId(), Field.Store.NO, Field.Index.NOT_ANALYZED));
  1936. // Add the tag-stripped contents as a Reader-valued Text field so it
  1937. // will
  1938. // get tokenized and indexed.
  1939. doc.add(new Field("contents", new StringReader(contentVersionVO.getVersionValue())));
  1940. doc.add(new Field("contents", new StringReader(contentVersionVO.getContentName())));
  1941. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Indexing end fields", (t.getElapsedTimeNanos() / 1000));
  1942. // return the document
  1943. return doc;
  1944. }
  1945. public Document getDocumentFromDigitalAsset(DigitalAssetVO digitalAssetVO, ContentVersionVO contentVersionVO, Database db) throws Exception, InterruptedException
  1946. {
  1947. ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId(), db);
  1948. if(contentVO == null || contentVO.getIsDeleted())
  1949. return null;
  1950. // make a new, empty document
  1951. Document doc = new Document();
  1952. // Add the last modified date of the file a field named "modified".
  1953. // Use a field that is indexed (i.e. searchable), but don't tokenize
  1954. // the field into words.
  1955. //doc.add(new Field("modified", DateTools.timeToString(contentVersionVO.getModifiedDateTime().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1956. doc.add(new NumericField("modificationDateTime", Field.Store.YES, true).setLongValue(contentVersionVO.getModifiedDateTime().getTime()));
  1957. doc.add(new Field("digitalAssetId", "" + digitalAssetVO.getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1958. doc.add(new Field("contentVersionId", "" + contentVersionVO.getId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1959. doc.add(new Field("contentId", "" + contentVersionVO.getContentId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1960. doc.add(new Field("contentTypeDefinitionId", "" + contentVO.getContentTypeDefinitionId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1961. doc.add(new Field("languageId", "" + contentVersionVO.getLanguageId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1962. doc.add(new Field("repositoryId", "" + contentVO.getRepositoryId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1963. doc.add(new Field("lastModifier", "" + contentVersionVO.getVersionModifier(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1964. doc.add(new Field("stateId", "" + contentVersionVO.getStateId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1965. doc.add(new Field("isAsset", "true", Field.Store.YES, Field.Index.NOT_ANALYZED));
  1966. doc.add(new Field("path", "" + getContentPath(contentVO.getId(), db), Field.Store.YES, Field.Index.NOT_ANALYZED));
  1967. // Add the uid as a field, so that index can be incrementally
  1968. // maintained.
  1969. // This field is not stored with document, it is indexed, but it is not
  1970. // tokenized prior to indexing.
  1971. doc.add(new Field("uid", "digitalAssetId_" + digitalAssetVO.getId(), Field.Store.NO, Field.Index.NOT_ANALYZED));
  1972. //doc.add(new Field("uid", "" + contentVersionVO.getId(), Field.Store.NO, Field.Index.NOT_ANALYZED));
  1973. // Add the tag-stripped contents as a Reader-valued Text field so it
  1974. // will
  1975. // get tokenized and indexed.
  1976. doc.add(new Field("contents", new StringReader(digitalAssetVO.getAssetKey() + " " + digitalAssetVO.getAssetFileName() + " " + digitalAssetVO.getAssetContentType())));
  1977. if (CmsPropertyHandler.getIndexDigitalAssetContent())
  1978. {
  1979. //String url = DigitalAssetController.getController().getDigitalAssetUrl(digitalAssetVO, db);
  1980. //if(logger.isInfoEnabled())
  1981. // logger.info("url if we should index file:" + url);
  1982. try
  1983. {
  1984. String filePath = DigitalAssetController.getController().getDigitalAssetFilePath(digitalAssetVO, db);
  1985. if(logger.isInfoEnabled())
  1986. logger.info("filePath if we should index file:" + filePath);
  1987. File file = new File(filePath);
  1988. String text = extractTextToIndex(digitalAssetVO, file);
  1989. doc.add(new Field("contents", new StringReader(text)));
  1990. }
  1991. catch(Exception e)
  1992. {
  1993. logger.warn("Problem getting asset:" + digitalAssetVO.getId() + ": " + e.getMessage());
  1994. }
  1995. }
  1996. return doc;
  1997. }
  1998. private String extractTextToIndex(DigitalAssetVO digitalAssetVO, File file)
  1999. {
  2000. String text = "";
  2001. if(logger.isInfoEnabled())
  2002. logger.info("Asset content type:" + digitalAssetVO.getAssetContentType());
  2003. if(digitalAssetVO.getAssetContentType().equalsIgnoreCase("application/pdf"))
  2004. {
  2005. try
  2006. {
  2007. Writer output = null;
  2008. PDDocument document = null;
  2009. try
  2010. {
  2011. document = PDDocument.load(file);
  2012. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  2013. if(!document.isEncrypted())
  2014. {
  2015. output = new OutputStreamWriter(baos, "UTF-8");
  2016. PDFTextStripper stripper = new PDFTextStripper();
  2017. //stripper.setSortByPosition( sort );
  2018. //stripper.setStartPage( startPage );
  2019. //stripper.setEndPage( endPage );
  2020. stripper.writeText( document, output );
  2021. text = baos.toString("UTF-8");
  2022. if(logger.isInfoEnabled())
  2023. logger.info("PDF Document has " + text.length() + " chars\n\n" + text);
  2024. }
  2025. }
  2026. catch (Exception e)
  2027. {
  2028. logger.warn("Error indexing file: " + file + "\nMessage: " + e.getMessage());
  2029. }
  2030. finally
  2031. {
  2032. if( output != null )
  2033. {
  2034. output.close();
  2035. }
  2036. if( document != null )
  2037. {
  2038. document.close();
  2039. }
  2040. }
  2041. }
  2042. catch (Exception e)
  2043. {
  2044. logger.warn("Error indexing:" + e.getMessage());
  2045. }
  2046. }
  2047. else if(digitalAssetVO.getAssetContentType().equalsIgnoreCase("application/msword"))
  2048. {
  2049. try
  2050. {
  2051. InputStream is = new FileInputStream(file);
  2052. POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
  2053. is.close();
  2054. // Create a document for this file
  2055. HWPFDocument doc = new HWPFDocument(fs);
  2056. // Create a WordExtractor to read the text of the word document
  2057. WordExtractor we = new WordExtractor(doc);
  2058. // Extract all paragraphs in the document as strings
  2059. text = we.getText();
  2060. // Output the document
  2061. if(logger.isInfoEnabled())
  2062. logger.info("Word Document has " + text.length() + " chars\n\n" + text);
  2063. }
  2064. catch (Exception e)
  2065. {
  2066. logger.warn("Error indexing file: " + file + "\nMessage: " + e.getMessage());
  2067. }
  2068. }
  2069. return text;
  2070. }
  2071. public void deleteVersionFromIndex(String contentVersionId)
  2072. {
  2073. try
  2074. {
  2075. IndexWriter writer = getIndexWriter();
  2076. logger.info("Deleting contentVersionId:" + contentVersionId);
  2077. writer.deleteDocuments(new Term("contentVersionId", "" + contentVersionId));
  2078. writer.commit();
  2079. }
  2080. catch (Exception e)
  2081. {
  2082. logger.error("Error deleteVersionFromIndex:" + e.getMessage(), e);
  2083. }
  2084. }
  2085. public String getContentPath(Integer contentId, Database db) throws Exception
  2086. {
  2087. StringBuffer sb = new StringBuffer();
  2088. ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId, db);
  2089. sb.insert(0, contentVO.getName());
  2090. while(contentVO.getParentContentId() != null)
  2091. {
  2092. contentVO = ContentController.getContentController().getContentVOWithId(contentVO.getParentContentId(), db);
  2093. sb.insert(0, contentVO.getName() + "/");
  2094. }
  2095. sb.insert(0, "/");
  2096. return sb.toString();
  2097. }
  2098. public String getSiteNodePath(Integer siteNodeId, Database db) throws Exception
  2099. {
  2100. StringBuffer sb = new StringBuffer();
  2101. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db);
  2102. while(siteNodeVO != null)
  2103. {
  2104. sb.insert(0, "/" + siteNodeVO.getName());
  2105. if(siteNodeVO.getParentSiteNodeId() != null)
  2106. siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeVO.getParentSiteNodeId(), db);
  2107. else
  2108. siteNodeVO = null;
  2109. }
  2110. return sb.toString();
  2111. }
  2112. /**
  2113. * This is a method that never should be called.
  2114. */
  2115. public BaseEntityVO getNewVO()
  2116. {
  2117. return null;
  2118. }
  2119. public void setContextParameters(Map map)
  2120. {
  2121. // TODO Auto-generated method stub
  2122. }
  2123. }