001    /**
002     * Copyright (c) 2000-2012 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 int countScoredFieldNames(Query query, String[] fieldNames);
073    
074            public void delete(long companyId);
075    
076            public void deleteDocuments(long companyId, Term term) throws IOException;
077    
078            public void dumpIndex(long companyId, OutputStream outputStream)
079                    throws IOException;
080    
081            public Analyzer getAnalyzer();
082    
083            public long getLastGeneration(long companyId);
084    
085            public InputStream getLoadIndexesInputStreamFromCluster(
086                            long companyId, Address bootupAddress)
087                    throws SystemException;
088    
089            public Set<String> getQueryTerms(Query query);
090    
091            public IndexSearcher getSearcher(long companyId, boolean readOnly)
092                    throws IOException;
093    
094            public String getSnippet(
095                            Query query, String field, String s, int maxNumFragments,
096                            int fragmentLength, String fragmentSuffix, Formatter formatter)
097                    throws IOException;
098    
099            public Version getVersion();
100    
101            public boolean isLoadIndexFromClusterEnabled();
102    
103            public void loadIndex(long companyId, InputStream inputStream)
104                    throws IOException;
105    
106            public void loadIndexesFromCluster(long companyId) throws SystemException;
107    
108            public void shutdown();
109    
110            public void startup(long companyId);
111    
112            public void updateDocument(long companyId, Term term, Document document)
113                    throws IOException;
114    
115    }