// All indexes has to be build with the same analyzer
mAnalyzer = indexSearcherManagers[0].getAnalyzer();
mIndexName = "multiindex";
} catch (IOException ex) {
throw new RegainException("Couldn't instantiate MultiSearcher.", ex);
}
}
mIndexConfig = indexConfigs[0];
mQuery = null;
if (queryText != null && queryText.length() > 0) {
// start the creation of the lucene query object
try {
mQuery = new BooleanQuery();
for (int k = 0; k < indexConfigs.length; k++) {
String[] searchFieldArr = indexConfigs[k].getSearchFieldList();
for (int i = 0; i < searchFieldArr.length; i++) {
QueryParser parser = new QueryParser(Version.LUCENE_30, searchFieldArr[i], mAnalyzer);
parser.setDefaultOperator(QueryParser.AND_OPERATOR);
parser.setAllowLeadingWildcard(true);
Query fieldQuery = parser.parse(queryText);
// Add as OR
mQuery.add(fieldQuery, Occur.SHOULD);
}
//System.out.println("Query: '" + queryText + "' -> '" + mQuery.toString() + "'");
}
} catch (ParseException exc) {
throw new RegainException("Error while parsing search pattern '" + mQueryText +
"': " + exc.getMessage(), exc);
}
// Check whether access control is used
if (allGroups != null && allGroups.length > 0) {
// Create a query that matches any group
BooleanQuery groupQuery = new BooleanQuery();
for (int i = 0; i < allGroups.length; i++) {
// Add as OR
groupQuery.add(new TermQuery(new Term("groups", allGroups[i])), Occur.SHOULD);
}
// Create a main query that contains the group query and the search query
// combined with AND
BooleanQuery mainQuery = new BooleanQuery();
mainQuery.add(mQuery, Occur.MUST);
mainQuery.add(groupQuery, Occur.MUST);
// Set the main query as query to use
mQuery = mainQuery;
}
}
// Add the mimetype field search
if (mimeTypeFieldText != null) {
BooleanQuery mimetypeFieldQuery = new BooleanQuery();
mimetypeFieldQuery.add(new TermQuery(new Term("mimetype",
mimeTypeFieldText.substring(9).replace("\"", ""))),
Occur.SHOULD);
BooleanQuery mainQuery = new BooleanQuery();
if (mQuery != null) {
mainQuery.add(mQuery, Occur.MUST);
}
mainQuery.add(mimetypeFieldQuery, Occur.MUST);
// Set the main query as query to use
mQuery = mainQuery;
}
if (mQuery != null) {
//System.out.println("Query: '" + mQueryText + "' -> '" + mQuery.toString() + "'");
try {
SortingOption sortingOption = new SortingOption(request.getParameter("order"));
Sort sort = new Sort(sortingOption.getSortField());
//System.out.println(sortingOption.toString());
topDocsCollector = TopFieldCollector.create(sort, 10000, true, true, true, false);
mIndexSearcher.search(mQuery, topDocsCollector);
hitScoreDocs = topDocsCollector.topDocs().scoreDocs;
} catch (IOException exc) {
throw new RegainException("Searching query failed", exc);
}
}
String openInNewWindowRegex = indexConfigs[0].getOpenInNewWindowRegex();
if (openInNewWindowRegex != null) {
try {
mOpenInNewWindowRegex = new RE(openInNewWindowRegex);
} catch (RESyntaxException exc) {
throw new RegainException("Syntax error in openInNewWindowRegex: '" + openInNewWindowRegex + "'", exc);
}
}
} else {
// no index given