SearchManager sm = gc.getBean(SearchManager.class);
IndexAndTaxonomy indexAndTaxonomy= sm.getNewIndexReader(null);
try {
GeonetworkMultiReader reader = indexAndTaxonomy.indexReader;
BooleanQuery groupsQuery = (BooleanQuery) CatalogSearcher.getGroupsQuery(context);
BooleanQuery query = null;
// Apply CSW service specific constraint
if (StringUtils.isNotEmpty(cswServiceSpecificConstraint)) {
Query constraintQuery = CatalogSearcher.getCswServiceSpecificConstraintQuery(cswServiceSpecificConstraint, luceneConfig);
query = new BooleanQuery();
BooleanClause.Occur occur = LuceneUtils
.convertRequiredAndProhibitedToOccur(true, false);
query.add(groupsQuery, occur);
query.add(constraintQuery, occur);
} else {
query = groupsQuery;
}
List<Pair<String, Boolean>> sortFields = Collections.singletonList(Pair.read(Geonet.SearchResult.SortBy.RELEVANCE, true));
Sort sort = LuceneSearcher.makeSort(sortFields, context.getLanguage(), false);
CachingWrapperFilter filter = null;
Pair<TopDocs,Element> searchResults = LuceneSearcher.doSearchAndMakeSummary(
maxRecords, 0, maxRecords, context.getLanguage(),
null, luceneConfig.getTaxonomyConfiguration(), reader,
query, filter, sort, null, false, false,
false, false // Scoring is useless for GetDomain operation
);
TopDocs hits = searchResults.one();
try {
// Get mapped lucene field in CSW configuration
String indexField = catalogConfig.getFieldMapping().get(
property.toLowerCase());
if (indexField != null)
property = indexField;
// check if params asked is in the index using getFieldNames ?
@SuppressWarnings("resource")
FieldInfos fi = SlowCompositeReaderWrapper.wrap(reader).getFieldInfos();
if (fi.fieldInfo(property) == null)
continue;
boolean isRange = false;
if (catalogConfig.getGetRecordsRangeFields().contains(
property))
isRange = true;
if (isRange)
listOfValues = new Element("RangeOfValues", Csw.NAMESPACE_CSW);
else
listOfValues = new Element("ListOfValues", Csw.NAMESPACE_CSW);
Set<String> fields = new HashSet<String>();
fields.add(property);
fields.add("_isTemplate");
// parse each document in the index
String[] fieldValues;
Collator stringCollator = Collator.getInstance();
stringCollator.setStrength(Collator.PRIMARY);
SortedSet<String> sortedValues = new TreeSet<String>(stringCollator);
ObjectKeyIntOpenHashMap duplicateValues = new ObjectKeyIntOpenHashMap();
for (int j = 0; j < hits.scoreDocs.length; j++) {
DocumentStoredFieldVisitor selector = new DocumentStoredFieldVisitor(fields);
reader.document(hits.scoreDocs[j].doc, selector);
Document doc = selector.getDocument();
// Skip templates and subTemplates
String[] isTemplate = doc.getValues("_isTemplate");
if (isTemplate[0] != null && !isTemplate[0].equals("n"))