DebugFile.incIdent();
}
MailRecord[] aRetArr;
BooleanQuery oFld = new BooleanQuery();
for (int f=0; f<aFolderName.length; f++)
oFld.add(new TermQuery(new Term("container",aFolderName[f])),BooleanClause.Occur.SHOULD);
BooleanQuery oQry = new BooleanQuery();
oQry.add(new TermQuery(new Term("workarea",sWorkArea)),BooleanClause.Occur.MUST);
oQry.add(oFld, BooleanClause.Occur.MUST);
if (null!=sSender)
oQry.add(new TermQuery(new Term("author",Gadgets.ASCIIEncode(sSender))),BooleanClause.Occur.MUST);
if (null!=sRecipient)
oQry.add(new TermQuery(new Term("recipients",sRecipient)),BooleanClause.Occur.MUST);
if (null!=sSubject)
oQry.add(new TermQuery(new Term("title",Gadgets.ASCIIEncode(sSubject))),BooleanClause.Occur.MUST);
if (dtFromDate!=null && dtToDate!=null)
oQry.add(new RangeQuery(new Term("created",DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY)),
new Term("created",DateTools.dateToString(dtToDate, DateTools.Resolution.DAY)), true), BooleanClause.Occur.MUST);
else if (dtFromDate!=null)
oQry.add(new RangeQuery(new Term("created",DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY)),
new Term("created",DateTools.dateToString(new Date(299,11,31), DateTools.Resolution.DAY)), true), BooleanClause.Occur.MUST);
else if (dtToDate!=null)
oQry.add(new RangeQuery(new Term("created",DateTools.dateToString(new Date(79,11,31), DateTools.Resolution.DAY)),
new Term("created",DateTools.dateToString(dtToDate, DateTools.Resolution.DAY)), true), BooleanClause.Occur.MUST);
if (null!=sText)
oQry.add(new TermQuery(new Term("text",sText)),BooleanClause.Occur.SHOULD);
String sSegments = Gadgets.chomp(sLuceneIndexPath,File.separator)+"k_mime_msgs"+File.separator+sWorkArea;
if (DebugFile.trace) DebugFile.writeln("new IndexSearcher("+sSegments+")");
IndexSearcher oSearch = new IndexSearcher(sSegments);
if (iLimit>0) {
if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQry.toString()+", null, "+String.valueOf(iLimit)+")");
TopDocs oTopSet = oSearch.search(oQry, null, iLimit);
if (oTopSet.scoreDocs!=null) {
ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
int iDocCount = oTopDoc.length;
if (DebugFile.trace) DebugFile.writeln("doc count is "+String.valueOf(iDocCount));
aRetArr = new MailRecord[iDocCount];
for (int d=0; d<iDocCount; d++) {
Document oDoc = oSearch.doc(oTopDoc[d].doc);
String[] aAbstract = Gadgets.split(oSearch.doc(oTopDoc[d].doc).get("abstract"), 'ยจ');
aRetArr[d] = new MailRecord(aAbstract[0], aAbstract[1], aAbstract[2],
aAbstract[3], aAbstract[4], aAbstract[5],
oDoc.get("container"));
} // next
} else {
aRetArr = null;
}
} else {
if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQry.toString()+")");
Hits oHitSet = oSearch.search(oQry);
int iHitCount = oHitSet.length();
if (DebugFile.trace) DebugFile.writeln("hit count is "+String.valueOf(iHitCount));
if (iHitCount>0) {
aRetArr = new MailRecord[iHitCount];