Search in sources :

Example 1 with EntitySearchResult

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

the class EntitySearcher method toSearchResult.

private EntitySearchResult toSearchResult(Pattern searchPattern, SearchMatch ren) {
    OWLEntityData ed = ren.getEntityData();
    String rendering = ed.getBrowserText();
    StringBuilder highlighted = new StringBuilder();
    highlightSearchResult(searchPattern, rendering, highlighted);
    if (ren.getMatchType() == MatchType.IRI) {
        // Matched the IRI remainder
        highlighted.append("<div class=\"searchedIri\">");
        IRI iri = ed.getEntity().getIRI();
        highlightSearchResult(searchPattern, iri.toString(), highlighted);
        highlighted.append("</div>");
    }
    if (ren.getMatchType() == MatchType.TAG) {
        for (Tag tag : tagsByEntity.get(ed.getEntity())) {
            if (searchString.equalsIgnoreCase(tag.getLabel())) {
                highlighted.append("<div class='wp-tag wp-tag--inline-tag' style='display: inline-block; color: ").append(tag.getColor().getHex()).append("; background-color:").append(tag.getBackgroundColor().getHex()).append(";'>");
                highlighted.append(tag.getLabel());
                highlighted.append("</div>");
            }
        }
    }
    return new EntitySearchResult(ed, displayName(), highlighted.toString());
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) EntitySearchResult(edu.stanford.bmir.protege.web.shared.search.EntitySearchResult)

Example 2 with EntitySearchResult

use of edu.stanford.bmir.protege.web.shared.search.EntitySearchResult 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)

Example 3 with EntitySearchResult

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

the class SearchPresenter method performSearch.

private void performSearch() {
    GWT.log("[SearchPresenter] Performing search");
    if (view.getSearchString().isEmpty()) {
        view.clearSearchMatches();
        return;
    }
    int pageNumber = view.getPageNumber();
    dispatchServiceManager.execute(new PerformEntitySearchAction(projectId, view.getSearchString(), entityTypes, PageRequest.requestPage(pageNumber)), view, result -> {
        Page<EntitySearchResult> results = result.getResults();
        view.setSearchMatches(result.getTotalResultCount(), results.getPageElements());
        view.setPageCount(results.getPageCount());
        view.setPageNumber(results.getPageNumber());
    });
}
Also used : PerformEntitySearchAction(edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchAction) EntitySearchResult(edu.stanford.bmir.protege.web.shared.search.EntitySearchResult)

Aggregations

EntitySearchResult (edu.stanford.bmir.protege.web.shared.search.EntitySearchResult)3 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)1 Page (edu.stanford.bmir.protege.web.shared.pagination.Page)1 PageRequest (edu.stanford.bmir.protege.web.shared.pagination.PageRequest)1 PerformEntitySearchAction (edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchAction)1 PerformEntitySearchResult (edu.stanford.bmir.protege.web.shared.search.PerformEntitySearchResult)1 Tag (edu.stanford.bmir.protege.web.shared.tag.Tag)1 Nonnull (javax.annotation.Nonnull)1 EntityType (org.semanticweb.owlapi.model.EntityType)1 IRI (org.semanticweb.owlapi.model.IRI)1