*/
public Element exec(Element params, ServiceContext context) throws Exception
{
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
SearchManager searchMan = gc.getBean(SearchManager.class);
String restoreLastSearch = _config.getValue("restoreLastSearch","no");
// store or possibly close old searcher
UserSession session = context.getUserSession();
Object oldSearcher = session.getProperty(Geonet.Session.SEARCH_RESULT);
if (oldSearcher != null) {
if (restoreLastSearch.equals("yes")) {
session.setProperty(Geonet.Session.LAST_SEARCH_RESULT, oldSearcher);
} else {
if (oldSearcher instanceof LuceneSearcher) ((LuceneSearcher)oldSearcher).close();
}
}
context.info("Get selected metadata");
SelectionManager sm = SelectionManager.getManager(session) ;
// Get the sortBy params in order to apply on new result list.
if (StringUtils.isNotEmpty(params.getChildText(Geonet.SearchResult.SORT_BY)) ) {
params.addContent(new Element(Geonet.SearchResult.SORT_BY).setText(params.getChildText(Geonet.SearchResult.SORT_BY)));
}
if (StringUtils.isNotEmpty(params.getChildText(Geonet.SearchResult.SORT_ORDER))) {
params.addContent(new Element(Geonet.SearchResult.SORT_ORDER).setText(params.getChildText(Geonet.SearchResult.SORT_ORDER)));
}
if (sm != null) {
String uuids= "";
boolean first = true;
synchronized(sm.getSelection("metadata")) {
for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
String uuid = (String) iter.next();
if (first) {
uuids = (String) uuid;
first = false;
}
else
uuids = uuids +" or "+ uuid;
}
}
if(context.isDebugEnabled())
context.debug("List of selected uuids: " + uuids);
params.addContent(new Element(Geonet.SearchResult.UUID).setText(uuids));
}
// perform the search and save search result into session
MetaSearcher searcher;
context.info("Creating searchers");
searcher = searchMan.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_LUCENE);
searcher.search(context, params, _config);
session.setProperty(Geonet.Session.SEARCH_RESULT, searcher);