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