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);
}
}
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);
}
}
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();
}
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());
}
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
}
Aggregations