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     * @author Andrea Di Giorgi
040     */
041    public interface LuceneHelper {
042    
043            public void addDocument(long companyId, Document document)
044                    throws IOException;
045    
046            public void addExactTerm(
047                    BooleanQuery booleanQuery, String field, String value);
048    
049            public void addNumericRangeTerm(
050                    BooleanQuery booleanQuery, String field, Integer startValue,
051                    Integer endValue);
052    
053            public void addNumericRangeTerm(
054                    BooleanQuery booleanQuery, String field, Long startValue,
055                    Long endValue);
056    
057            /**
058             * @deprecated As of 6.2.0, replaced by {@link
059             *             #addNumericRangeTerm(BooleanQuery, String, Long, Long)}
060             */
061            public void addNumericRangeTerm(
062                    BooleanQuery booleanQuery, String field, String startValue,
063                    String endValue);
064    
065            public void addRangeTerm(
066                    BooleanQuery booleanQuery, String field, String startValue,
067                    String endValue);
068    
069            public void addRequiredTerm(
070                    BooleanQuery booleanQuery, String field, String value, boolean like);
071    
072            public void addRequiredTerm(
073                    BooleanQuery booleanQuery, String field, String[] values, boolean like);
074    
075            public void addTerm(
076                    BooleanQuery booleanQuery, String field, String value, boolean like);
077    
078            public void addTerm(
079                    BooleanQuery booleanQuery, String field, String value, boolean like,
080                    BooleanClauseOccur booleanClauseOccur);
081    
082            public void addTerm(
083                    BooleanQuery booleanQuery, String field, String[] values, boolean like);
084    
085            public void cleanUp(IndexSearcher indexSearcher);
086    
087            public int countScoredFieldNames(Query query, String[] fieldNames);
088    
089            public void delete(long companyId);
090    
091            public void deleteDocuments(long companyId, Term term) throws IOException;
092    
093            public void dumpIndex(long companyId, OutputStream outputStream)
094                    throws IOException;
095    
096            public Analyzer getAnalyzer();
097    
098            public IndexAccessor getIndexAccessor(long companyId);
099    
100            public long getLastGeneration(long companyId);
101    
102            public InputStream getLoadIndexesInputStreamFromCluster(
103                            long companyId, Address bootupAddress)
104                    throws SystemException;
105    
106            public Set<String> getQueryTerms(Query query);
107    
108            public IndexSearcher getSearcher(long companyId, boolean readOnly)
109                    throws IOException;
110    
111            public String getSnippet(
112                            Query query, String field, String s, int maxNumFragments,
113                            int fragmentLength, String fragmentSuffix, Formatter formatter)
114                    throws IOException;
115    
116            public Version getVersion();
117    
118            public boolean isLoadIndexFromClusterEnabled();
119    
120            public void loadIndex(long companyId, InputStream inputStream)
121                    throws IOException;
122    
123            public void loadIndexesFromCluster(long companyId) throws SystemException;
124    
125            public void shutdown();
126    
127            public void shutdown(long companyId);
128    
129            public void startup(long companyId);
130    
131            public void updateDocument(long companyId, Term term, Document document)
132                    throws IOException;
133    
134    }