Search in sources :

Example 1 with SearchResult

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);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 2 with SearchResult

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);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 3 with SearchResult

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() + ")");
    }
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) SearchService(org.eclipse.sw360.datahandler.thrift.search.SearchService) THttpClient(org.apache.thrift.transport.THttpClient) SearchResult(org.eclipse.sw360.datahandler.thrift.search.SearchResult) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Example 4 with SearchResult

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;
}
Also used : TException(org.apache.thrift.TException) SearchResult(org.eclipse.sw360.datahandler.thrift.search.SearchResult)

Example 5 with SearchResult

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;
}
Also used : SearchResult(org.eclipse.sw360.datahandler.thrift.search.SearchResult)

Aggregations

TException (org.apache.thrift.TException)4 SearchResult (org.eclipse.sw360.datahandler.thrift.search.SearchResult)4 User (org.eclipse.sw360.datahandler.thrift.users.User)3 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)2 SearchService (org.eclipse.sw360.datahandler.thrift.search.SearchService)2 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1