List of usage examples for org.apache.lucene.index IndexWriter addDocument
public long addDocument(Iterable<? extends IndexableField> doc) throws IOException
From source file:com.aurel.track.lucene.index.associatedFields.AttachmentIndexer.java
License:Open Source License
/** * Adds an attachment to the attachment index * Used by attaching a new file to the workItem * @param attachFile/*from w w w. j a va2 s .c om*/ */ @Override public void addToIndex(Object object, boolean add) { if (!LuceneUtil.isUseLucene() || !LuceneUtil.isIndexAttachments() || object == null) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false"); return; } IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID()); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding an attachment"); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Save a new " + add + " attachment into attachmentIndex"); } TAttachmentBean attachmentBean = (TAttachmentBean) object; if (!add) { Integer objectID = attachmentBean.getObjectID(); if (objectID != null) { Term keyTerm = new Term(getObjectIDFieldName(), objectID.toString()); try { indexWriter.deleteDocuments(keyTerm); indexWriter.commit(); } catch (IOException e) { LOGGER.error("Removing the attachment " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } try { Document doc = createDocument(attachmentBean); if (doc != null) { indexWriter.addDocument(doc); } } catch (IOException e) { LOGGER.error("Adding an attachment to the index failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing the attachment failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }
From source file:com.aurel.track.lucene.index.associatedFields.BudgetPlanIndexer.java
License:Open Source License
/** * Adds an attachment to the attachment index * Used by attaching a new file to the workItem * @param attachFile//from w ww .j a va 2s .c o m */ @Override public void addToIndex(Object object, boolean add) { if (!LuceneUtil.isUseLucene()) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false"); return; } IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID()); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a budget/plan"); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Save a new " + add + " " + getLuceneFieldName()); } TBudgetBean budgetBean = (TBudgetBean) object; if (!add) { Integer objectID = budgetBean.getObjectID(); if (objectID != null) { Term keyTerm = new Term(getObjectIDFieldName(), objectID.toString()); try { indexWriter.deleteDocuments(keyTerm); indexWriter.commit(); } catch (IOException e) { LOGGER.error("Removing the entity " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } try { Document doc = createDocument(budgetBean); if (doc != null) { indexWriter.addDocument(doc); } } catch (IOException e) { LOGGER.error("Adding a budget/plan to the index failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing the budget/plan failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }
From source file:com.aurel.track.lucene.index.associatedFields.ExpenseIndexer.java
License:Open Source License
/** * Adds an attachment to the attachment index * Used by attaching a new file to the workItem * @param attachFile//www . j av a 2s.co m */ @Override public void addToIndex(Object object, boolean add) { if (!LuceneUtil.isUseLucene()) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false"); return; } IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID()); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding an expense"); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Save a new " + add + " " + getLuceneFieldName()); } TCostBean costBean = (TCostBean) object; if (!add) { Integer objectID = costBean.getObjectID(); if (objectID != null) { Term keyTerm = new Term(getObjectIDFieldName(), objectID.toString()); try { indexWriter.deleteDocuments(keyTerm); indexWriter.commit(); } catch (IOException e) { LOGGER.error("Removing the entity " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } try { Document doc = createDocument(costBean); if (doc != null) { indexWriter.addDocument(doc); } } catch (IOException e) { LOGGER.error("Adding an expense to the index failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing the expense failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }
From source file:com.aurel.track.lucene.index.associatedFields.LinkIndexer.java
License:Open Source License
/** * Adds an attachment to the attachment index * Used by attaching a new file to the workItem * @param attachFile// w ww . ja v a2 s . c om */ @Override public void addToIndex(Object object, boolean add) { if (!LuceneUtil.isUseLucene()) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false"); return; } IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID()); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a link"); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Save a new " + add + " " + getLuceneFieldName()); } TWorkItemLinkBean workItemLinkBean = (TWorkItemLinkBean) object; if (!add) { Integer objectID = workItemLinkBean.getObjectID(); if (objectID != null) { Term keyTerm = new Term(getObjectIDFieldName(), objectID.toString()); try { indexWriter.deleteDocuments(keyTerm); indexWriter.commit(); } catch (IOException e) { LOGGER.error("Removing the entity " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } try { Document doc = createDocument(workItemLinkBean); if (doc != null) { indexWriter.addDocument(doc); } } catch (IOException e) { LOGGER.error("Adding an link to the index failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing the link failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }
From source file:com.aurel.track.lucene.index.listFields.AbstractListFieldIndexer.java
License:Open Source License
/** * Adds the list of ILabelBeans to the non-localized lookup index * @param indexWriter//w w w . j a va2s . c o m * @param fieldID */ protected void addToListFieldToIndex(IndexWriter indexWriter, IFieldTypeRT fieldTypeRT, Integer fieldID) { if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a list options for fieldID " + fieldID); return; } LOGGER.debug("Reindexing " + getListFieldType() + " list field " + fieldID + " started..."); List allExternalLookups = loadAllIndexable(fieldTypeRT, fieldID); if (allExternalLookups != null && !allExternalLookups.isEmpty()) { for (Object externalObject : allExternalLookups) { Document document = createDocument(externalObject, fieldTypeRT, fieldID); if (document != null) { try { indexWriter.addDocument(document); } catch (IOException e) { LOGGER.error("Adding a list option document for field " + fieldID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } LOGGER.debug("Reindexing " + allExternalLookups.size() + " options for " + getListFieldType() + " list field " + fieldID + " completed"); } }
From source file:com.aurel.track.lucene.index.listFields.AbstractListFieldIndexer.java
License:Open Source License
/** * Adds the list of ILabelBeans to the non-localized lookup index * @param indexWriter//from ww w.j av a2 s . c om * @param fieldID */ protected void addCustomListToIndex(IndexWriter indexWriter, TListBean listBean) { Integer listID = listBean.getObjectID(); String listLabel = listBean.getLabel(); if (indexWriter == null) { LOGGER.error( "IndexWriter null by adding a list options for custom list " + listLabel + " ID " + listID); return; } StringBuilder stringBuilder = new StringBuilder(); if (listBean.getProject() != null) { stringBuilder.append(" project " + listBean.getProject()); } if (listBean.getParentList() != null) { stringBuilder.append(" parent list " + listBean.getParentList()); } LOGGER.debug("Reindexing " + getListFieldType() + " custom list " + listLabel + " with ID " + listID + stringBuilder.toString() + " started..."); List allExternalLookups = OptionBL.loadByListID(listID); if (allExternalLookups != null && !allExternalLookups.isEmpty()) { for (Object externalObject : allExternalLookups) { Document document = createDocument(externalObject, new CustomSelectSimpleRT(), null); if (document != null) { try { indexWriter.addDocument(document); } catch (IOException e) { LOGGER.error("Adding a list option document for custom list " + listLabel + " with ID " + listID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } LOGGER.debug("Reindexing " + allExternalLookups.size() + " options for " + getListFieldType() + " custom list " + listLabel + " ID " + listID + " completed"); } }
From source file:com.aurel.track.lucene.index.listFields.InternalListIndexer.java
License:Open Source License
/** * //w w w. j a v a2s.c o m * Adds a ILabelBeans to the non-localized lookup index * @param labelBean * @param type */ public synchronized void addLabelBean(ILabelBean labelBean, int type, boolean add) { if (!LuceneUtil.isUseLucene()) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false"); return; } if (labelBean == null || labelBean.getObjectID() == null) { LOGGER.warn("Bean or value null by adding a internal list option of type " + type); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Save a new " + add + " internal list option of type " + type); } Document document = createDocument(labelBean, type); if (document != null) { IndexWriter indexWriter = LuceneIndexer.getIndexWriter(getIndexWriterID()); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a non-localized list option of type " + type); return; } try { indexWriter.addDocument(document); } catch (IOException e) { LOGGER.error("Adding the document for list option with key " + labelBean.getObjectID() + " and type " + type + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing list option with key " + labelBean.getObjectID() + " and type " + type + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } }
From source file:com.aurel.track.lucene.index.LuceneIndexer.java
License:Open Source License
/** * Adds a list of TWorkItems to the workItem index * Used by recreating the index/*from w w w . ja v a 2 s. com*/ * @param indexWriter * @param workItemBeans the beans are considered to be fully prepared: * i.e. history beans and custom attributes are set */ private static void addToWorkItemIndex(IndexWriter indexWriter, List<TWorkItemBean> workItemBeans) { //use lucene uncheched in site config if (!LuceneUtil.isUseLucene()) { return; } if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a list if workItems"); return; } prepareWorkItemBeans(workItemBeans); if (workItemBeans != null && !workItemBeans.isEmpty()) { for (TWorkItemBean workItemBean : workItemBeans) { //use lucene uncheched in site config if (!LuceneUtil.isUseLucene()) { return; } //addToWorkItemIndex(TWorkItemBean workItemBean) could be used, //but we do not use it because of the superfluous flushes //we make flush and optimize only after each workItem is added Document document = createWorkItemDocument(workItemBean); try { if (document != null) { indexWriter.addDocument(document); } } catch (IOException e) { LOGGER.error("Adding a workItem document for workItemBean " + workItemBean.getObjectID() + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error( "Flushing the IndexWriter after adding all workItemBeanss failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } }
From source file:com.aurel.track.lucene.index.LuceneIndexer.java
License:Open Source License
/** * Adds a list of TWorkItems to the workItem index * Used by recreating the index/*from w w w.ja v a 2 s . c o m*/ * @param workItemBeans * @param fieldID the beans are considered to be fully prepared: * i.e. history beans and custom attributes are set */ public static synchronized void addToWorkItemIndex(List<TWorkItemBean> workItemBeans, Integer fieldID) { //use lucene unchecked in site config if (!LuceneUtil.isUseLucene()) { return; } if (workItemBeans == null) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false by adding workItemBeans " + workItemBeans.size() + " by field " + fieldID); return; } prepareWorkItemBeans(workItemBeans); if (workItemBeans != null && !workItemBeans.isEmpty()) { IndexWriter indexWriter = getWorkItemIndexWriter(); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a list if workItems"); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Add " + workItemBeans.size() + " previously deleted workItem documents back to workItemIndex after changing a dependency for field " + fieldID); } for (TWorkItemBean workItemBean : workItemBeans) { //use lucene uncheched in site config if (!LuceneUtil.isUseLucene()) { return; } //addToWorkItemIndex(TWorkItemBean workItemBean) could be used, //but we do not use it because of the superfluous flushes //we make flush and optimize only after each workItem is added Document document = createWorkItemDocument(workItemBean); try { if (document != null) { indexWriter.addDocument(document); } } catch (IOException e) { LOGGER.error("Adding a workItem document for workItemBean " + workItemBean.getObjectID() + " failed with IOException" + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing the workItemBeans failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } }
From source file:com.aurel.track.lucene.index.LuceneIndexer.java
License:Open Source License
/** * Adds a TWorkItem to the workitem index * Used by creating a new and by updating (delete old and create new) of an existing workItem * Although workItemBean contains no history bean it is not needed * because by creating only an "emtpy" state change history is created. * However it contains the custom attribute values. * @param workItemBean// w w w. j a v a2s .c o m */ public static synchronized void addToWorkItemIndex(TWorkItemBean workItemBean, boolean deleteExisting) { if (!LuceneUtil.isUseLucene()) { return; } if (!ClusterBL.indexInstantly()) { LOGGER.debug("Index instantly is false"); return; } if (workItemBean == null || workItemBean.getObjectID() == null) { LOGGER.error("TWorkItemBean or ObjectID null by adding/updating a workitem"); return; } IndexWriter indexWriter = getWorkItemIndexWriter(); if (indexWriter == null) { LOGGER.error("IndexWriter null by adding a workitem"); return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Save a new " + !deleteExisting + " workItem into workItemIndex"); } if (deleteExisting) { String workItemID = workItemBean.getObjectID().toString(); Term term = new Term(LuceneUtil.getFieldName(SystemFields.ISSUENO), workItemID); try { indexWriter.deleteDocuments(term); indexWriter.commit(); } catch (IOException e) { LOGGER.error( "Removing a workItembean " + workItemID + " from the index failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } List<Integer> workItemIDsList = new ArrayList<Integer>(); workItemIDsList.add(workItemBean.getObjectID()); Map<Integer, StringBuffer> workItemsCommentsMap = HistoryLoaderBL.getByWorkItemsLongTextField( workItemIDsList, SystemFields.INTEGER_COMMENT, HistoryLoaderBL.LONG_TEXT_TYPE.ISPLAIN); String actualComment = workItemBean.getComment(); String actualCommentPlain = ""; try { actualCommentPlain = Html2Text.getNewInstance().convert(actualComment); } catch (Exception e) { LOGGER.warn("Transforming the actual comment to plain text failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); actualCommentPlain = workItemBean.getComment(); } workItemBean .setComment(getComments(workItemsCommentsMap.get(workItemBean.getObjectID()), actualCommentPlain)); Document doc = createWorkItemDocument(workItemBean); //set the original comment back because the workItem will be used by other parts (e-mail notification, etc.) workItemBean.setComment(actualComment); if (doc != null) { try { indexWriter.addDocument(doc); } catch (IOException e) { LOGGER.error("Adding a workItemBean " + workItemBean.getObjectID() + " to the index failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } try { indexWriter.commit(); } catch (IOException e) { LOGGER.error("Flushing the workItemBean failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }