boolean requestedLanguageOnTop = sm.getSettingInfo().getRequestedLanguageOnTop();
Query data;
LuceneConfig luceneConfig = getLuceneConfig();
if (luceneExpr == null) {
data = null;
Log.info(Geonet.CSW_SEARCH, "LuceneSearcher made null query");
} else {
PerFieldAnalyzerWrapper analyzer = SearchManager.getAnalyzer(_lang.analyzerLanguage, true);
SettingInfo.SearchRequestLanguage requestedLanguageOnly = sm.getSettingInfo().getRequestedLanguageOnly();
data = LuceneSearcher.makeLocalisedQuery(luceneExpr,
analyzer, luceneConfig, _lang.presentationLanguage, requestedLanguageOnly);
Log.info(Geonet.CSW_SEARCH, "LuceneSearcher made query:\n" + data.toString());
}
Query cswCustomFilterQuery = null;
Log.info(Geonet.CSW_SEARCH,"LuceneSearcher cswCustomFilter:\n" + cswServiceSpecificContraint);
if (StringUtils.isNotEmpty(cswServiceSpecificContraint)) {
cswCustomFilterQuery = getCswServiceSpecificConstraintQuery(cswServiceSpecificContraint, luceneConfig);
Log.info(Geonet.CSW_SEARCH,"LuceneSearcher cswCustomFilterQuery:\n" + cswCustomFilterQuery);
}
Query groups = getGroupsQuery(context);
if (sort == null) {
List<Pair<String, Boolean>> fields = Collections.singletonList(Pair.read(Geonet.SearchResult.SortBy.RELEVANCE, true));
sort = LuceneSearcher.makeSort(fields, _lang.presentationLanguage, requestedLanguageOnTop);
}
// --- put query on groups in AND with lucene query
BooleanQuery query = new BooleanQuery();
// FIXME : DO I need to fix that here ???
// BooleanQuery.setMaxClauseCount(1024); // FIXME : using MAX_VALUE
// solve
// // partly the org.apache.lucene.search.BooleanQuery$TooManyClauses
// // problem.
// // Improve index content.
BooleanClause.Occur occur = LuceneUtils.convertRequiredAndProhibitedToOccur(true, false);
if (data != null) {
query.add(data, occur);
}
query.add(groups, occur);
if (cswCustomFilterQuery != null) {
query.add(cswCustomFilterQuery, occur);
}
// --- proper search
if(Log.isDebugEnabled(Geonet.CSW_SEARCH))
Log.debug(Geonet.CSW_SEARCH, "Lucene query: " + query.toString());
int numHits = startPosition + maxRecords;
updateRegionsInSpatialFilter(context, filterExpr);
// TODO Handle NPE creating spatial filter (due to constraint)
_filter = sm.getSpatial().filter(query, Integer.MAX_VALUE, filterExpr, filterVersion);
boolean buildSummary = resultType == ResultType.RESULTS_WITH_SUMMARY;
// get as many results as instructed or enough for search summary
if (buildSummary) {
numHits = Math.max(maxHitsInSummary, numHits);
}
// record globals for reuse
_query = query;
_sort = sort;
ServiceConfig config = new ServiceConfig();
String geomWkt = null;
LuceneSearcher.logSearch(context, config, _query, numHits, _sort, geomWkt, sm);
Pair<TopDocs,Element> searchResults = LuceneSearcher.doSearchAndMakeSummary(numHits, startPosition - 1,
maxRecords, _lang.presentationLanguage,
luceneConfig.getTaxonomy().get(resultType.toString()), luceneConfig.getTaxonomyConfiguration(),
reader, _query, wrapSpatialFilter(),
_sort, taxonomyReader, buildSummary, luceneConfig.isTrackDocScores(), luceneConfig.isTrackMaxScore(),
luceneConfig.isDocsScoredInOrder()
);
TopDocs hits = searchResults.one();
Element summary = searchResults.two();
numHits = Integer.parseInt(summary.getAttributeValue("count"));