List of usage examples for com.liferay.portal.kernel.search IndexWriterHelperUtil deleteDocuments
public static void deleteDocuments(String searchEngineId, long companyId, Collection<String> uids, boolean commitImmediately) throws SearchException
From source file:com.liferay.mail.util.AccountIndexer.java
License:Open Source License
@Override protected void doDelete(Account account) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(account.getCompanyId()); searchContext.setEnd(QueryUtil.ALL_POS); searchContext.setSearchEngineId(getSearchEngineId()); searchContext.setSorts(SortFactoryUtil.getDefaultSorts()); searchContext.setStart(QueryUtil.ALL_POS); BooleanQuery booleanQuery = new BooleanQueryImpl(); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME); booleanQuery.addRequiredTerm("accountId", account.getAccountId()); Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery); List<String> uids = new ArrayList<>(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document document = hits.doc(i); uids.add(document.get(Field.UID)); }//ww w. j ava2s . co m IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids, isCommitImmediately()); }
From source file:com.liferay.mail.util.FolderIndexer.java
License:Open Source License
@Override protected void doDelete(Folder folder) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(folder.getCompanyId()); searchContext.setEnd(QueryUtil.ALL_POS); searchContext.setSearchEngineId(getSearchEngineId()); searchContext.setSorts(SortFactoryUtil.getDefaultSorts()); searchContext.setStart(QueryUtil.ALL_POS); BooleanQuery booleanQuery = new BooleanQueryImpl(); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME); booleanQuery.addRequiredTerm("folderId", folder.getFolderId()); Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery); List<String> uids = new ArrayList<>(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document document = hits.doc(i); uids.add(document.get(Field.UID)); }//from ww w . j a v a2s. c o m IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids, isCommitImmediately()); }