Search in sources :

Example 6 with SearchResultHit

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

the class MavenRepositorySearchTest method testMultipleArtifactsSameVersionWithClassifier.

@Test
public void testMultipleArtifactsSameVersionWithClassifier() throws Exception {
    createIndexContainingMultipleArtifactsSameVersion(true);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    // search artifactId
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setArtifactId("archiva-search");
    searchFields.setClassifier("sources");
    searchFields.setRepositories(selectedRepos);
    SearchResults results = search.search("user", searchFields, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-search", hit.getArtifactId());
    assertEquals("1.0", hit.getVersions().get(0));
    // only 1 version of 1.0 is retrieved
    assertEquals(1, hit.getVersions().size());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 7 with SearchResultHit

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

the class MavenRepositorySearchTest method testAdvancedSearch.

// tests for advanced search
@Test
public void testAdvancedSearch() throws Exception {
    List<Path> files = new ArrayList<>();
    files.add(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/repos/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar"));
    files.add(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/repos/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar"));
    createIndex(TEST_REPO_2, files, false);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_2);
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setVersion("1.0");
    searchFields.setRepositories(selectedRepos);
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfigControl.replay();
    SearchResults results = search.search("user", searchFields, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals(1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-search", hit.getArtifactId());
    assertEquals("1.0", hit.getVersions().get(0));
}
Also used : Path(java.nio.file.Path) SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) ArrayList(java.util.ArrayList) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 8 with SearchResultHit

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

the class DefaultSearchService method getArtifacts.

// -------------------------------------
// internal
// -------------------------------------
protected List<Artifact> getArtifacts(SearchResults searchResults) throws ArchivaRestServiceException {
    if (searchResults == null || searchResults.isEmpty()) {
        return Collections.emptyList();
    }
    List<Artifact> artifacts = new ArrayList<>(searchResults.getReturnedHitsCount());
    for (SearchResultHit hit : searchResults.getHits()) {
        // duplicate Artifact one per available version
        if (hit.getVersions().size() > 0) {
            for (String version : hit.getVersions()) {
                Artifact versionned = getModelMapper().map(hit, Artifact.class);
                if (StringUtils.isNotBlank(version)) {
                    versionned.setVersion(version);
                    versionned.setUrl(getArtifactUrl(versionned));
                    artifacts.add(versionned);
                }
            }
        }
    }
    return artifacts;
}
Also used : SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) ArrayList(java.util.ArrayList) Artifact(org.apache.archiva.maven2.model.Artifact)

Example 9 with SearchResultHit

use of org.apache.archiva.indexer.search.SearchResultHit 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 10 with SearchResultHit

use of org.apache.archiva.indexer.search.SearchResultHit 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

SearchResultHit (org.apache.archiva.indexer.search.SearchResultHit)14 SearchResults (org.apache.archiva.indexer.search.SearchResults)13 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)7 SearchFields (org.apache.archiva.indexer.search.SearchFields)5 Path (java.nio.file.Path)2 SearchResultLimits (org.apache.archiva.indexer.search.SearchResultLimits)1 Artifact (org.apache.archiva.maven2.model.Artifact)1 ArtifactInfo (org.apache.maven.index.ArtifactInfo)1