Incorporating TUV r1845/1846 - update lucene

git-svn-id: https://svn.libreccm.org/ccm/trunk@95 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2009-03-15 14:51:02 +00:00
parent ed0197e820
commit 584e543e08
3 changed files with 70 additions and 69 deletions

View File

@ -18,9 +18,16 @@
*/
package com.arsdigita.cms.search;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.DateTools.Resolution;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.RangeFilter;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.search.ContentTypeFilterSpecification;
import com.arsdigita.cms.search.ContentTypeFilterType;
import com.arsdigita.kernel.PartyCollection;
import com.arsdigita.search.FilterSpecification;
import com.arsdigita.search.FilterType;
@ -33,12 +40,6 @@ import com.arsdigita.search.lucene.PartyFilter;
import com.arsdigita.search.lucene.SqlFilter;
import com.arsdigita.search.lucene.TypeSpecificFilter;
import com.arsdigita.search.lucene.UnionFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.lucene.search.DateFilter;
import org.apache.lucene.search.Filter;
public class LuceneQueryEngine extends BaseQueryEngine {
@ -90,14 +91,17 @@ public class LuceneQueryEngine extends BaseQueryEngine {
protected void addDateRangeFilter(List list,
DateRangeFilterSpecification filter,
String paramName) {
Date startDate = filter.getStartDate();
Date endDate = filter.getEndDate();
String startDate = (filter.getStartDate() == null ? null : DateTools.dateToString(filter.getStartDate(),
Resolution.MINUTE));
String endDate = (filter.getEndDate() == null ? null : DateTools.dateToString(filter.getEndDate(),
Resolution.MINUTE));
if (startDate != null && endDate != null) {
list.add(new DateFilter(paramName, startDate, endDate));
list.add(new RangeFilter(paramName, startDate, endDate, true, true));
} else if (startDate != null) {
list.add(DateFilter.After(paramName, startDate));
list.add(RangeFilter.More(paramName, startDate));
} else if (endDate != null) {
list.add(DateFilter.Before(paramName, startDate));
list.add(RangeFilter.Less(paramName, endDate));
}
}
@ -125,7 +129,6 @@ public class LuceneQueryEngine extends BaseQueryEngine {
protected void addContentTypeFilter(List list,
ContentTypeFilterSpecification filter) {
List l = new ArrayList();
ContentType[] types = filter.getTypes();
if (types == null || types.length == 0) {
return;

View File

@ -18,30 +18,29 @@
*/
package com.arsdigita.search.lucene;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TimerTask;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.TransactionContext;
import com.arsdigita.runtime.RuntimeConfig;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Locale;
import java.util.TimerTask;
import java.util.List;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.DateField;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
/**
* Indexer.
*
@ -52,8 +51,8 @@ import org.apache.lucene.index.Term;
class Indexer extends TimerTask {
public final static String versionId =
"$Id: Indexer.java 1517 2007-03-22 10:52:37Z sskracic $" +
" by $Author: sskracic $, $DateTime: 2004/08/16 18:10:38 $";
"$Id: Indexer.java 1845 2009-03-05 13:39:09Z terry $" +
" by $Author: terry $, $DateTime: 2004/08/16 18:10:38 $";
private static final Logger LOG =
Logger.getLogger(Indexer.class);
@ -177,7 +176,7 @@ class Indexer extends TimerTask {
}
IndexReader ir = IndexReader.open(m_index);
try {
ir.delete(new Term(Document.ID, doc.getID().toString()));
ir.deleteDocuments(new Term(Document.ID, doc.getID().toString()));
} finally {
ir.close();
}
@ -205,7 +204,7 @@ class Indexer extends TimerTask {
org.apache.lucene.document.Document result =
new org.apache.lucene.document.Document();
result.add(Field.Keyword(Document.ID, doc.getID().toString()));
result.add(new Field(Document.ID, doc.getID().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
String language = "";
String country = "";
@ -214,36 +213,29 @@ class Indexer extends TimerTask {
language = locale.getLanguage();
country = locale.getCountry();
}
result.add(Field.Keyword(Document.LANGUAGE, language));
result.add(Field.Keyword(Document.COUNTRY, country));
result.add(Field.Keyword(Document.TYPE, doc.getType()));
result.add(Field.Keyword(Document.TYPE_SPECIFIC_INFO,
toString(doc.getTypeSpecificInfo())));
result.add(Field.Keyword(Document.TITLE, doc.getTitle()));
result.add(Field.Keyword(Document.SUMMARY,
toString(doc.getSummary())));
result.add(Field.Text(Document.CONTENT, toString(doc.getContent())));
result.add(Field.Keyword(Document.CREATION_DATE,
toString(doc.getCreationDate())));
result.add(Field.Keyword(Document.CREATION_PARTY,
toString(doc.getCreationParty())));
result.add(Field.Keyword(Document.LAST_MODIFIED_DATE,
toString(doc.getLastModifiedDate())));
result.add(Field.Keyword(Document.LAST_MODIFIED_PARTY,
toString(doc.getLastModifiedParty())));
result.add(Field.Keyword(Document.CONTENT_SECTION,
toString(doc.getContentSection())));
result.add(new Field(Document.LANGUAGE, language, Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.COUNTRY, country, Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.TYPE, doc.getType(), Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.TYPE_SPECIFIC_INFO, toString(doc.getTypeSpecificInfo()), Field.Store.YES,
Field.Index.NOT_ANALYZED));
result.add(new Field(Document.TITLE, toString(doc.getTitle()), Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.SUMMARY, toString(doc.getSummary()), Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.CONTENT, new StringReader(toString(doc.getContent()))));
result.add(new Field(Document.CREATION_DATE, DateTools.timeToString(doc.getCreationDate().getTime(),
DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.CREATION_PARTY, toString(doc.getCreationParty()), Field.Store.YES,
Field.Index.NOT_ANALYZED));
result.add(new Field(Document.LAST_MODIFIED_DATE, DateTools.timeToString(doc.getLastModifiedDate().getTime(),
DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
result.add(new Field(Document.LAST_MODIFIED_PARTY, toString(doc.getLastModifiedParty()), Field.Store.YES,
Field.Index.NOT_ANALYZED));
result.add(new Field(Document.CONTENT_SECTION, toString(doc.getContentSection()), Field.Store.YES,
Field.Index.NOT_ANALYZED));
return result;
}
private static final String toString(Date date) {
return date == null ? "" : DateField.dateToString(date);
}
private static final String toString(Object obj) {
return obj == null ? "" : obj.toString();
}
}

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.search.lucene;
import com.arsdigita.search.Search;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
@ -28,9 +27,10 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.DateField;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Filter;
@ -39,6 +39,9 @@ import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import com.arsdigita.search.Search;
import com.arsdigita.util.UncheckedWrapperException;
/**
*
* LuceneSearch is a wrapper for the Lucene search facilities. It contains
@ -46,7 +49,7 @@ import org.apache.lucene.search.Query;
* information for each hit.
*
* @author Richard Su (richard.su@alum.mit.edu)
* @version $Id: LuceneSearch.java 1391 2006-11-24 15:02:21Z sskracic $
* @version $Id: LuceneSearch.java 1846 2009-03-06 04:17:36Z terry $
*
**/
@ -110,9 +113,8 @@ public class LuceneSearch {
try {
LuceneConfig conf = LuceneConfig.getConfig();
Analyzer analyzer = conf.getAnalyzer();
m_query = QueryParser.parse(searchString,
Document.CONTENT,
analyzer);
QueryParser parser = new QueryParser(Document.CONTENT, analyzer);
m_query = parser.parse(searchString);
} catch (ParseException ex) {
LOG.fatal("failed parsing the expression: " + searchString, ex);
}
@ -447,7 +449,11 @@ public class LuceneSearch {
if (date == null || date.equals("")) {
return null;
} else {
return DateField.stringToDate(date);
try {
return DateTools.stringToDate(date);
} catch (java.text.ParseException e) {
throw new UncheckedWrapperException(e);
}
}
}