Search in sources :

Example 1 with PerformEntitySearchResult

use of edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult in project webprotege by protegeproject.

the class PerformEntitySearchActionHandler method execute.

@Nonnull
@Override
public PerformEntitySearchResult execute(@Nonnull PerformEntitySearchAction action, @Nonnull ExecutionContext executionContext) {
    Set<EntityType<?>> entityTypes = action.getEntityTypes();
    String searchString = action.getSearchString();
    EntitySearcher entitySearcher = EntitySearcher.get(projectId, tagsManager, executionContext.getUserId(), () -> entityStream(entityTypes, rootOntology, Imports.INCLUDED), renderer, entityTypes, searchString);
    PageRequest pageRequest = action.getPageRequest();
    int pageSize = pageRequest.getPageSize();
    entitySearcher.setLimit(pageSize);
    int pageNumber = pageRequest.getPageNumber();
    entitySearcher.setSkip((pageNumber - 1) * pageSize);
    entitySearcher.invoke();
    int totalSearchResults = entitySearcher.getSearchResultsCount();
    List<EntitySearchResult> results = entitySearcher.getResults();
    int pageCount = (totalSearchResults / pageSize) + 1;
    Page<EntitySearchResult> page = new Page<>(pageNumber > pageCount ? 1 : pageNumber, pageCount, results, totalSearchResults);
    return new PerformEntitySearchResult(totalSearchResults, page);
}
Also used : EntityType(org.semanticweb.owlapi.model.EntityType) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) EntitySearchResult(edu.stanford.bmir.protege.web.shared.search.EntitySearchResult) PerformEntitySearchResult(edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult) PerformEntitySearchResult(edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult) Nonnull(javax.annotation.Nonnull)

Aggregations

Page (edu.stanford.bmir.protege.web.shared.pagination.Page)1 PageRequest (edu.stanford.bmir.protege.web.shared.pagination.PageRequest)1 EntitySearchResult (edu.stanford.bmir.protege.web.shared.search.EntitySearchResult)1 PerformEntitySearchResult (edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult)1 Nonnull (javax.annotation.Nonnull)1 EntityType (org.semanticweb.owlapi.model.EntityType)1