Search in sources :

Example 1 with SearchResultHit

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

the class MavenRepositorySearch method paginate.

protected SearchResults paginate(SearchResults results) {
    SearchResultLimits limits = results.getLimits();
    SearchResults paginated = new SearchResults();
    // ( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) );
    int fetchCount = limits.getPageSize();
    int offset = (limits.getSelectedPage() * limits.getPageSize());
    if (fetchCount > results.getTotalHits()) {
        fetchCount = results.getTotalHits();
    }
    // Goto offset.
    if (offset < results.getTotalHits()) {
        // only process if the offset is within the hit count.
        for (int i = 0; i < fetchCount; i++) {
            // Stop fetching if we are past the total # of available hits.
            if (offset + i >= results.getHits().size()) {
                break;
            }
            SearchResultHit hit = results.getHits().get((offset + i));
            if (hit != null) {
                String id = SearchUtil.getHitId(hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), hit.getPackaging());
                paginated.addHit(id, hit);
            } else {
                break;
            }
        }
    }
    paginated.setTotalHits(results.getTotalHits());
    paginated.setReturnedHitsCount(paginated.getHits().size());
    paginated.setTotalHitsMapSize(results.getTotalHitsMapSize());
    paginated.setLimits(limits);
    return paginated;
}
Also used : SearchResultLimits(org.apache.archiva.indexer.search.SearchResultLimits) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 2 with SearchResultHit

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

the class MavenRepositorySearchOSGITest method searchFelixWithSymbolicName.

@Test
public void searchFelixWithSymbolicName() throws Exception {
    createIndex(TEST_REPO_1, Collections.<Path>emptyList(), 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();
    SearchFields searchFields = new SearchFields();
    searchFields.setBundleSymbolicName("org.apache.felix.bundlerepository");
    searchFields.setBundleVersion("1.6.6");
    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.felix", hit.getGroupId());
    assertEquals("org.apache.felix.bundlerepository", hit.getArtifactId());
    assertEquals("1.6.6", hit.getVersions().get(0));
    assertEquals("org.apache.felix.bundlerepository;uses:=\"org.osgi.framework\";version=\"2.0\"", hit.getBundleExportPackage());
    assertEquals("org.apache.felix.bundlerepository.RepositoryAdmin,org.osgi.service.obr.RepositoryAdmin", hit.getBundleExportService());
    assertEquals("org.apache.felix.bundlerepository", hit.getBundleSymbolicName());
    assertEquals("1.6.6", hit.getBundleVersion());
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 3 with SearchResultHit

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

the class MavenRepositorySearchTest method testQuickSearch.

@Test
public void testQuickSearch() throws Exception {
    createSimpleIndex(false);
    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();
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    // search groupId
    archivaConfigControl.replay();
    results = search.search("user", selectedRepos, "org.apache.archiva", null, null);
    archivaConfigControl.verify();
    assertNotNull(results);
    assertEquals("total hints not 3", 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)

Example 4 with SearchResultHit

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

the class MavenRepositorySearchTest method testAdvancedSearchClassname.

@Test
public void testAdvancedSearchClassname() throws Exception {
    createIndexContainingMoreArtifacts(true);
    List<String> selectedRepos = Arrays.asList(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setClassName("com.classname.search.App");
    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("totalHits not 1 results " + results, 1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("groupId not com", "com", hit.getGroupId());
    assertEquals("arttifactId not classname-search", "classname-search", hit.getArtifactId());
    assertEquals(" hits.version(0) not 1.0", "1.0", hit.getVersions().get(0));
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) SearchResultHit(org.apache.archiva.indexer.search.SearchResultHit) SearchResults(org.apache.archiva.indexer.search.SearchResults) Test(org.junit.Test)

Example 5 with SearchResultHit

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

the class MavenRepositorySearchTest method testAdvancedSearchAllSearchCriteriaSpecified.

@Test
public void testAdvancedSearchAllSearchCriteriaSpecified() throws Exception {
    createSimpleIndex(true);
    List<String> selectedRepos = new ArrayList<>();
    selectedRepos.add(TEST_REPO_1);
    SearchFields searchFields = new SearchFields();
    searchFields.setGroupId("org.apache.archiva");
    searchFields.setArtifactId("archiva-test");
    searchFields.setVersion("2.0");
    searchFields.setPackaging("jar");
    searchFields.setClassName("org.apache.archiva.test.App");
    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("total hints not 1" + results, 1, results.getTotalHits());
    SearchResultHit hit = results.getHits().get(0);
    assertEquals("org.apache.archiva", hit.getGroupId());
    assertEquals("archiva-test", hit.getArtifactId());
    assertEquals("version not 2.0", "2.0", hit.getVersions().get(0));
}
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)

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