From: <ap...@vh...> - 2005-09-21 17:10:56
|
Author: apevec Date: 2005-09-21 19:01:27 +0200 (Wed, 21 Sep 2005) New Revision: 887 Added: trunk/ccm-core/lib/lucene-1.4.3.jar Removed: trunk/ccm-core/lib/lucene-1.2.jar Modified: trunk/ccm-core/etc/java-libs.txt trunk/ccm-core/src/com/arsdigita/search/lucene/Indexer.java trunk/ccm-core/src/com/arsdigita/search/lucene/Initializer.java trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig.java trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig_parameter.properties trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneSearch.java trunk/ccm-core/test/src/com/arsdigita/search/lucene/SearchTest.java Log: SF patch [ 1292835 ] Lucene customized Analyzer Update Lucene to 1.4.3 Modified: trunk/ccm-core/etc/java-libs.txt =================================================================== --- trunk/ccm-core/etc/java-libs.txt 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/etc/java-libs.txt 2005-09-21 17:01:27 UTC (rev 887) @@ -25,8 +25,7 @@ jdxslt.jar 1.5.5 MPL 1.1 http://www.mozilla.org/MPL/ jdom.jar beta 9 http://cvs.jdom.org/cgi-bin/viewcvs.cgi/jdom/LICENSE.txt log4j.jar 1.2 APACHE http://www.apache.org/LICENSE.txt -lucene-1.2.jar 1.2 APACHE http://www.apache.org/LICENSE.txt -postgresql.jar 7.2 BSD http://www.postgresql.org/licence.html +lucene-1.4.3.jar 1.4.3 APACHE http://www.apache.org/LICENSE.txt mail.jar 1.3.1 SUN http://java.sun.com/products/javamail/ saxon.jar 6.5.2 MPL 1.0 http://www.mozilla.org/MPL/ servlet.jar 2.2 APACHE http://www.apache.org/LICENSE.txt Deleted: trunk/ccm-core/lib/lucene-1.2.jar Added: trunk/ccm-core/lib/lucene-1.4.3.jar =================================================================== (Binary files differ) Property changes on: trunk/ccm-core/lib/lucene-1.4.3.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/ccm-core/src/com/arsdigita/search/lucene/Indexer.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/search/lucene/Indexer.java 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/src/com/arsdigita/search/lucene/Indexer.java 2005-09-21 17:01:27 UTC (rev 887) @@ -33,7 +33,7 @@ import org.apache.log4j.Logger; -import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.DateField; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; @@ -149,9 +149,10 @@ } private void update(Document doc) throws IOException { + LuceneConfig conf = LuceneConfig.getConfig(); + Analyzer analyzer = conf.getAnalyzer(); synchronized (LOCK) { - IndexWriter iw = new IndexWriter(m_index, new StandardAnalyzer(), - false); + IndexWriter iw = new IndexWriter(m_index, analyzer, false); try { if (LOG.isDebugEnabled()) { LOG.debug("Indexing document (" + doc.getID() + "): " + Modified: trunk/ccm-core/src/com/arsdigita/search/lucene/Initializer.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/search/lucene/Initializer.java 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/src/com/arsdigita/search/lucene/Initializer.java 2005-09-21 17:01:27 UTC (rev 887) @@ -30,7 +30,7 @@ import java.util.Date; import org.apache.log4j.Logger; -import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; @@ -66,14 +66,16 @@ LuceneConfig conf = LuceneConfig.getConfig(); String location = conf.getIndexLocation(); int interval = conf.getIndexerInterval(); + Analyzer analyzer = conf.getAnalyzer(); LOG.info("Lucene index location: " + location); + LOG.info("Lucene Analyzer = " + analyzer.getClass().getName()); try { if (!IndexReader.indexExists(location)) { File f = new File(location); f.mkdirs(); IndexWriter iw = new IndexWriter - (location, new StandardAnalyzer(), true); + (location, analyzer, true); iw.close(); LOG.info("Lucene created index directory"); } Modified: trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig.java 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig.java 2005-09-21 17:01:27 UTC (rev 887) @@ -23,6 +23,9 @@ import com.arsdigita.util.parameter.IntegerParameter; import com.arsdigita.util.parameter.Parameter; import com.arsdigita.util.parameter.StringParameter; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.log4j.Logger; import java.io.File; @@ -36,6 +39,7 @@ public class LuceneConfig extends AbstractConfig { public final static String versionId = "$Id$ by $Author$, $DateTime: 2004/08/16 18:10:38 $"; + private static final Logger LOG = Logger.getLogger(LuceneConfig.class); private static LuceneConfig s_conf; @@ -48,15 +52,21 @@ return s_conf; } + private Class m_analyzerClass; + private StringParameter m_location = new StringParameter ("waf.lucene.location", Parameter.REQUIRED, new File(CCM.getDataDirectory(), "lucene").getPath()); private IntegerParameter m_interval = new IntegerParameter ("waf.lucene.interval", Parameter.REQUIRED, new Integer(2*60)); + private StringParameter m_analyzer = new StringParameter + ("waf.lucene.analyzer", Parameter.REQUIRED, + "org.apache.lucene.analysis.standard.StandardAnalyzer"); public LuceneConfig() { register(m_location); register(m_interval); + register(m_analyzer); loadInfo(); } @@ -67,4 +77,24 @@ public int getIndexerInterval() { return ((Integer) get(m_interval)).intValue(); } + + public Analyzer getAnalyzer() { + + if (m_analyzerClass == null) { + String className = (String) get(m_analyzer); + try { + m_analyzerClass = Class.forName(className); + } catch (Exception ex) { + LOG.error("Unable to load "+className+", using StandardAnalyzer", ex); + return new StandardAnalyzer(); + } + } + try { + return (Analyzer) m_analyzerClass.newInstance(); + } catch (Exception ex) { + LOG.error("Unable to create Lucene analyzer, using StandardAnalyzer", ex); + return new StandardAnalyzer(); + } + } + } Modified: trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig_parameter.properties =================================================================== --- trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig_parameter.properties 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneConfig_parameter.properties 2005-09-21 17:01:27 UTC (rev 887) @@ -5,4 +5,8 @@ waf.lucene.interval.title=Lucene update interval waf.lucene.interval.purpose=The frequency with which the Lucene index is updated waf.lucene.interval.example=120 -waf.lucene.interval.format=[integer] \ No newline at end of file +waf.lucene.interval.format=[integer] +waf.lucene.analyzer.title=Lucene Analyzer implementation +waf.lucene.analyzer.purpose=The class implementing the Analyzer, standard by default +waf.lucene.analyzer.example=org.apache.lucene.analysis.standard.StandardAnalyzer +waf.lucene.analyzer.format=[string] Modified: trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneSearch.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneSearch.java 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/src/com/arsdigita/search/lucene/LuceneSearch.java 2005-09-21 17:01:27 UTC (rev 887) @@ -21,7 +21,7 @@ import com.arsdigita.util.UncheckedWrapperException; import org.apache.log4j.Logger; -import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.DateField; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; @@ -66,11 +66,13 @@ **/ public LuceneSearch(String searchString) { try { + LuceneConfig conf = LuceneConfig.getConfig(); + Analyzer analyzer = conf.getAnalyzer(); synchronized(LOCK) { m_index = new IndexSearcher(Index.getLocation()); Query query = QueryParser.parse(searchString, Document.CONTENT, - new StandardAnalyzer()); + analyzer); m_hits = m_index.search(query); } m_hitIndex = 0; @@ -99,11 +101,13 @@ **/ public LuceneSearch(String searchString, Filter f) { try { + LuceneConfig conf = LuceneConfig.getConfig(); + Analyzer analyzer = conf.getAnalyzer(); synchronized(LOCK) { m_index = new IndexSearcher(Index.getLocation()); Query query = QueryParser.parse(searchString, Document.CONTENT, - new StandardAnalyzer()); + analyzer); m_hits = m_index.search(query, f); } m_hitIndex = 0; Modified: trunk/ccm-core/test/src/com/arsdigita/search/lucene/SearchTest.java =================================================================== --- trunk/ccm-core/test/src/com/arsdigita/search/lucene/SearchTest.java 2005-09-21 16:47:54 UTC (rev 886) +++ trunk/ccm-core/test/src/com/arsdigita/search/lucene/SearchTest.java 2005-09-21 17:01:27 UTC (rev 887) @@ -21,7 +21,7 @@ import com.arsdigita.search.Search; import java.math.BigDecimal; import org.apache.log4j.Logger; -import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexWriter; /** @@ -153,9 +153,11 @@ } private void cleanIndex() throws Exception { + LuceneConfig conf = LuceneConfig.getConfig(); + Analyzer analyzer = conf.getAnalyzer(); synchronized (LuceneLock.getInstance()) { IndexWriter iw = new IndexWriter(Index.getLocation(), - new StandardAnalyzer(), + analyzer, true); iw.close(); |