//--- some other stuff
if(Log.isDebugEnabled(Geonet.LUCENE))
Log.debug(Geonet.LUCENE, "CRITERIA:\n"+ Xml.getString(request));
SettingInfo settingInfo = _sm.getSettingInfo();
SettingInfo.SearchRequestLanguage requestedLanguageOnly = settingInfo.getRequestedLanguageOnly();
if(Log.isDebugEnabled(Geonet.LUCENE))
Log.debug(Geonet.LUCENE, "requestedLanguageOnly: " + requestedLanguageOnly);
// --- operation parameter
List<Content> operations = new ArrayList<Content>(request.getChildren("operation"));
// removes the parameter from the request
request.removeChildren("operation");
// Handles operation (filter by download / dynamic visible to the
// current user)
if (operations.size() > 0) {
StringBuilder grpList = new StringBuilder();
for (Integer g : userGroups) {
if (grpList.length() > 0)
grpList.append(" or ");
grpList.append(g);
}
String grps = grpList.toString();
for (Content elem : operations) {
if (elem.getValue().equalsIgnoreCase("view")) {
request.addContent(new Element("_operation0").addContent(grps));
} else if (elem.getValue().equalsIgnoreCase("download")) {
request.addContent(new Element("_operation1").addContent(grps));
} else if (elem.getValue().equalsIgnoreCase("editing")) {
request.addContent(new Element("_operation2").addContent(grps));
} else if (elem.getValue().equalsIgnoreCase("notify")) {
request.addContent(new Element("_operation3").addContent(grps));
} else if (elem.getValue().equalsIgnoreCase("dynamic")) {
request.addContent(new Element("_operation5").addContent(grps));
} else if (elem.getValue().equalsIgnoreCase("featured")) {
request.addContent(new Element("_operation6").addContent(grps));
}
}
}
if (_styleSheetName.equals(Geonet.File.SEARCH_Z3950_SERVER)) {
// Construct Lucene query by XSLT, not Java, for Z3950 anyway :-)
Element xmlQuery = _sm.transform(_styleSheetName, request);
if(Log.isDebugEnabled(Geonet.SEARCH_ENGINE))
Log.debug(Geonet.SEARCH_ENGINE, "XML QUERY:\n"+ Xml.getString(xmlQuery));
_query = LuceneSearcher.makeLocalisedQuery(xmlQuery, SearchManager.getAnalyzer(_language.analyzerLanguage, true), _luceneConfig, _language.presentationLanguage, requestedLanguageOnly);
}
else {
// Construct Lucene query (Java)
if(Log.isDebugEnabled(Geonet.LUCENE))
Log.debug(Geonet.LUCENE, "LuceneSearcher constructing Lucene query (LQB)");
LuceneQueryInput luceneQueryInput = new LuceneQueryInput(request);
luceneQueryInput.setRequestedLanguageOnly(requestedLanguageOnly);
_query = new LuceneQueryBuilder(_tokenizedFieldSet, _luceneConfig.getNumericFields(), SearchManager.getAnalyzer(_language.analyzerLanguage, true), _language.presentationLanguage).build(luceneQueryInput);
if(Log.isDebugEnabled(Geonet.SEARCH_ENGINE))
Log.debug(Geonet.SEARCH_ENGINE,"Lucene query: " + _query);
try {
// only for debugging -- might cause NPE is query was wrongly constructed
//Query rw = _query.rewrite(_indexAndTaxonomy.indexReader);
//if(Log.isDebugEnabled(Geonet.SEARCH_ENGINE)) Log.debug(Geonet.SEARCH_ENGINE,"Rewritten Lucene query: " + _query);
//System.out.println("** rewritten:\n"+ rw);
}
catch(Throwable x){
Log.warning(Geonet.SEARCH_ENGINE,"Error rewriting Lucene query: " + _query);
//System.out.println("** error rewriting query: "+x.getMessage());
}
}
// Boosting query
if (_boostQueryClass != null) {
try {
if(Log.isDebugEnabled(Geonet.SEARCH_ENGINE)) {
Log.debug(Geonet.SEARCH_ENGINE, "Create boosting query:" + _boostQueryClass);
}
@SuppressWarnings("unchecked")
Class<Query> boostClass = (Class<Query>) Class.forName(_boostQueryClass);
Class<?>[] clTypesArray = _luceneConfig.getBoostQueryParameterClass();
Object[] inParamsArray = _luceneConfig.getBoostQueryParameter();
Class<?>[] clTypesArrayAll = new Class[clTypesArray.length + 1];
clTypesArrayAll[0] = Class.forName("org.apache.lucene.search.Query");
System.arraycopy(clTypesArray, 0, clTypesArrayAll, 1, clTypesArray.length);
Object[] inParamsArrayAll = new Object[inParamsArray.length + 1];
inParamsArrayAll[0] = _query;
System.arraycopy(inParamsArray, 0, inParamsArrayAll, 1, inParamsArray.length);
try {
if(Log.isDebugEnabled(Geonet.SEARCH_ENGINE))
Log.debug(Geonet.SEARCH_ENGINE, "Creating boost query with parameters:" + Arrays.toString(inParamsArrayAll));
Constructor<Query> c = boostClass.getConstructor(clTypesArrayAll);
_query = c.newInstance(inParamsArrayAll);
} catch (Exception e) {
Log.warning(Geonet.SEARCH_ENGINE, " Failed to create boosting query: " + e.getMessage()
+ ". Check Lucene configuration");
e.printStackTrace();
}
} catch (Exception e1) {
Log.warning(Geonet.SEARCH_ENGINE, " Error on boosting query initialization: " + e1.getMessage()
+ ". Check Lucene configuration");
}
}
// Use RegionsData rather than fetching from the DB everytime
//
//request.addContent(Lib.db.select(dbms, "Regions", "region"));
//RegionsDAO dao = srvContext.getApplicationContext().getBean(RegionsDAO.class);
//request.addContent(dao.getAllRegionsAsXml(srvContext));
}
Collection<Geometry> geometry = getGeometry(srvContext, request);
SpatialFilter spatialfilter = null;
if (geometry != null) {
if (_sm.getLogSpatialObject()) {
StringBuilder wkt = new StringBuilder();
for (Geometry geom : geometry) {
wkt.append("geom:").append(geom.toText()).append("\n");
}
_geomWKT = wkt.toString();
}
spatialfilter = _sm.getSpatial().filter(_query, Integer.MAX_VALUE, geometry, request);
}
Filter duplicateRemovingFilter = new DuplicateDocFilter(_query, 1000000);
Filter filter;
if (spatialfilter == null) {
filter = duplicateRemovingFilter;
} else {
Filter[] filters = new Filter[]{duplicateRemovingFilter, spatialfilter};
filter = new ChainedFilter(filters, ChainedFilter.AND);
}
_filter = new CachingWrapperFilter(filter);
String sortBy = Util.getParam(request, Geonet.SearchResult.SORT_BY, Geonet.SearchResult.SortBy.RELEVANCE);
boolean sortOrder = (Util.getParam(request, Geonet.SearchResult.SORT_ORDER, "").equals(""));
if(Log.isDebugEnabled(Geonet.SEARCH_ENGINE))
Log.debug(Geonet.SEARCH_ENGINE, "Sorting by : " + sortBy);
SettingInfo settingInfo = _sm.getSettingInfo();
boolean sortRequestedLanguageOnTop = settingInfo.getRequestedLanguageOnTop();
if(Log.isDebugEnabled(Geonet.LUCENE))
Log.debug(Geonet.LUCENE, "sortRequestedLanguageOnTop: " + sortRequestedLanguageOnTop);
_sort = LuceneSearcher.makeSort(Collections.singletonList(Pair.read(sortBy, sortOrder)), _language.presentationLanguage, sortRequestedLanguageOnTop);