Incorporating TUV r1845/1846 - update lucene
git-svn-id: https://svn.libreccm.org/ccm/trunk@95 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
ed0197e820
commit
584e543e08
|
|
@ -18,9 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.search;
|
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.ContentType;
|
||||||
import com.arsdigita.cms.search.ContentTypeFilterSpecification;
|
|
||||||
import com.arsdigita.cms.search.ContentTypeFilterType;
|
|
||||||
import com.arsdigita.kernel.PartyCollection;
|
import com.arsdigita.kernel.PartyCollection;
|
||||||
import com.arsdigita.search.FilterSpecification;
|
import com.arsdigita.search.FilterSpecification;
|
||||||
import com.arsdigita.search.FilterType;
|
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.SqlFilter;
|
||||||
import com.arsdigita.search.lucene.TypeSpecificFilter;
|
import com.arsdigita.search.lucene.TypeSpecificFilter;
|
||||||
import com.arsdigita.search.lucene.UnionFilter;
|
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 {
|
public class LuceneQueryEngine extends BaseQueryEngine {
|
||||||
|
|
@ -90,14 +91,17 @@ public class LuceneQueryEngine extends BaseQueryEngine {
|
||||||
protected void addDateRangeFilter(List list,
|
protected void addDateRangeFilter(List list,
|
||||||
DateRangeFilterSpecification filter,
|
DateRangeFilterSpecification filter,
|
||||||
String paramName) {
|
String paramName) {
|
||||||
Date startDate = filter.getStartDate();
|
String startDate = (filter.getStartDate() == null ? null : DateTools.dateToString(filter.getStartDate(),
|
||||||
Date endDate = filter.getEndDate();
|
Resolution.MINUTE));
|
||||||
|
String endDate = (filter.getEndDate() == null ? null : DateTools.dateToString(filter.getEndDate(),
|
||||||
|
Resolution.MINUTE));
|
||||||
|
|
||||||
if (startDate != null && endDate != null) {
|
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) {
|
} else if (startDate != null) {
|
||||||
list.add(DateFilter.After(paramName, startDate));
|
list.add(RangeFilter.More(paramName, startDate));
|
||||||
} else if (endDate != null) {
|
} 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,
|
protected void addContentTypeFilter(List list,
|
||||||
ContentTypeFilterSpecification filter) {
|
ContentTypeFilterSpecification filter) {
|
||||||
List l = new ArrayList();
|
|
||||||
ContentType[] types = filter.getTypes();
|
ContentType[] types = filter.getTypes();
|
||||||
if (types == null || types.length == 0) {
|
if (types == null || types.length == 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -18,30 +18,29 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.search.lucene;
|
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.DataQuery;
|
||||||
import com.arsdigita.persistence.Session;
|
import com.arsdigita.persistence.Session;
|
||||||
import com.arsdigita.persistence.SessionManager;
|
import com.arsdigita.persistence.SessionManager;
|
||||||
import com.arsdigita.persistence.TransactionContext;
|
import com.arsdigita.persistence.TransactionContext;
|
||||||
import com.arsdigita.runtime.RuntimeConfig;
|
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.
|
* Indexer.
|
||||||
*
|
*
|
||||||
|
|
@ -52,8 +51,8 @@ import org.apache.lucene.index.Term;
|
||||||
class Indexer extends TimerTask {
|
class Indexer extends TimerTask {
|
||||||
|
|
||||||
public final static String versionId =
|
public final static String versionId =
|
||||||
"$Id: Indexer.java 1517 2007-03-22 10:52:37Z sskracic $" +
|
"$Id: Indexer.java 1845 2009-03-05 13:39:09Z terry $" +
|
||||||
" by $Author: sskracic $, $DateTime: 2004/08/16 18:10:38 $";
|
" by $Author: terry $, $DateTime: 2004/08/16 18:10:38 $";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(Indexer.class);
|
Logger.getLogger(Indexer.class);
|
||||||
|
|
@ -177,7 +176,7 @@ class Indexer extends TimerTask {
|
||||||
}
|
}
|
||||||
IndexReader ir = IndexReader.open(m_index);
|
IndexReader ir = IndexReader.open(m_index);
|
||||||
try {
|
try {
|
||||||
ir.delete(new Term(Document.ID, doc.getID().toString()));
|
ir.deleteDocuments(new Term(Document.ID, doc.getID().toString()));
|
||||||
} finally {
|
} finally {
|
||||||
ir.close();
|
ir.close();
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +204,7 @@ class Indexer extends TimerTask {
|
||||||
org.apache.lucene.document.Document result =
|
org.apache.lucene.document.Document result =
|
||||||
new org.apache.lucene.document.Document();
|
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 language = "";
|
||||||
String country = "";
|
String country = "";
|
||||||
|
|
@ -214,36 +213,29 @@ class Indexer extends TimerTask {
|
||||||
language = locale.getLanguage();
|
language = locale.getLanguage();
|
||||||
country = locale.getCountry();
|
country = locale.getCountry();
|
||||||
}
|
}
|
||||||
result.add(Field.Keyword(Document.LANGUAGE, language));
|
result.add(new Field(Document.LANGUAGE, language, Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.COUNTRY, country));
|
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(Field.Keyword(Document.TYPE, doc.getType()));
|
result.add(new Field(Document.TYPE_SPECIFIC_INFO, toString(doc.getTypeSpecificInfo()), Field.Store.YES,
|
||||||
result.add(Field.Keyword(Document.TYPE_SPECIFIC_INFO,
|
Field.Index.NOT_ANALYZED));
|
||||||
toString(doc.getTypeSpecificInfo())));
|
result.add(new Field(Document.TITLE, toString(doc.getTitle()), Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.TITLE, doc.getTitle()));
|
result.add(new Field(Document.SUMMARY, toString(doc.getSummary()), Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.SUMMARY,
|
result.add(new Field(Document.CONTENT, new StringReader(toString(doc.getContent()))));
|
||||||
toString(doc.getSummary())));
|
result.add(new Field(Document.CREATION_DATE, DateTools.timeToString(doc.getCreationDate().getTime(),
|
||||||
result.add(Field.Text(Document.CONTENT, toString(doc.getContent())));
|
DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.CREATION_DATE,
|
result.add(new Field(Document.CREATION_PARTY, toString(doc.getCreationParty()), Field.Store.YES,
|
||||||
toString(doc.getCreationDate())));
|
Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.CREATION_PARTY,
|
result.add(new Field(Document.LAST_MODIFIED_DATE, DateTools.timeToString(doc.getLastModifiedDate().getTime(),
|
||||||
toString(doc.getCreationParty())));
|
DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.LAST_MODIFIED_DATE,
|
result.add(new Field(Document.LAST_MODIFIED_PARTY, toString(doc.getLastModifiedParty()), Field.Store.YES,
|
||||||
toString(doc.getLastModifiedDate())));
|
Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.LAST_MODIFIED_PARTY,
|
result.add(new Field(Document.CONTENT_SECTION, toString(doc.getContentSection()), Field.Store.YES,
|
||||||
toString(doc.getLastModifiedParty())));
|
Field.Index.NOT_ANALYZED));
|
||||||
result.add(Field.Keyword(Document.CONTENT_SECTION,
|
|
||||||
toString(doc.getContentSection())));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String toString(Date date) {
|
|
||||||
return date == null ? "" : DateField.dateToString(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String toString(Object obj) {
|
private static final String toString(Object obj) {
|
||||||
return obj == null ? "" : obj.toString();
|
return obj == null ? "" : obj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.search.lucene;
|
package com.arsdigita.search.lucene;
|
||||||
|
|
||||||
import com.arsdigita.search.Search;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -28,9 +27,10 @@ import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
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.ParseException;
|
||||||
import org.apache.lucene.queryParser.QueryParser;
|
import org.apache.lucene.queryParser.QueryParser;
|
||||||
import org.apache.lucene.search.Filter;
|
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.IndexSearcher;
|
||||||
import org.apache.lucene.search.Query;
|
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
|
* 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.
|
* information for each hit.
|
||||||
*
|
*
|
||||||
* @author Richard Su (richard.su@alum.mit.edu)
|
* @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 {
|
try {
|
||||||
LuceneConfig conf = LuceneConfig.getConfig();
|
LuceneConfig conf = LuceneConfig.getConfig();
|
||||||
Analyzer analyzer = conf.getAnalyzer();
|
Analyzer analyzer = conf.getAnalyzer();
|
||||||
m_query = QueryParser.parse(searchString,
|
QueryParser parser = new QueryParser(Document.CONTENT, analyzer);
|
||||||
Document.CONTENT,
|
m_query = parser.parse(searchString);
|
||||||
analyzer);
|
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
LOG.fatal("failed parsing the expression: " + searchString, ex);
|
LOG.fatal("failed parsing the expression: " + searchString, ex);
|
||||||
}
|
}
|
||||||
|
|
@ -447,7 +449,11 @@ public class LuceneSearch {
|
||||||
if (date == null || date.equals("")) {
|
if (date == null || date.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return DateField.stringToDate(date);
|
try {
|
||||||
|
return DateTools.stringToDate(date);
|
||||||
|
} catch (java.text.ParseException e) {
|
||||||
|
throw new UncheckedWrapperException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue