001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.geonet.services.main;
025:
026: import org.jdom.*;
027:
028: import jeeves.interfaces.*;
029: import jeeves.server.*;
030: import jeeves.server.context.*;
031:
032: import org.fao.geonet.constants.*;
033: import org.fao.geonet.kernel.search.*;
034: import org.fao.geonet.GeonetContext;
035: import org.fao.geonet.services.util.MainUtil;
036:
037: //=============================================================================
038:
039: /** main.search service. Perform a search
040: */
041:
042: public class Search implements Service {
043: private ServiceConfig _config;
044:
045: //--------------------------------------------------------------------------
046: //---
047: //--- Init
048: //---
049: //--------------------------------------------------------------------------
050:
051: public void init(String appPath, ServiceConfig config)
052: throws Exception {
053: _config = config;
054: }
055:
056: //--------------------------------------------------------------------------
057: //---
058: //--- Service
059: //---
060: //--------------------------------------------------------------------------
061:
062: public Element exec(Element params, ServiceContext context)
063: throws Exception {
064: GeonetContext gc = (GeonetContext) context
065: .getHandlerContext(Geonet.CONTEXT_NAME);
066:
067: SearchManager searchMan = gc.getSearchmanager();
068:
069: Element elData = MainUtil.getDefaultSearch(context, params);
070: String sRemote = elData
071: .getChildText(Geonet.SearchResult.REMOTE);
072: boolean remote = sRemote != null
073: && sRemote.equals(Geonet.Text.ON);
074:
075: Element title = params.getChild(Geonet.SearchResult.TITLE);
076: Element abstr = params.getChild(Geonet.SearchResult.ABSTRACT);
077: Element any = params.getChild(Geonet.SearchResult.ANY);
078:
079: if (title != null)
080: title.setText(MainUtil.splitWord(title.getText()));
081:
082: if (abstr != null)
083: abstr.setText(MainUtil.splitWord(abstr.getText()));
084:
085: if (any != null)
086: any.setText(MainUtil.splitWord(any.getText()));
087:
088: // possibly close old searcher
089: UserSession session = context.getUserSession();
090: MetaSearcher oldSearcher = (MetaSearcher) session
091: .getProperty(Geonet.Session.SEARCH_RESULT);
092:
093: if (oldSearcher != null)
094: oldSearcher.close();
095:
096: // perform the search and save search result into session
097: MetaSearcher searcher;
098:
099: context.info("Creating searchers");
100:
101: if (remote)
102: searcher = searchMan.newSearcher(SearchManager.Z3950,
103: Geonet.File.SEARCH_Z3950_CLIENT);
104: else
105: searcher = searchMan.newSearcher(SearchManager.LUCENE,
106: Geonet.File.SEARCH_LUCENE);
107:
108: searcher.search(context, params, _config);
109: session.setProperty(Geonet.Session.SEARCH_RESULT, searcher);
110:
111: context.info("Getting summary");
112:
113: return searcher.getSummary();
114: }
115: }
116:
117: //=============================================================================
|