use of org.apache.maven.index_shaded.lucene.search.BooleanClause in project archiva by apache.
the class MavenRepositorySearch method search.
/**
* @see RepositorySearch#search(String, SearchFields, SearchResultLimits)
*/
@SuppressWarnings("deprecation")
@Override
public SearchResults search(String principal, SearchFields searchFields, SearchResultLimits limits) throws RepositorySearchException {
if (searchFields.getRepositories() == null) {
throw new RepositorySearchException("Repositories cannot be null.");
}
List<String> indexingContextIds = addIndexingContexts(searchFields.getRepositories());
// olamy: IMHO doesn't make sense
if (!searchFields.getRepositories().isEmpty() && (indexingContextIds == null || indexingContextIds.isEmpty())) {
return new SearchResults();
}
BooleanQuery.Builder qb = new BooleanQuery.Builder();
if (StringUtils.isNotBlank(searchFields.getGroupId())) {
qb.add(indexer.constructQuery(MAVEN.GROUP_ID, searchFields.isExactSearch() ? new SourcedSearchExpression(searchFields.getGroupId()) : new UserInputSearchExpression(searchFields.getGroupId())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getArtifactId())) {
qb.add(indexer.constructQuery(MAVEN.ARTIFACT_ID, searchFields.isExactSearch() ? new SourcedSearchExpression(searchFields.getArtifactId()) : new UserInputSearchExpression(searchFields.getArtifactId())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getVersion())) {
qb.add(indexer.constructQuery(MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression(searchFields.getVersion()) : new SourcedSearchExpression(searchFields.getVersion())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getPackaging())) {
qb.add(indexer.constructQuery(MAVEN.PACKAGING, searchFields.isExactSearch() ? new SourcedSearchExpression(searchFields.getPackaging()) : new UserInputSearchExpression(searchFields.getPackaging())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getClassName())) {
qb.add(indexer.constructQuery(MAVEN.CLASSNAMES, new UserInputSearchExpression(searchFields.getClassName())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleSymbolicName())) {
qb.add(indexer.constructQuery(OSGI.SYMBOLIC_NAME, new UserInputSearchExpression(searchFields.getBundleSymbolicName())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleVersion())) {
qb.add(indexer.constructQuery(OSGI.VERSION, new UserInputSearchExpression(searchFields.getBundleVersion())), BooleanClause.Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleExportPackage())) {
qb.add(indexer.constructQuery(OSGI.EXPORT_PACKAGE, new UserInputSearchExpression(searchFields.getBundleExportPackage())), Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleExportService())) {
qb.add(indexer.constructQuery(OSGI.EXPORT_SERVICE, new UserInputSearchExpression(searchFields.getBundleExportService())), Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleImportPackage())) {
qb.add(indexer.constructQuery(OSGI.IMPORT_PACKAGE, new UserInputSearchExpression(searchFields.getBundleImportPackage())), Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleName())) {
qb.add(indexer.constructQuery(OSGI.NAME, new UserInputSearchExpression(searchFields.getBundleName())), Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleImportPackage())) {
qb.add(indexer.constructQuery(OSGI.IMPORT_PACKAGE, new UserInputSearchExpression(searchFields.getBundleImportPackage())), Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getBundleRequireBundle())) {
qb.add(indexer.constructQuery(OSGI.REQUIRE_BUNDLE, new UserInputSearchExpression(searchFields.getBundleRequireBundle())), Occur.MUST);
}
if (StringUtils.isNotBlank(searchFields.getClassifier())) {
qb.add(indexer.constructQuery(MAVEN.CLASSIFIER, searchFields.isExactSearch() ? new SourcedSearchExpression(searchFields.getClassifier()) : new UserInputSearchExpression(searchFields.getClassifier())), Occur.MUST);
} else if (searchFields.isExactSearch()) {
// TODO improvement in case of exact search and no classifier we must query for classifier with null value
// currently it's done in DefaultSearchService with some filtering
}
BooleanQuery qu = qb.build();
if (qu.clauses() == null || qu.clauses().size() <= 0) {
throw new RepositorySearchException("No search fields set.");
}
if (qu.clauses() != null) {
log.debug("CLAUSES ", qu.clauses());
for (BooleanClause cl : qu.clauses()) {
log.debug("Clause ", cl);
}
}
return search(limits, qu, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(), searchFields.getRepositories(), searchFields.isIncludePomArtifacts());
}
Aggregations