}
}
IInterestedInSearch[] plugins = PluginManager.getInterestedInSearch();
log.debug("Number of plugins able to carry out search:"+plugins.length);
SearchQuery query = new SearchQuery(somethingToSearch);
//do the search
for (int i = 0; i < plugins.length; i++) {
plugins[i].doSearch(query, DocumStruct.FIELD_SORT_SCORE, true,
searchCount,useThreading);
}
//wait till all the search plugins are done or time out was reached
if(useThreading){
boolean wait = true;
log.debug(
"Wait for plugin to finish the search operation (plugins are ready or time expired)");
while (wait && !Util.isTimeExpired(start, maxWaitSearchTime)) {
wait = false;
for (int i = 0; i < plugins.length; i++) {
if (!plugins[i].isReady()) {
wait = true;
}
}
}
}
//iterate on the plugins and gather the result:startno,endno,list of documents found it, search query)
int countErrors = 0;
int countHits = 0;
List allDocs = new ArrayList();
for (int i = 0; i < plugins.length; i++) {
ISearchResult result = plugins[i].getResults();
countHits = countHits + result.getCountFound();
countErrors = countErrors + result.getCountErrors();
allDocs.addAll(result.getDocuments());
}
if (allDocs.size() > 0) {
//we found documents (maybe with errors
myModel.put(ModelView.STARTNO, "1");
myModel.put(ModelView.ENDNO, String.valueOf(allDocs.size()));
myModel.put(ModelView.DOCUMENTSNO,
String.valueOf(allDocs.size()));
myModel.put(ModelView.DOCUMENTS, allDocs);
myModel.put(ModelView.ERROR, "false");
float elapsedTimeMillis = (System.currentTimeMillis() - start) / 1000F;
myModel.put(ModelView.SEARCHTIME,
String.valueOf(elapsedTimeMillis));
if (countErrors == 0) {
myModel.put(ModelView.STATUS,
MessageUtil.getMessage("app.search.status.noerror"));
} else {
myModel.put(ModelView.STATUS,
MessageUtil.getMessage("app.search.status.errors",
new Object[] { String.valueOf(countErrors) }));
}
} else {
//no document was found it
log.debug("No pages were found containing " +
query.getQuery());
myModel.put(ModelView.ERROR, "true");
myModel.put(ModelView.STATUS,
MessageUtil.getMessage("app.search.status.nopage",
new Object[] { query.getQuery() }));
}
} catch (RpException e) {
log.warn("Exception in search " + e.getMessage(), e);
myModel.put(ModelView.ERROR, "true");