use of org.eclipse.sw360.datahandler.thrift.search.SearchResult in project sw360portal by sw360.
the class ProjectPortlet method serveProjectSearchResults.
private void serveProjectSearchResults(ResourceRequest request, ResourceResponse response, String searchText) throws IOException, PortletException {
final User user = UserCacheHolder.getUserFromRequest(request);
List<Project> searchResult;
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
if (isNullOrEmpty(searchText)) {
searchResult = client.getAccessibleProjectsSummary(user);
} else {
searchResult = client.searchByName(searchText, user);
}
} catch (TException e) {
log.error("Error searching projects", e);
searchResult = Collections.emptyList();
}
request.setAttribute(PortalConstants.PROJECT_SEARCH, searchResult);
include("/html/projects/ajax/searchProjectsAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
use of org.eclipse.sw360.datahandler.thrift.search.SearchResult in project sw360portal by sw360.
the class ProjectPortlet method serveReleasesFromLinkedProjects.
private void serveReleasesFromLinkedProjects(ResourceRequest request, ResourceResponse response, String projectId) throws IOException, PortletException {
List<Release> searchResult;
Set<String> releaseIdsFromLinkedProjects = new HashSet<>();
User user = UserCacheHolder.getUserFromRequest(request);
try {
ComponentService.Iface componentClient = thriftClients.makeComponentClient();
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
Project project = projectClient.getProjectById(projectId, user);
Map<String, ProjectRelationship> linkedProjects = CommonUtils.nullToEmptyMap(project.getLinkedProjects());
for (String linkedProjectId : linkedProjects.keySet()) {
Project linkedProject = projectClient.getProjectById(linkedProjectId, user);
if (linkedProject != null) {
Map<String, ProjectReleaseRelationship> releaseIdToUsage = CommonUtils.nullToEmptyMap(linkedProject.getReleaseIdToUsage());
releaseIdsFromLinkedProjects.addAll(releaseIdToUsage.keySet());
}
}
if (releaseIdsFromLinkedProjects.size() > 0) {
searchResult = componentClient.getReleasesById(releaseIdsFromLinkedProjects, user);
} else {
searchResult = Collections.emptyList();
}
} catch (TException e) {
log.error("Error searching projects", e);
searchResult = Collections.emptyList();
}
request.setAttribute(PortalConstants.RELEASE_SEARCH, searchResult);
include("/html/utils/ajax/searchReleasesAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
use of org.eclipse.sw360.datahandler.thrift.search.SearchResult in project sw360portal by sw360.
the class TestSearchClient method main.
public static void main(String[] args) throws TException, IOException {
THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/search/thrift");
TProtocol protocol = new TCompactProtocol(thriftClient);
SearchService.Iface client = new SearchService.Client(protocol);
List<SearchResult> results = client.search(searchtext, null);
// List<SearchResult> results = new SearchHandler().search(searchtext);
// http://localhost:5984/_fti/local/sw360db/_design/lucene/all?q=type:project%20AND%20P1*
System.out.println("Fetched " + results.size() + " from search service");
for (SearchResult result : results) {
System.out.println(result.getId() + "(" + result.getType() + "): " + result.getName() + " (" + result.getScore() + ")");
}
}
use of org.eclipse.sw360.datahandler.thrift.search.SearchResult in project sw360portal by sw360.
the class SearchHandler method searchFiltered.
@Override
public List<SearchResult> searchFiltered(String text, User user, List<String> typeMask) throws TException {
if (text == null)
throw new TException("Search text was null.");
if ("".equals(text))
return Collections.emptyList();
// Query new and old database
List<SearchResult> results = Lists.newArrayList();
if (typeMask.contains(SW360Constants.TYPE_USER)) {
results.addAll(dbSw360users.search(text, Arrays.asList(SW360Constants.TYPE_USER), user));
}
results.addAll(dbSw360db.search(text, typeMask, user));
Collections.sort(results, new SearchResultComparator());
if (log.isTraceEnabled())
log.trace("Search for " + text + " returned " + results.size() + " results");
return results;
}
use of org.eclipse.sw360.datahandler.thrift.search.SearchResult in project sw360portal by sw360.
the class AbstractDatabaseSearchHandler method makeSearchResult.
/**
* Transforms a LuceneResult row into a Thrift SearchResult object
*/
private static SearchResult makeSearchResult(LuceneResult.Row row) {
SearchResult result = new SearchResult();
// Set row properties
result.id = row.getId();
result.score = row.getScore();
// Get document and
SearchDocument parser = new SearchDocument(row.getDoc());
// Get basic search results information
result.type = parser.getType();
result.name = parser.getName();
return result;
}
Aggregations