*/
@SuppressWarnings("unchecked")
public final HashMap<String, Object> search(final String query, final String[] searchedAttributes, final int count, final int start,
final boolean explain, final String[] sorting, final CRRequest request) throws IOException, CRException {
Searcher searcher;
Analyzer analyzer;
// Collect count + start hits
int hits = count + start; // we want to retreive the startcount (start) to endcount (hits)
LuceneIndexLocation idsLocation = LuceneIndexLocation.getIndexLocation(config);
// TODO: maybe we should make this configurable. Imho this should not be a problem if enabled by default as once a search
// has been executed the Factory is opened and we only need to make sure that on shutdown it is released.
boolean reopenIndexFactory = true;
IndexAccessor indexAccessor = idsLocation.getAccessor(reopenIndexFactory);
if (indexAccessor == null) {
log.error("IndexAccessor is null. Search will not work.");
}
// Resources needed for faceted search
TaxonomyAccessor taAccessor = null;
TaxonomyReader taReader = null;
IndexReader facetsIndexReader = null;
IndexReader uniqueMimeTypesIndexReader = null;
List<String> uniqueMimeTypes = null;
if (retrieveUniqueMimeTypes) {
// retrieve all possible file types
uniqueMimeTypesIndexReader = indexAccessor.getReader(false);
final TermEnum termEnum = uniqueMimeTypesIndexReader.terms(new Term(LUCENE_INDEX_MIMETYPE, ""));
uniqueMimeTypes = new ArrayList<String>();
while (termEnum.next() && termEnum.term().field().equals(LUCENE_INDEX_MIMETYPE)) {
uniqueMimeTypes.add(termEnum.term().text());
}
}
// get accessors and reader only if facets are activated
if (facetsSearch.useFacets()) {
facetsIndexReader = indexAccessor.getReader(false);
taAccessor = idsLocation.getTaxonomyAccessor();
taReader = taAccessor.getTaxonomyReader();
}
searcher = indexAccessor.getPrioritizedSearcher();
Object userPermissionsObject = request.get(CRRequest.PERMISSIONS_KEY);
String[] userPermissions = new String[0];
if (userPermissionsObject instanceof String[]) {
userPermissions = (String[]) userPermissionsObject;
}
TopDocsCollector<?> collector = createCollector(searcher, hits, sorting, computescores, userPermissions);
HashMap<String, Object> result = null;
try {
analyzer = LuceneAnalyzerFactory.createAnalyzer(config);
if (searchedAttributes != null && searchedAttributes.length > 0 && query != null && !query.equals("")) {
QueryParser parser = CRQueryParserFactory.getConfiguredParser(searchedAttributes, analyzer, request, config);
Query parsedQuery = parser.parse(query);
// GENERATE A NATIVE QUERY
parsedQuery = searcher.rewrite(parsedQuery);
result = new HashMap<String, Object>(3);
result.put(RESULT_QUERY_KEY, parsedQuery);
// when facets are active create a FacetsCollector