001    /**
002     * Copyright (c) 2000-2013 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.search.lucene;
016    
017    import com.liferay.portal.kernel.cluster.Address;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.search.BooleanClauseOccur;
020    
021    import java.io.IOException;
022    import java.io.InputStream;
023    import java.io.OutputStream;
024    
025    import java.util.Set;
026    
027    import org.apache.lucene.analysis.Analyzer;
028    import org.apache.lucene.document.Document;
029    import org.apache.lucene.index.Term;
030    import org.apache.lucene.search.BooleanQuery;
031    import org.apache.lucene.search.IndexSearcher;
032    import org.apache.lucene.search.Query;
033    import org.apache.lucene.search.highlight.Formatter;
034    import org.apache.lucene.util.Version;
035    
036    /**
037     * @author Bruno Farache
038     * @author Shuyang Zhou
039     */
040    public interface LuceneHelper {
041    
042            public void addDocument(long companyId, Document document)
043                    throws IOException;
044    
045            public void addExactTerm(
046                    BooleanQuery booleanQuery, String field, String value);
047    
048            public void addNumericRangeTerm(
049                    BooleanQuery booleanQuery, String field, String startValue,
050                    String endValue);
051    
052            public void addRangeTerm(
053                    BooleanQuery booleanQuery, String field, String startValue,
054                    String endValue);
055    
056            public void addRequiredTerm(
057                    BooleanQuery booleanQuery, String field, String value, boolean like);
058    
059            public void addRequiredTerm(
060                    BooleanQuery booleanQuery, String field, String[] values, boolean like);
061    
062            public void addTerm(
063                    BooleanQuery booleanQuery, String field, String value, boolean like);
064    
065            public void addTerm(
066                    BooleanQuery booleanQuery, String field, String value, boolean like,
067                    BooleanClauseOccur booleanClauseOccur);
068    
069            public void addTerm(
070                    BooleanQuery booleanQuery, String field, String[] values, boolean like);
071    
072            public void cleanUp(IndexSearcher indexSearcher);
073    
074            public int countScoredFieldNames(Query query, String[] fieldNames);
075    
076            public void delete(long companyId);
077    
078            public void deleteDocuments(long companyId, Term term) throws IOException;
079    
080            public void dumpIndex(long companyId, OutputStream outputStream)
081                    throws IOException;
082    
083            public Analyzer getAnalyzer();
084    
085            public IndexAccessor getIndexAccessor(long companyId);
086    
087            public long getLastGeneration(long companyId);
088    
089            public InputStream getLoadIndexesInputStreamFromCluster(
090                            long companyId, Address bootupAddress)
091                    throws SystemException;
092    
093            public Set<String> getQueryTerms(Query query);
094    
095            public IndexSearcher getSearcher(long companyId, boolean readOnly)
096                    throws IOException;
097    
098            public String getSnippet(
099                            Query query, String field, String s, int maxNumFragments,
100                            int fragmentLength, String fragmentSuffix, Formatter formatter)
101                    throws IOException;
102    
103            public Version getVersion();
104    
105            public boolean isLoadIndexFromClusterEnabled();
106    
107            public void loadIndex(long companyId, InputStream inputStream)
108                    throws IOException;
109    
110            public void loadIndexesFromCluster(long companyId) throws SystemException;
111    
112            public void shutdown();
113    
114            public void shutdown(long companyId);
115    
116            public void startup(long companyId);
117    
118            public void updateDocument(long companyId, Term term, Document document)
119                    throws IOException;
120    
121    }