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.Hits;
020    import com.liferay.portal.kernel.search.IndexSearcher;
021    import com.liferay.portal.kernel.search.Query;
022    import com.liferay.portal.kernel.search.SearchException;
023    import com.liferay.portal.kernel.search.Sort;
024    import com.liferay.portal.kernel.search.messaging.SearchRequest;
025    
026    /**
027     * @author Bruno Farache
028     */
029    public class IndexSearcherImpl implements IndexSearcher {
030    
031            public Hits search(
032                            long companyId, Query query, Sort[] sorts, int start, int end)
033                    throws SearchException {
034    
035                    try {
036                            SearchRequest searchRequest = SearchRequest.search(
037                                    companyId, query, sorts, start, end);
038    
039                            Hits hits = (Hits)MessageBusUtil.sendSynchronousMessage(
040                                    DestinationNames.SEARCH_READER, searchRequest,
041                                    DestinationNames.SEARCH_READER_RESPONSE);
042    
043                            return hits;
044                    }
045                    catch (Exception e) {
046                            throw new SearchException(e);
047                    }
048            }
049    
050    }