Search in sources :

Example 1 with TopDocs

use of org.apache.maven.index_shaded.lucene.search.TopDocs in project archiva by apache.

the class ArchivaIndexingTaskExecutorTest method testUpdateArtifactInIndex.

@Test
public void testUpdateArtifactInIndex() throws Exception {
    Path basePath = repo.getLocalPath();
    Path artifactFile = basePath.resolve("org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar");
    ArtifactIndexingTask task = new ArtifactIndexingTask(repo, artifactFile, ArtifactIndexingTask.Action.ADD, repo.getIndexingContext());
    indexingExecutor.executeTask(task);
    indexingExecutor.executeTask(task);
    BooleanQuery.Builder qb = new BooleanQuery.Builder();
    qb.add(indexer.constructQuery(MAVEN.GROUP_ID, new StringSearchExpression("org.apache.archiva")), BooleanClause.Occur.SHOULD);
    qb.add(indexer.constructQuery(MAVEN.ARTIFACT_ID, new StringSearchExpression("archiva-index-methods-jar-test")), BooleanClause.Occur.SHOULD);
    IndexingContext ctx = getIndexingContext();
    IndexSearcher searcher = ctx.acquireIndexSearcher();
    TopDocs topDocs = searcher.search(qb.build(), 10);
    // searcher.close();
    ctx.releaseIndexSearcher(searcher);
    assertTrue(Files.exists(basePath.resolve(".indexer")));
    assertTrue(Files.exists(basePath.resolve(".index")));
    // should only return 1 hit!
    assertEquals(1, topDocs.totalHits);
}
Also used : Path(java.nio.file.Path) IndexSearcher(org.apache.maven.index_shaded.lucene.search.IndexSearcher) TopDocs(org.apache.maven.index_shaded.lucene.search.TopDocs) BooleanQuery(org.apache.maven.index_shaded.lucene.search.BooleanQuery) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) StringSearchExpression(org.apache.maven.index.expr.StringSearchExpression) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)1 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)1 IndexingContext (org.apache.maven.index.context.IndexingContext)1 StringSearchExpression (org.apache.maven.index.expr.StringSearchExpression)1 BooleanQuery (org.apache.maven.index_shaded.lucene.search.BooleanQuery)1 IndexSearcher (org.apache.maven.index_shaded.lucene.search.IndexSearcher)1 TopDocs (org.apache.maven.index_shaded.lucene.search.TopDocs)1 Test (org.junit.Test)1