001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.search.dummy;
016    
017    import com.liferay.portal.kernel.search.Document;
018    import com.liferay.portal.kernel.search.Hits;
019    import com.liferay.portal.kernel.search.HitsImpl;
020    import com.liferay.portal.kernel.search.IndexSearcher;
021    import com.liferay.portal.kernel.search.Query;
022    import com.liferay.portal.kernel.search.SearchContext;
023    import com.liferay.portal.kernel.search.Sort;
024    import com.liferay.portal.kernel.search.generic.StringQuery;
025    import com.liferay.portal.kernel.search.suggest.Suggester;
026    import com.liferay.portal.kernel.search.suggest.SuggesterResults;
027    import com.liferay.portal.kernel.util.StringPool;
028    
029    import java.util.Collections;
030    import java.util.List;
031    import java.util.Map;
032    
033    /**
034     * @author Marcellus Tavares
035     * @author Carlos Sierra Andr??s
036     */
037    public class DummyIndexSearcher implements IndexSearcher {
038    
039            @Override
040            public String getQueryString(SearchContext searchContext, Query query) {
041                    return StringPool.BLANK;
042            }
043    
044            @Override
045            public Hits search(SearchContext searchContext, Query query) {
046                    return _getHits();
047            }
048    
049            /**
050             * @deprecated As of 7.0.0, replaced by {@link #search(SearchContext,
051             *             Query)}
052             */
053            @Deprecated
054            @Override
055            public Hits search(
056                    String searchEngineId, long companyId, Query query, Sort[] sort,
057                    int start, int end) {
058    
059                    return _getHits();
060            }
061    
062            @Override
063            public long searchCount(SearchContext searchContext, Query query) {
064                    return 0;
065            }
066    
067            @Override
068            public String spellCheckKeywords(SearchContext searchContext) {
069                    return StringPool.BLANK;
070            }
071    
072            @Override
073            public Map<String, List<String>> spellCheckKeywords(
074                    SearchContext searchContext, int max) {
075    
076                    return Collections.emptyMap();
077            }
078    
079            @Override
080            public SuggesterResults suggest(
081                    SearchContext searchContext, Suggester suggester) {
082    
083                    return new SuggesterResults();
084            }
085    
086            @Override
087            public String[] suggestKeywordQueries(
088                    SearchContext searchContext, int max) {
089    
090                    return new String[0];
091            }
092    
093            private Hits _getHits() {
094                    Hits hits = new HitsImpl();
095    
096                    hits.setCollatedSpellCheckResult(StringPool.BLANK);
097                    hits.setDocs(new Document[0]);
098                    hits.setLength(0);
099                    hits.setQuery(new StringQuery(StringPool.BLANK));
100                    hits.setQuerySuggestions(new String[0]);
101                    hits.setQueryTerms(new String[0]);
102                    hits.setLength(0);
103                    hits.setScores(new float[0]);
104                    hits.setSearchTime(0);
105                    hits.setSnippets(new String[0]);
106                    hits.setSpellCheckResults(_spellCheckResults);
107                    hits.setStart(0);
108    
109                    return hits;
110            }
111    
112            private static final Map<String, List<String>> _spellCheckResults =
113                    Collections.emptyMap();
114    
115    }