use of org.apache.maven.index.expr.UserInputSearchExpression 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());
}
use of org.apache.maven.index.expr.UserInputSearchExpression in project archiva by apache.
the class MavenIndexManagerTest method scan.
@Test
public void scan() throws Exception {
createTestContext();
Path destDir = repository.getLocalPath().resolve("org/apache/archiva/archiva-webapp/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-webapp/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
mavenIndexManager.scan(ctx);
IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)), BooleanClause.Occur.SHOULD).build();
assertEquals(4, mvnCtx.acquireIndexSearcher().count(q));
}
use of org.apache.maven.index.expr.UserInputSearchExpression in project archiva by apache.
the class MavenIndexManagerTest method addArtifactsToIndex.
@Test
public void addArtifactsToIndex() throws Exception {
ArchivaIndexingContext ctx = createTestContext();
Path destDir = repository.getLocalPath().resolve("org/apache/archiva/archiva-search/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
List<URI> uriList = new ArrayList<>();
uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri());
uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri());
mavenIndexManager.addArtifactsToIndex(ctx, uriList);
IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)), BooleanClause.Occur.SHOULD).build();
assertEquals(2, mvnCtx.acquireIndexSearcher().count(q));
}
use of org.apache.maven.index.expr.UserInputSearchExpression in project archiva by apache.
the class MavenIndexManagerTest method removeArtifactsFromIndex.
@Test
public void removeArtifactsFromIndex() throws Exception {
ArchivaIndexingContext ctx = createTestContext();
Path destDir = repository.getLocalPath().resolve("org/apache/archiva/archiva-search/1.0");
Path srcDir = Paths.get("src/test/maven-search-test-repo/org/apache/archiva/archiva-search/1.0");
org.apache.commons.io.FileUtils.copyDirectory(srcDir.toFile(), destDir.toFile());
List<URI> uriList = new ArrayList<>();
uriList.add(destDir.resolve("archiva-search-1.0.jar").toUri());
uriList.add(destDir.resolve("archiva-search-1.0-sources.jar").toUri());
mavenIndexManager.addArtifactsToIndex(ctx, uriList);
IndexingContext mvnCtx = mavenIndexManager.getMvnContext(ctx);
String term = "org.apache.archiva";
Query q = new BooleanQuery.Builder().add(queryCreator.constructQuery(MAVEN.GROUP_ID, new UserInputSearchExpression(term)), BooleanClause.Occur.SHOULD).build();
assertEquals(2, mvnCtx.acquireIndexSearcher().count(q));
uriList.remove(0);
mavenIndexManager.removeArtifactsFromIndex(ctx, uriList);
assertEquals(1, mvnCtx.acquireIndexSearcher().count(q));
}
Aggregations