Search in sources :

Example 21 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearch method convertToSearchResults.

private SearchResults convertToSearchResults(FlatSearchResponse response, SearchResultLimits limits, List<? extends ArtifactInfoFilter> artifactInfoFilters, List<String> selectedRepos, boolean includePoms) throws RepositoryAdminException {
    SearchResults results = new SearchResults();
    Set<ArtifactInfo> artifactInfos = response.getResults();
    for (ArtifactInfo artifactInfo : artifactInfos) {
        if (StringUtils.equalsIgnoreCase("pom", artifactInfo.getFileExtension()) && !includePoms) {
            continue;
        }
        String id = // 
        SearchUtil.getHitId(// 
        artifactInfo.getGroupId(), // 
        artifactInfo.getArtifactId(), // 
        artifactInfo.getClassifier(), artifactInfo.getPackaging());
        Map<String, SearchResultHit> hitsMap = results.getHitsMap();
        if (!applyArtifactInfoFilters(artifactInfo, artifactInfoFilters, hitsMap)) {
            continue;
        }
        SearchResultHit hit = hitsMap.get(id);
        if (hit != null) {
            if (!hit.getVersions().contains(artifactInfo.getVersion())) {
                hit.addVersion(artifactInfo.getVersion());
            }
        } else {
            hit = new SearchResultHit();
            hit.setArtifactId(artifactInfo.getArtifactId());
            hit.setGroupId(artifactInfo.getGroupId());
            hit.setRepositoryId(artifactInfo.getRepository());
            hit.addVersion(artifactInfo.getVersion());
            hit.setBundleExportPackage(artifactInfo.getBundleExportPackage());
            hit.setBundleExportService(artifactInfo.getBundleExportService());
            hit.setBundleSymbolicName(artifactInfo.getBundleSymbolicName());
            hit.setBundleVersion(artifactInfo.getBundleVersion());
            hit.setBundleDescription(artifactInfo.getBundleDescription());
            hit.setBundleDocUrl(artifactInfo.getBundleDocUrl());
            hit.setBundleRequireBundle(artifactInfo.getBundleRequireBundle());
            hit.setBundleImportPackage(artifactInfo.getBundleImportPackage());
            hit.setBundleLicense(artifactInfo.getBundleLicense());
            hit.setBundleName(artifactInfo.getBundleName());
            hit.setContext(artifactInfo.getContext());
            hit.setGoals(artifactInfo.getGoals());
            hit.setPrefix(artifactInfo.getPrefix());
            hit.setPackaging(artifactInfo.getPackaging());
            hit.setClassifier(artifactInfo.getClassifier());
            hit.setFileExtension(artifactInfo.getFileExtension());
            hit.setUrl(getBaseUrl(artifactInfo, selectedRepos));
        }
        results.addHit(id, hit);
    }
    results.setTotalHits(response.getTotalHitsCount());
    results.setTotalHitsMapSize(results.getHitsMap().values().size());
    results.setReturnedHitsCount(response.getReturnedHitsCount());
    results.setLimits(limits);
    if (limits == null || limits.getSelectedPage() == SearchResultLimits.ALL_PAGES) {
        return results;
    } else {
        return paginate(results);
    }
}
Also used : ArtifactInfo(org.apache.maven.index.ArtifactInfo) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 22 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearch method search.

private SearchResults search(SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds, List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos, boolean includePoms) throws RepositorySearchException {
    try {
        FlatSearchRequest request = new FlatSearchRequest(q);
        request.setContexts(getIndexingContexts(indexingContextIds));
        if (limits != null) {
            // we apply limits only when first page asked
            if (limits.getSelectedPage() == 0) {
                request.setCount(limits.getPageSize() * (Math.max(1, limits.getSelectedPage())));
            }
        }
        FlatSearchResponse response = indexer.searchFlat(request);
        if (response == null || response.getTotalHitsCount() == 0) {
            SearchResults results = new SearchResults();
            results.setLimits(limits);
            return results;
        }
        return convertToSearchResults(response, limits, filters, selectedRepos, includePoms);
    } catch (IOException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    }
}
Also used : FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) IOException(java.io.IOException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) SearchResults(org.apache.archiva.indexer.search.SearchResults) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 23 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testNoIndexFound.

@Test
public void testNoIndexFound() throws Exception {
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults results = search.search("user", selectedRepos, "org.apache.archiva", null, null);
    assertNotNull(results);
    assertEquals(0, results.getTotalHits());
    archivaConfigControl.verify();
}
Also used : ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 24 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testSearchWithUnknownRepo.

@Test
public void testSearchWithUnknownRepo() throws Exception {
    createIndexContainingMoreArtifacts(true);
    List<String> selectedRepos = Arrays.asList("foo");
    SearchFields searchFields = new SearchFields();
    searchFields.setClassName("SomeClass");
    searchFields.setRepositories(selectedRepos);
    archivaConfigControl.replay();
    SearchResults results = search.search("user", searchFields, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(0, results.getHits().size());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 25 with SearchResults

use of org.apache.archiva.indexer.search.SearchResults in project archiva by apache.

the class MavenRepositorySearchTest method testQuickSearchNotWithClassifier.

@Test
public void testQuickSearchNotWithClassifier() throws Exception {
    createSimpleIndex(true);
    List<String> selectedRepos = Arrays.asList(TEST_REPO_1);
    // search artifactId
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults results = search.search("user", selectedRepos, "archiva-search", null, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    SearchResultHit hit = results.getSearchResultHit(SearchUtil.getHitId("org.apache.archiva", "archiva-search", null, "jar"));
    assertNotNull("hit null in result " + results.getHits(), hit);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-search", hit.getArtifactId());
    assertEquals("1.0", hit.getVersions().get(0));
    archivaConfigControl.reset();
    // search groupId
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    results = search.search("user", selectedRepos, "archiva-search", null, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals("total hints not 3 hits " + results.getHits(), 3, results.getTotalHits());
// TODO: search for class & package names
}
Also used : SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Aggregations

SearchResults (org.apache.archiva.indexer.search.SearchResults)35 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)17 SearchFields (org.apache.archiva.indexer.search.SearchFields)16 SearchResultHit (org.apache.archiva.indexer.search.SearchResultHit)13 SearchResultLimits (org.apache.archiva.indexer.search.SearchResultLimits)9 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)6 Path (java.nio.file.Path)4 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)4 IOException (java.io.IOException)1 URI (java.net.URI)1 TreeMap (java.util.TreeMap)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 Artifact (org.apache.archiva.maven2.model.Artifact)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 ArtifactInfo (org.apache.maven.index.ArtifactInfo)1 FlatSearchRequest (org.apache.maven.index.FlatSearchRequest)1 FlatSearchResponse (org.apache.maven.index.FlatSearchResponse)1 SourcedSearchExpression (org.apache.maven.index.expr.SourcedSearchExpression)1 UserInputSearchExpression (org.apache.maven.index.expr.UserInputSearchExpression)1