Search in sources :

Example 1 with Query

use of org.apache.maven.index_shaded.lucene.search.Query 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));
}
Also used : Path(java.nio.file.Path) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) Query(org.apache.maven.index_shaded.lucene.search.Query) UserInputSearchExpression(org.apache.maven.index.expr.UserInputSearchExpression) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) Test(org.junit.Test)

Example 2 with Query

use of org.apache.maven.index_shaded.lucene.search.Query 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));
}
Also used : Path(java.nio.file.Path) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) Query(org.apache.maven.index_shaded.lucene.search.Query) UserInputSearchExpression(org.apache.maven.index.expr.UserInputSearchExpression) ArrayList(java.util.ArrayList) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) URI(java.net.URI) Test(org.junit.Test)

Example 3 with Query

use of org.apache.maven.index_shaded.lucene.search.Query 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));
}
Also used : Path(java.nio.file.Path) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) Query(org.apache.maven.index_shaded.lucene.search.Query) UserInputSearchExpression(org.apache.maven.index.expr.UserInputSearchExpression) ArrayList(java.util.ArrayList) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)3 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)3 IndexingContext (org.apache.maven.index.context.IndexingContext)3 UserInputSearchExpression (org.apache.maven.index.expr.UserInputSearchExpression)3 BooleanQuery (org.apache.maven.index_shaded.lucene.search.BooleanQuery)3 Query (org.apache.maven.index_shaded.lucene.search.Query)3 Test (org.junit.Test)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2