r960 - in trunk/wikitty-lucene/src: main/java/org/nuiton/wikitty/storage/lucene test/resources
Author: echatellier Date: 2011-06-22 12:13:34 +0200 (Wed, 22 Jun 2011) New Revision: 960 Url: http://nuiton.org/repositories/revision/wikitty/960 Log: Fix first launch runtime exceptions Added: trunk/wikitty-lucene/src/test/resources/log4j.properties Modified: trunk/wikitty-lucene/src/main/java/org/nuiton/wikitty/storage/lucene/WikittySearchEngineLucene.java Modified: trunk/wikitty-lucene/src/main/java/org/nuiton/wikitty/storage/lucene/WikittySearchEngineLucene.java =================================================================== --- trunk/wikitty-lucene/src/main/java/org/nuiton/wikitty/storage/lucene/WikittySearchEngineLucene.java 2011-06-22 09:47:11 UTC (rev 959) +++ trunk/wikitty-lucene/src/main/java/org/nuiton/wikitty/storage/lucene/WikittySearchEngineLucene.java 2011-06-22 10:13:34 UTC (rev 960) @@ -33,6 +33,7 @@ import java.util.List; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.lucene.analysis.Analyzer; @@ -90,9 +91,6 @@ /** Lucene version used by wikitty. */ protected static final Version WIKITTY_LUCENE_VERSION = Version.LUCENE_32; - /** Index writer config. */ - protected IndexWriterConfig indexWriterConfig; - /** * Constructor. * @@ -104,7 +102,6 @@ try { indexDirectory = getIndexDirectory(config); indexAnalyzer = getIndexAnalyzer(config); - indexWriterConfig = new IndexWriterConfig(WIKITTY_LUCENE_VERSION, indexAnalyzer); } catch (IOException ex) { throw new WikittyException("Can't init lucene directory", ex); } @@ -184,6 +181,8 @@ IndexWriter writer = null; try { + // must be instancied every time (single instance per writer) + IndexWriterConfig indexWriterConfig = new IndexWriterConfig(WIKITTY_LUCENE_VERSION, indexAnalyzer); writer = new IndexWriter(indexDirectory, indexWriterConfig); writer.deleteAll(); writer.commit(); @@ -211,6 +210,8 @@ IndexWriter writer = null; try { + // must be instancied every time (single instance per writer) + IndexWriterConfig indexWriterConfig = new IndexWriterConfig(WIKITTY_LUCENE_VERSION, indexAnalyzer); writer = new IndexWriter(indexDirectory, indexWriterConfig); for (Wikitty w : wikitties) { @@ -252,11 +253,17 @@ String ext = WikittyUtil.getExtensionNameFromFQFieldName(wikyttyField); String fieldName = WikittyUtil.getFieldNameFromFQFieldName(wikyttyField); String value = w.getFieldAsString(ext, fieldName); - - // Store.YES = mandatory for facets - // Index.ANALYZED = mandatory for search on field - Field luceneField = new Field(wikyttyField, value, Store.YES, Index.ANALYZED); - document.add(luceneField); + + if (StringUtils.isNotEmpty(value)) { + if (log.isDebugEnabled()) { + log.debug("add lucene field : " + wikyttyField + " = " + value); + } + + // Store.YES = mandatory for facets + // Index.ANALYZED = mandatory for search on field + Field luceneField = new Field(wikyttyField, value, Store.YES, Index.ANALYZED); + document.add(luceneField); + } } return document; @@ -273,6 +280,8 @@ IndexWriter writer = null; try { + // must be instancied every time (single instance per writer) + IndexWriterConfig indexWriterConfig = new IndexWriterConfig(WIKITTY_LUCENE_VERSION, indexAnalyzer); writer = new IndexWriter(indexDirectory, indexWriterConfig); for (String id : idList) { @@ -333,8 +342,7 @@ sortFields.add(sortField); } } - Sort sortOption = new Sort(sortAscending.toArray(new SortField[sortAscending.size()])); - + // get search offset and limit int firstIndex = criteria.getFirstIndex(); int endIndex = criteria.getEndIndex(); @@ -343,7 +351,13 @@ } // get results - TopDocs topDocs = searcher.search(query, null, endIndex, sortOption); + TopDocs topDocs = null; + if (sortFields.isEmpty()) { + topDocs = searcher.search(query, null, endIndex); + } else { + Sort sortOption = new Sort(sortFields.toArray(new SortField[sortFields.size()])); + topDocs = searcher.search(query, null, endIndex, sortOption); + } ScoreDoc[] scoreDocs = topDocs.scoreDocs; int currentDocIndex = 0; Added: trunk/wikitty-lucene/src/test/resources/log4j.properties =================================================================== --- trunk/wikitty-lucene/src/test/resources/log4j.properties (rev 0) +++ trunk/wikitty-lucene/src/test/resources/log4j.properties 2011-06-22 10:13:34 UTC (rev 960) @@ -0,0 +1,33 @@ +### +# #%L +# Wikitty :: wikitty-lucene +# +# $Id: log4j.properties 650 2010-12-23 11:44:57Z sletellier $ +# $HeadURL: http://svn.nuiton.org/svn/wikitty/trunk/wikitty-jdbc/src/test/resources/log4... $ +# %% +# Copyright (C) 2011 CodeLutin, Chatellier Eric +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +# Appender and Layout +log4j.appender.logConsole=org.apache.log4j.ConsoleAppender +log4j.appender.logConsole.layout=org.apache.log4j.PatternLayout +log4j.appender.logConsole.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n + +# Configuration by components +log4j.rootLogger=DEBUG, logConsole +log4j.category.org.nuiton.wikitty=INFO +log4j.category.org.nuiton.wikitty.storage.lucene=DEBUG \ No newline at end of file
participants (1)
-
echatellier@users.nuiton.org