⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keywordssearcher.java

📁 联合国农粮署牵头开发的geonetwork源代码最新版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//===	Copyright (C) 2001-2005 Food and Agriculture Organization of the//===	United Nations (FAO-UN), United Nations World Food Programme (WFP)//===	and United Nations Environment Programme (UNEP)//===//===	This program is free software; you can redistribute it and/or modify//===	it under the terms of the GNU General Public License as published by//===	the Free Software Foundation; either version 2 of the License, or (at//===	your option) any later version.//===//===	This program is distributed in the hope that it will be useful, but//===	WITHOUT ANY WARRANTY; without even the implied warranty of//===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU//===	General Public License for more details.//===//===	You should have received a copy of the GNU General Public License//===	along with this program; if not, write to the Free Software//===	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//===//===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,//===	Rome - Italy. email: GeoNetwork@fao.org//==============================================================================package org.fao.geonet.kernel.search;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Hashtable;import java.util.Enumeration;import java.util.List;import java.util.Vector;import jeeves.server.context.ServiceContext;import jeeves.utils.Util;import org.fao.geonet.kernel.Thesaurus;import org.fao.geonet.kernel.ThesaurusManager;import org.fao.geonet.kernel.KeywordBean;import org.jdom.Element;import org.openrdf.model.Value;import org.openrdf.sesame.query.QueryResultsTable;public class KeywordsSearcher {	private ThesaurusManager _tm;	private String _query;	private String _lang;	private String _sortBy = "label";	private String _sortOrder = "ascending";	private ArrayList<KeywordBean> _results = new ArrayList<KeywordBean>();	private int _pTypeSearch = 1;	// --------------------------------------------------------------------------------	// constructor	public KeywordsSearcher(ThesaurusManager tm) {		_tm = tm;	}	// --------------------------------------------------------------------------------	public KeywordBean searchById(String id, String sThesaurusName, String lang)	throws Exception {		_query = "SELECT prefLab, note, id, lowc, uppc "			+ " FROM {id} rdf:type {skos:Concept}; "			+ " skos:prefLabel {prefLab};"			+ " [skos:scopeNote {note} WHERE lang(note) LIKE \""+lang+"\"]; "			+ " [gml:BoundedBy {} gml:lowerCorner {lowc}]; "			+ " [gml:BoundedBy {} gml:upperCorner {uppc}] "			+ " WHERE lang(prefLab) LIKE \""+lang+"\" "			+ " AND id LIKE \""+id+"\" "			+ " IGNORE CASE "			+ " USING NAMESPACE skos=<http://www.w3.org/2004/02/skos/core#>, gml=<http://www.opengis.net/gml#> ";			Thesaurus thesaurus = _tm.getThesaurusByName(sThesaurusName);			// Perform request			QueryResultsTable resultsTable = thesaurus.performRequest(_query);			int rowCount = resultsTable.getRowCount();			int idKeyword = 0;			if (rowCount == 0){				return null;			}else{				// MUST be one because search by ID				// preflab				Value value = resultsTable.getValue(0, 0);				String sValue = "";				if (value != null) {					sValue = value.toString();				}//				 uri (= id in RDF file != id in list)				Value uri = resultsTable.getValue(0, 2);				String sUri = "";				if (uri != null) {					sUri = uri.toString();				}				KeywordBean kb = new KeywordBean(idKeyword, sValue,						"", sUri, "", "", "", "",						sThesaurusName, false, _lang);				idKeyword++;				return kb;			}	}	public void search(ServiceContext srvContext, Element params)			throws Exception {		// Get params from request and set default		String sKeyword = Util.getParam(params, "pKeyword");		// Type of search		int pTypeSearch = _pTypeSearch;		if (params.getChild("pTypeSearch") != null){							// if param pTypeSearch not here			pTypeSearch = Util.getParamAsInt(params, "pTypeSearch");		// Thesaurus to search in		List listThesauri = new Vector<Element>();		// Type of thesaurus to search in		String pTypeThesaurus = null;		if (params.getChild("pType") != null)							// if param pTypeSearch not here			pTypeThesaurus = Util.getParam(params, "pType");		boolean bAll = true;		if (params.getChild("pThesauri") != null){							// if param pThesauri not here			listThesauri = params.getChildren("pThesauri");			bAll = false;			if (((Element) listThesauri.get(0)).getTextTrim().equals(""))	// If first element is empty </>				bAll = true;		}		//	If no thesaurus search in all.		if (bAll){			Hashtable<String, Thesaurus> tt = _tm.getThesauriTable();			Enumeration e = tt.keys();			boolean add = true;		    while (e.hasMoreElements())										// Fill the list with all thesauri available		    {		    	Thesaurus thesaurus = tt.get(e.nextElement());		    	if (pTypeThesaurus != null){			    	if (!thesaurus.getDname().equals(pTypeThesaurus)) // Add thesaurus only if type is corresponding with MD type (based on ISO type ie. theme, discipline, ...)			    		add = false;			    	else			    		add = true;		    	}		    	if (add){		    		Element el = new Element("pThesauri");			    	el.addContent(thesaurus.getKey());			    	listThesauri.add(el);		    	}		    }		}		// Keyword to look for		if (!sKeyword.equals("")) {			// FIXME : Where to search ? only on term having GUI language or in all ?			// Should be			// - look for a term in all language			// - get prefLab in GUI lang			// This will cause multilingual metadata search quite complex !!			// Quid Lucene and thesaurus ?			String _lang = srvContext.getLanguage();			_query = "SELECT prefLab, note, id, lowc, uppc "				+ " FROM {id} rdf:type {skos:Concept}; "				+ " skos:prefLabel {prefLab};"				+ " [skos:scopeNote {note} WHERE lang(note) LIKE \""+_lang+"\"]; "				+ " [gml:BoundedBy {} gml:lowerCorner {lowc}]; "				+ " [gml:BoundedBy {} gml:upperCorner {uppc}] "				+ " WHERE lang(prefLab) LIKE \""+_lang+"\""				+ " AND prefLab LIKE ";			switch (pTypeSearch) {			case 0: // commence par				_query += "\""+ sKeyword+ "*\" ";				break;			case 1: // contient				_query += "\"*"+ sKeyword+ "*\" ";				break;			case 2: // terme exact				_query += "\""+ sKeyword+ "\" ";				break;			default:				break;			}			_query 	+= " IGNORE CASE "					+ " USING NAMESPACE skos=<http://www.w3.org/2004/02/skos/core#>, gml=<http://www.opengis.net/gml#> ";		}		// For each thesaurus, search for keywords in _results		_results = new ArrayList<KeywordBean>();		int idKeyword = 0;		for (int i = 0; i < listThesauri.size(); i++) { 			// Search in all Thesaurus if none selected			Element el = (Element) listThesauri.get(i);			String sThesaurusName = el.getTextTrim();			Thesaurus thesaurus = _tm.getThesaurusByName(sThesaurusName);			// Perform request			QueryResultsTable resultsTable = thesaurus.performRequest(_query);			int rowCount = resultsTable.getRowCount();			for (int row = 0; row < rowCount; row++) {				// preflab				Value value = resultsTable.getValue(row, 0);				String sValue = "";				if (value != null) {					sValue = value.toString();				}				// definition				Value definition = resultsTable.getValue(row, 1);				String sDefinition = "";				if (definition != null) {					sDefinition = definition.toString();				}				// uri (= id in RDF file != id in list)				Value uri = resultsTable.getValue(row, 2);				String sUri = "";				if (uri != null) {					sUri = uri.toString();				}				// lowcorner				Value lowCorner = resultsTable.getValue(row, 4);				String sLowCorner = "";				String sEast = "";				String sSouth = "";				if (lowCorner != null) {					sLowCorner = lowCorner.toString();					sEast = sLowCorner.substring(0, sLowCorner.indexOf(' '))							.trim();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -