|
|
|
|
|
|
|
|
import org.apache.maven.index_shaded.lucene.search.BooleanClause; |
|
|
import org.apache.maven.index_shaded.lucene.search.BooleanClause; |
|
|
import org.apache.maven.index_shaded.lucene.search.BooleanClause.Occur; |
|
|
import org.apache.maven.index_shaded.lucene.search.BooleanClause.Occur; |
|
|
import org.apache.maven.index_shaded.lucene.search.BooleanQuery; |
|
|
import org.apache.maven.index_shaded.lucene.search.BooleanQuery; |
|
|
|
|
|
import org.apache.maven.index_shaded.lucene.search.Query; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
// since upgrade to nexus 2.0.0, query has changed from g:[QUERIED TERM]* to g:*[QUERIED TERM]* |
|
|
// since upgrade to nexus 2.0.0, query has changed from g:[QUERIED TERM]* to g:*[QUERIED TERM]* |
|
|
// resulting to more wildcard searches so we need to increase max clause count |
|
|
// resulting to more wildcard searches so we need to increase max clause count |
|
|
BooleanQuery.setMaxClauseCount( Integer.MAX_VALUE ); |
|
|
BooleanQuery.setMaxClauseCount( Integer.MAX_VALUE ); |
|
|
BooleanQuery q = new BooleanQuery(); |
|
|
|
|
|
|
|
|
BooleanQuery.Builder qb = new BooleanQuery.Builder(); |
|
|
|
|
|
|
|
|
if ( previousSearchTerms == null || previousSearchTerms.isEmpty() ) |
|
|
if ( previousSearchTerms == null || previousSearchTerms.isEmpty() ) |
|
|
{ |
|
|
{ |
|
|
constructQuery( term, q ); |
|
|
|
|
|
|
|
|
constructQuery( term, qb ); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
for ( String previousTerm : previousSearchTerms ) |
|
|
for ( String previousTerm : previousSearchTerms ) |
|
|
{ |
|
|
{ |
|
|
BooleanQuery iQuery = new BooleanQuery(); |
|
|
|
|
|
|
|
|
BooleanQuery.Builder iQuery = new BooleanQuery.Builder(); |
|
|
constructQuery( previousTerm, iQuery ); |
|
|
constructQuery( previousTerm, iQuery ); |
|
|
|
|
|
|
|
|
q.add( iQuery, BooleanClause.Occur.MUST ); |
|
|
|
|
|
|
|
|
qb.add( iQuery.build(), BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
BooleanQuery iQuery = new BooleanQuery(); |
|
|
|
|
|
|
|
|
BooleanQuery.Builder iQuery = new BooleanQuery.Builder(); |
|
|
constructQuery( term, iQuery ); |
|
|
constructQuery( term, iQuery ); |
|
|
q.add( iQuery, BooleanClause.Occur.MUST ); |
|
|
|
|
|
|
|
|
qb.add( iQuery.build(), BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty |
|
|
// we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty |
|
|
// FIXME cannot find a way currently to setup this in constructQuery !!! |
|
|
// FIXME cannot find a way currently to setup this in constructQuery !!! |
|
|
return search( limits, q, indexingContextIds, NoClassifierArtifactInfoFilter.LIST, selectedRepos, true ); |
|
|
|
|
|
|
|
|
return search( limits, qb.build(), indexingContextIds, NoClassifierArtifactInfoFilter.LIST, selectedRepos, true ); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new SearchResults(); |
|
|
return new SearchResults(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
BooleanQuery q = new BooleanQuery(); |
|
|
|
|
|
|
|
|
BooleanQuery.Builder qb = new BooleanQuery.Builder(); |
|
|
if ( StringUtils.isNotBlank( searchFields.getGroupId() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getGroupId() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( MAVEN.GROUP_ID, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
searchFields.getGroupId() ) : new UserInputSearchExpression( searchFields.getGroupId() ) ), |
|
|
searchFields.getGroupId() ) : new UserInputSearchExpression( searchFields.getGroupId() ) ), |
|
|
BooleanClause.Occur.MUST ); |
|
|
BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, |
|
|
searchFields.isExactSearch() |
|
|
searchFields.isExactSearch() |
|
|
? new SourcedSearchExpression( searchFields.getArtifactId() ) |
|
|
? new SourcedSearchExpression( searchFields.getArtifactId() ) |
|
|
: new UserInputSearchExpression( searchFields.getArtifactId() ) ), |
|
|
: new UserInputSearchExpression( searchFields.getArtifactId() ) ), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getVersion() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getVersion() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
searchFields.getVersion() ) : new SourcedSearchExpression( searchFields.getVersion() ) ), |
|
|
searchFields.getVersion() ) : new SourcedSearchExpression( searchFields.getVersion() ) ), |
|
|
BooleanClause.Occur.MUST ); |
|
|
BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getPackaging() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getPackaging() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.PACKAGING, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( MAVEN.PACKAGING, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
searchFields.getPackaging() ) : new UserInputSearchExpression( searchFields.getPackaging() ) ), |
|
|
searchFields.getPackaging() ) : new UserInputSearchExpression( searchFields.getPackaging() ) ), |
|
|
BooleanClause.Occur.MUST ); |
|
|
BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getClassName() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getClassName() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.CLASSNAMES, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( MAVEN.CLASSNAMES, |
|
|
new UserInputSearchExpression( searchFields.getClassName() ) ), |
|
|
new UserInputSearchExpression( searchFields.getClassName() ) ), |
|
|
BooleanClause.Occur.MUST ); |
|
|
BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME, |
|
|
new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ), |
|
|
BooleanClause.Occur.MUST ); |
|
|
BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.VERSION, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.VERSION, |
|
|
new UserInputSearchExpression( searchFields.getBundleVersion() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleVersion() ) ), |
|
|
BooleanClause.Occur.MUST ); |
|
|
BooleanClause.Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE, |
|
|
new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.EXPORT_SERVICE, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.EXPORT_SERVICE, |
|
|
new UserInputSearchExpression( searchFields.getBundleExportService() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleExportService() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, |
|
|
new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleName() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleName() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.NAME, new UserInputSearchExpression( searchFields.getBundleName() ) ), |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.NAME, new UserInputSearchExpression( searchFields.getBundleName() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, |
|
|
new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE, |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE, |
|
|
new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ), |
|
|
new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( StringUtils.isNotBlank( searchFields.getClassifier() ) ) |
|
|
if ( StringUtils.isNotBlank( searchFields.getClassifier() ) ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.CLASSIFIER, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
|
|
|
|
|
|
qb.add( indexer.constructQuery( MAVEN.CLASSIFIER, searchFields.isExactSearch() ? new SourcedSearchExpression( |
|
|
searchFields.getClassifier() ) : new UserInputSearchExpression( searchFields.getClassifier() ) ), |
|
|
searchFields.getClassifier() ) : new UserInputSearchExpression( searchFields.getClassifier() ) ), |
|
|
Occur.MUST ); |
|
|
Occur.MUST ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// currently it's done in DefaultSearchService with some filtering |
|
|
// currently it's done in DefaultSearchService with some filtering |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( q.getClauses() == null || q.getClauses().length <= 0 ) |
|
|
|
|
|
|
|
|
BooleanQuery qu = qb.build(); |
|
|
|
|
|
if ( qu.clauses() == null || qu.clauses().size() <= 0 ) |
|
|
{ |
|
|
{ |
|
|
throw new RepositorySearchException( "No search fields set." ); |
|
|
throw new RepositorySearchException( "No search fields set." ); |
|
|
} |
|
|
} |
|
|
if (q.getClauses()!=null) { |
|
|
|
|
|
log.debug("CLAUSES ", q.getClauses()); |
|
|
|
|
|
for (BooleanClause cl : q.getClauses()) { |
|
|
|
|
|
|
|
|
if (qu.clauses()!=null) { |
|
|
|
|
|
log.debug("CLAUSES ", qu.clauses()); |
|
|
|
|
|
for (BooleanClause cl : qu.clauses()) { |
|
|
log.debug("Clause ",cl); |
|
|
log.debug("Clause ",cl); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return search( limits, q, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(), |
|
|
|
|
|
|
|
|
return search( limits, qu, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(), |
|
|
searchFields.getRepositories(), searchFields.isIncludePomArtifacts() ); |
|
|
searchFields.getRepositories(), searchFields.isIncludePomArtifacts() ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return contexts; |
|
|
return contexts; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void constructQuery( String term, BooleanQuery q ) |
|
|
|
|
|
|
|
|
private void constructQuery( String term, BooleanQuery.Builder q ) |
|
|
{ |
|
|
{ |
|
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD ); |
|
|
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD ); |
|
|
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD ); |
|
|
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD ); |