StringBuffer tempBuf = new StringBuffer();
if (currentIndex.getShouldBeSearched()) {
String findText = "";
// create searcher
Searcher searcher = new IndexSearcher(currentIndex.getIndexPath());
if ((searchText.indexOf("(") != -1) || (searchText.indexOf("[") != -1)) {
findText = searchText;
}
else {
// add body and title, or single field to query
if (selectedFields == 0) {
findText = "+(" + Index.FIELD_BODY + ":(" + searchText + ") OR " +
Index.FIELD_TITLE + ":(" + searchText + "))";
}
else {
// TODO dont use sField directly, because it is translated in other languages
findText = "+" + sField + ":(" + searchText + ")";
}
// add author to query
if (useAuthor.isSelected()) {
findText += " +" + Index.FIELD_AUTHOR + ":(" + authorField.getText() + ")";
}
// add filetype to query
if (useType.isSelected()) {
findText += " +" + Index.FIELD_TYPE + ":(" + fileTypesToGet[fileType.getSelectedIndex()] + ")";
}
}
logger.debug("doSearch() query string '" + findText + "'");
setStatus(dsSrchStr + ": " + findText + "...");
// create query
QueryParser queryParser = new QueryParser(Index.FIELD_BODY, new StandardAnalyzer());
Query query = queryParser.parse(findText);
// check for date filter and search in index
Hits hits;
if (useDate.isSelected()) {
String dateFrom = DateTimeUtils.getDateStringForIndex(DateTimeUtils.getDateFromString(fromField.getText()));
String dateTo = DateTimeUtils.getDateStringForIndex(DateTimeUtils.getDateFromString(toField.getText()));
RangeFilter rangeFilter = new RangeFilter(Index.FIELD_MODDATE, dateFrom, dateTo, true, true);
if (logger.isDebugEnabled()) {
logger.debug("doSearch() search with date range '" + rangeFilter + "'");
}
hits = searcher.search(query, rangeFilter);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("doSearch() search without date range");
}
hits = searcher.search(query);
}
// check for search with filesize
int numHits;
if (useSize.isSelected()) {
int minFilesize = 1;
int maxFilesize = 2;
try {
minFilesize = Integer.parseInt(sizeFromField.getText()) * 1024;
maxFilesize = Integer.parseInt(sizeToField.getText()) * 1024;
}
catch (Exception e) {
setStatus(dsErrParseNums + " " + e.toString());
}
sizeList = getHitsForFilesizeRange(hits, minFilesize, maxFilesize);
numHits = sizeList[0].size();
}
else {
numHits = hits.length(); // NOT A SIZE QUERY
}
searchedIndexes.append("<li> <font color=\"blue\">");
searchedIndexes.append(currentIndex.getDescription());
searchedIndexes.append("</font> (<b>");
searchedIndexes.append(numHits);
searchedIndexes.append("</b> ");
searchedIndexes.append(I18n.getString("documents"));
searchedIndexes.append(")</li>");
if (env.isGUIMode()) {
if (logger.isDebugEnabled()) {
logger.debug("doSearch() " + I18n.getString("index") + ": " + currentIndex.getDescription());
}
}
else {
System.out.println(I18n.getString("index") + ": " + currentIndex.getDescription());
}
grandTotalHits += numHits;
tempBuf.append("<p align=\"center\"><b>");
tempBuf.append(numHits);
tempBuf.append("</b> ");
tempBuf.append(dsDocsFndInIndx);
tempBuf.append("<b> ");
tempBuf.append(currentIndex.getDescription());
tempBuf.append("</b></p>");
curSrchPos++;
if (curSrchPos > 0) {
pPanel.setCurPos(curSrchPos);
}
for (int i = 0; i < numHits; i++) {
if (i > maxNumHitsShown) {
setStatus(dsMxNumHits + " (" + maxNumHitsShown + ") " + I18n.getString("exceeded") + " (" + numHits + ").");
break;
}
// get document and score from result or special result
Document currentDocument;
float currentScore;
// filesize result?
if (useSize.isSelected()) {
currentDocument = (Document) sizeList[0].get(i);
currentScore = ((Float) sizeList[1].get(i)).floatValue();
}
else {
currentDocument = hits.doc(i);
currentScore = hits.score(i);
}
// title
String currentTitle = Utils.convertTextToHTML(currentDocument.get(Index.FIELD_TITLE));
// filesize
String currentFilesize = currentDocument.get(Index.FIELD_SIZE);
// path or url
String currentFile;
if (! currentIndex.getIsWeb()) {
if (! isCdRomIdx) {
currentFile = currentDocument.get(Index.FIELD_PATH);
}
else {
currentFile = getCDROMPath(currentDocument.get(Index.FIELD_URL));
}
}
else {
currentFile = currentDocument.get(Index.FIELD_URL);
}
// type
String currentTypeStr = currentDocument.get(Index.FIELD_TYPE);
FileType currentType = FileType.fromValue(currentTypeStr);
// author
String currentAuthor = currentDocument.get(Index.FIELD_AUTHOR);
if ("".equals(currentAuthor)) {
currentAuthor = I18n.getString("unknown");
}
// date
String currentDate = currentDocument.get(Index.FIELD_MODDATE);
if ("".equals(currentDate)) {
currentDate = I18n.getString("unknown");
}
else {
currentDate = DateTimeUtils.getDateParsedFromIndex(currentDate);
}
String currentSummary = Utils.convertTextToHTML(currentDocument.get(Index.FIELD_SUMMARY));
// add it to our page - doc size title score
tempBuf.append("<p align=\"left\">");
if (! currentIndex.getIsWeb()) {
tempBuf.append("<a href=\"");
tempBuf.append(fileString);
tempBuf.append(currentFile);
tempBuf.append("\">");
}
else {
tempBuf.append("<a href=\"");
tempBuf.append(currentFile);
tempBuf.append("\">");
}
if (hasIcons) {
switch (currentType) {
case HTML: // html
tempBuf.append(htmlTag);
break;
case MS_WORD: // ms word
tempBuf.append(wordTag);
break;
case MS_EXCEL: // ms excel
tempBuf.append(excelTag);
break;
case PDF: // pdf
tempBuf.append(pdfTag);
break;
case RTF: // rtf
tempBuf.append(rtfTag);
break;
case OO_WRITER: // openoffice writer
tempBuf.append(ooWriterTag);
break;
case OO_IMPRESS: // openoffice impress
tempBuf.append(ooImpressTag);
break;
case OO_CALC: // openoffice calc
tempBuf.append(ooCalcTag);
break;
case OO_DRAW: // openoffice draw
tempBuf.append(ooDrawTag);
break;
case OPENDOCUMENT_TEXT: // opendocument text
tempBuf.append(openDocumentTextTag);
break;
case TEXT:
tempBuf.append(textTag);
break;
default:
logger.error("doSearch() FileType." + currentType + " is not ok here!");
}
}
else {
tempBuf.append(currentTypeStr);
}
tempBuf.append(" ");
tempBuf.append(currentTitle);
tempBuf.append("</a><br>");
tempBuf.append(currentSummary);
tempBuf.append("<font color=\"green\"><br><em>");
tempBuf.append(currentDate);
tempBuf.append(", ");
tempBuf.append(Utils.getKStyle(currentFilesize));
tempBuf.append("bytes, ");
tempBuf.append(currentAuthor);
tempBuf.append(", <b>");
tempBuf.append(Utils.getPercentStringFromScore(currentScore));
tempBuf.append("</b></em></font><br><font color=\"gray\">");
tempBuf.append(currentFile);
tempBuf.append("</font>");
tempBuf.append("</p>");
if (env.isGUIMode()) {
if (logger.isDebugEnabled()) {
logger.debug("doSearch() \n\n* " + currentTitle + "\n" + currentSummary + "\n" + currentDate + ", " +
Utils.getKStyle(currentFilesize) + "bytes, " + currentAuthor + ", " +
Utils.getPercentStringFromScore(currentScore) + "\n" + currentFile);
}
}
else {
System.out.println("\n\n* " + currentTitle + "\n" + currentSummary + "\n" + currentDate + ", " +
Utils.getKStyle(currentFilesize) + "bytes, " + currentAuthor + ", " +
Utils.getPercentStringFromScore(currentScore) + "\n" + currentFile);
}
} // end for hits
// now add our results
curSrchPos++;
if (curSrchPos > 0) {
pPanel.setCurPos(curSrchPos);
}
// add the footer
bodyBuf.append(tempBuf);
// close index
searcher.close();
} // end if shouldbesearched
else {
tempBuf.append("<p align=\"left\">");
tempBuf.append(I18n.getString("index"));
tempBuf.append(" <b>");