001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.search;
016    
017    import com.liferay.portal.kernel.messaging.DestinationNames;
018    import com.liferay.portal.kernel.messaging.MessageBusUtil;
019    import com.liferay.portal.kernel.search.Document;
020    import com.liferay.portal.kernel.search.IndexWriter;
021    import com.liferay.portal.kernel.search.messaging.SearchRequest;
022    
023    import java.util.Collection;
024    
025    /**
026     * @author Bruno Farache
027     */
028    public class IndexWriterImpl implements IndexWriter {
029    
030            public void addDocument(long companyId, Document document) {
031                    SearchRequest searchRequest = SearchRequest.addDocument(
032                            companyId, document);
033    
034                    MessageBusUtil.sendMessage(
035                            DestinationNames.SEARCH_WRITER, searchRequest);
036            }
037    
038            public void addDocuments(long companyId, Collection<Document> documents) {
039                    if (documents.isEmpty()) {
040                            return;
041                    }
042    
043                    SearchRequest searchRequest = SearchRequest.addDocuments(
044                            companyId, documents);
045    
046                    MessageBusUtil.sendMessage(
047                            DestinationNames.SEARCH_WRITER, searchRequest);
048            }
049    
050            public void deleteDocument(long companyId, String uid) {
051                    SearchRequest searchRequest = SearchRequest.deleteDocument(
052                            companyId, uid);
053    
054                    MessageBusUtil.sendMessage(
055                            DestinationNames.SEARCH_WRITER, searchRequest);
056            }
057    
058            public void deleteDocuments(long companyId, Collection<String> uids) {
059                    if (uids.isEmpty()) {
060                            return;
061                    }
062    
063                    SearchRequest searchRequest = SearchRequest.deleteDocuments(
064                            companyId, uids);
065    
066                    MessageBusUtil.sendMessage(
067                            DestinationNames.SEARCH_WRITER, searchRequest);
068            }
069    
070            public void deletePortletDocuments(long companyId, String portletId) {
071                    SearchRequest searchRequest = SearchRequest.deletePortletDocuments(
072                            companyId, portletId);
073    
074                    MessageBusUtil.sendMessage(
075                            DestinationNames.SEARCH_WRITER, searchRequest);
076            }
077    
078            public void updateDocument(long companyId, Document document) {
079                    SearchRequest searchRequest = SearchRequest.updateDocument(
080                            companyId, document);
081    
082                    MessageBusUtil.sendMessage(
083                            DestinationNames.SEARCH_WRITER, searchRequest);
084            }
085    
086            public void updateDocuments(
087                    long companyId, Collection<Document> documents) {
088    
089                    if (documents.isEmpty()) {
090                            return;
091                    }
092    
093                    SearchRequest searchRequest = SearchRequest.updateDocuments(
094                            companyId, documents);
095    
096                    MessageBusUtil.sendMessage(
097                            DestinationNames.SEARCH_WRITER, searchRequest);
098            }
099    
100    }