Search in sources :

Example 1 with DisplayedResultQuery

use of annis.gui.objects.DisplayedResultQuery in project ANNIS by korpling.

the class QueryController method executeSearch.

/**
 * Executes a query.
 * @param replaceOldTab
 * @param freshQuery If true the offset and the selected matches are reset before executing the query.
 */
public void executeSearch(boolean replaceOldTab, boolean freshQuery) {
    if (freshQuery) {
        getState().getOffset().setValue(0l);
        getState().getSelectedMatches().setValue(new TreeSet<Long>());
        // get the value for the visible segmentation from the configured context
        Set<String> selectedCorpora = getState().getSelectedCorpora().getValue();
        CorpusConfig config = new CorpusConfig();
        if (selectedCorpora != null && !selectedCorpora.isEmpty()) {
            config = ui.getCorpusConfigWithCache(selectedCorpora.iterator().next());
        }
        if (config.containsKey(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION)) {
            String configVal = config.getConfig(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION);
            if ("".equals(configVal) || "tok".equals(configVal)) {
                configVal = null;
            }
            getState().getVisibleBaseText().setValue(configVal);
        } else {
            getState().getVisibleBaseText().setValue(getState().getContextSegmentation().getValue());
        }
    }
    // construct a query from the current properties
    DisplayedResultQuery displayedQuery = getSearchQuery();
    searchView.getControlPanel().getQueryPanel().setStatus("Searching...");
    cancelSearch();
    // cleanup resources
    VaadinSession session = VaadinSession.getCurrent();
    session.setAttribute(IFrameResourceMap.class, new IFrameResourceMap());
    if (session.getAttribute(MediaController.class) != null) {
        session.getAttribute(MediaController.class).clearMediaPlayers();
    }
    searchView.updateFragment(displayedQuery);
    if (displayedQuery.getCorpora() == null || displayedQuery.getCorpora().isEmpty()) {
        Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE);
        return;
    }
    if ("".equals(displayedQuery.getQuery())) {
        Notification.show("Empty query", Notification.Type.WARNING_MESSAGE);
        return;
    }
    addHistoryEntry(displayedQuery);
    AsyncWebResource res = Helper.getAnnisAsyncWebResource();
    // 
    // begin execute match fetching
    // 
    ResultViewPanel oldPanel = searchView.getLastSelectedResultView();
    if (replaceOldTab) {
        // remove old panel from view
        searchView.closeTab(oldPanel);
    }
    ResultViewPanel newResultView = new ResultViewPanel(ui, ui, ui.getInstanceConfig(), displayedQuery);
    newResultView.getPaging().addCallback(new SpecificPagingCallback(ui, searchView, newResultView, displayedQuery));
    TabSheet.Tab newTab;
    List<ResultViewPanel> existingResultPanels = getResultPanels();
    String caption = existingResultPanels.isEmpty() ? "Query Result" : "Query Result #" + (existingResultPanels.size() + 1);
    newTab = searchView.getMainTab().addTab(newResultView, caption);
    newTab.setClosable(true);
    newTab.setIcon(FontAwesome.SEARCH);
    searchView.getMainTab().setSelectedTab(newResultView);
    searchView.notifiyQueryStarted();
    Background.run(new ResultFetchJob(displayedQuery, newResultView, ui));
    // 
    // end execute match fetching
    // 
    // 
    // begin execute count
    // 
    // start count query
    searchView.getControlPanel().getQueryPanel().setCountIndicatorEnabled(true);
    AsyncWebResource countRes = res.path("query").path("search").path("count").queryParam("q", Helper.encodeJersey(displayedQuery.getQuery())).queryParam("corpora", Helper.encodeJersey(StringUtils.join(displayedQuery.getCorpora(), ",")));
    Future<MatchAndDocumentCount> futureCount = countRes.get(MatchAndDocumentCount.class);
    state.getExecutedTasks().put(QueryUIState.QueryType.COUNT, futureCount);
    Background.run(new CountCallback(newResultView, displayedQuery.getLimit(), ui));
// 
// end execute count
// 
}
Also used : MediaController(annis.libgui.media.MediaController) VaadinSession(com.vaadin.server.VaadinSession) ResultViewPanel(annis.gui.resultview.ResultViewPanel) SingleResultFetchJob(annis.gui.resultfetch.SingleResultFetchJob) ResultFetchJob(annis.gui.resultfetch.ResultFetchJob) CountCallback(annis.gui.controller.CountCallback) CorpusConfig(annis.service.objects.CorpusConfig) TabSheet(com.vaadin.ui.TabSheet) IFrameResourceMap(annis.libgui.visualizers.IFrameResourceMap) DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery) SpecificPagingCallback(annis.gui.controller.SpecificPagingCallback) MatchAndDocumentCount(annis.service.objects.MatchAndDocumentCount) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource)

Example 2 with DisplayedResultQuery

use of annis.gui.objects.DisplayedResultQuery in project ANNIS by korpling.

the class SearchView method evaluateFragment.

private void evaluateFragment(String fragment) {
    // do nothing if not changed
    if (fragment == null || fragment.isEmpty() || fragment.equals(lastEvaluatedFragment)) {
        return;
    }
    Map<String, String> args = Helper.parseFragment(fragment);
    if (args.containsKey("c")) {
        String[] originalCorpusNames = args.get("c").split("\\s*,\\s*");
        Set<String> corpora = getMappedCorpora(Arrays.asList(originalCorpusNames));
        if (corpora.isEmpty()) {
            if (Helper.getUser() == null && toolbar != null) {
                // not logged in, show login window
                boolean onlyCorpusSelected = args.containsKey("c") && args.size() == 1;
                toolbar.showLoginWindow(!onlyCorpusSelected);
            } else {
                // already logged in or no login system available, just display a message
                new Notification("Linked corpus does not exist", "<div><p>The corpus you wanted to access unfortunally does not (yet) exist" + " in ANNIS.</p>" + "<h2>possible reasons are:</h2>" + "<ul>" + "<li>that it has not been imported yet,</li>" + "<li>you don't have the access rights to see this corpus,</li>" + "<li>or the ANNIS service is not running.</li>" + "</ul>" + "<p>Please ask the responsible person of the site that contained " + "the link to import the corpus.</p></div>", Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
        } else // end if corpus list returned from service is empty
        {
            if (args.containsKey("c") && args.size() == 1) {
                // special case: we were called from outside and should only select,
                // but not query, the selected corpora
                ui.getQueryState().getSelectedCorpora().setValue(corpora);
            } else if (args.get("cl") != null && args.get("cr") != null) {
                // make sure the properties are not overwritten by the background process
                getControlPanel().getSearchOptions().setUpdateStateFromConfig(false);
                DisplayedResultQuery query = QueryGenerator.displayed().left(Integer.parseInt(args.get("cl"))).right(Integer.parseInt(args.get("cr"))).offset(Integer.parseInt(args.get("s"))).limit(Integer.parseInt(args.get("l"))).segmentation(args.get("seg")).baseText(args.get("bt")).query(args.get("q")).corpora(corpora).build();
                if (query.getBaseText() == null && query.getSegmentation() != null) {
                    // if no explicit visible segmentation was given use the same as the context
                    query.setBaseText(query.getSegmentation());
                }
                if (query.getBaseText() != null && query.getBaseText().isEmpty()) {
                    // empty string means "null"
                    query.setBaseText(null);
                }
                String matchSelectionRaw = args.get("m");
                if (matchSelectionRaw != null) {
                    for (String selectedMatchNr : Splitter.on(',').omitEmptyStrings().trimResults().split(matchSelectionRaw)) {
                        try {
                            long nr = Long.parseLong(selectedMatchNr);
                            query.getSelectedMatches().add(nr);
                        } catch (NumberFormatException ex) {
                            log.warn("Invalid long provided as selected match", ex);
                        }
                    }
                }
                if (args.get("o") != null) {
                    try {
                        query.setOrder(OrderType.valueOf(args.get("o").toLowerCase()));
                    } catch (IllegalArgumentException ex) {
                        log.warn("Could not parse query fragment argument for order", ex);
                    }
                }
                // full query with given context
                ui.getQueryController().setQuery(query);
                ui.getQueryController().executeSearch(true, false);
            } else if (args.get("q") != null) {
                // use default context
                ui.getQueryController().setQuery(new Query(args.get("q"), corpora));
                ui.getQueryController().executeSearch(true, true);
            }
            getControlPanel().getCorpusList().scrollToSelectedCorpus();
        }
    // end if corpus list from server was non-empty
    }
// end if there is a corpus definition
}
Also used : DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery) PagedResultQuery(annis.gui.objects.PagedResultQuery) Query(annis.gui.objects.Query) DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery) Notification(com.vaadin.ui.Notification)

Example 3 with DisplayedResultQuery

use of annis.gui.objects.DisplayedResultQuery in project ANNIS by korpling.

the class CitationLinkGenerator method generateCell.

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    Button btLink = new Button();
    btLink.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    btLink.setIcon(FontAwesome.SHARE_ALT);
    btLink.setDescription("Share query reference link");
    btLink.addClickListener(this);
    if (itemId instanceof DisplayedResultQuery) {
        btLink.addClickListener(new LinkClickListener((DisplayedResultQuery) itemId));
    } else if (itemId instanceof Query) {
        final CitationProvider citationProvider = new CitationProviderForQuery((Query) itemId);
        btLink.addClickListener(new LinkClickListener(citationProvider));
    } else if (itemId instanceof CitationProvider) {
        final CitationProvider citationProvider = (CitationProvider) itemId;
        btLink.addClickListener(new LinkClickListener(citationProvider));
    }
    return btLink;
}
Also used : CitationProvider(annis.gui.beans.CitationProvider) ContextualizedQuery(annis.gui.objects.ContextualizedQuery) DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery) Query(annis.gui.objects.Query) Button(com.vaadin.ui.Button) DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery)

Aggregations

DisplayedResultQuery (annis.gui.objects.DisplayedResultQuery)3 Query (annis.gui.objects.Query)2 CitationProvider (annis.gui.beans.CitationProvider)1 CountCallback (annis.gui.controller.CountCallback)1 SpecificPagingCallback (annis.gui.controller.SpecificPagingCallback)1 ContextualizedQuery (annis.gui.objects.ContextualizedQuery)1 PagedResultQuery (annis.gui.objects.PagedResultQuery)1 ResultFetchJob (annis.gui.resultfetch.ResultFetchJob)1 SingleResultFetchJob (annis.gui.resultfetch.SingleResultFetchJob)1 ResultViewPanel (annis.gui.resultview.ResultViewPanel)1 MediaController (annis.libgui.media.MediaController)1 IFrameResourceMap (annis.libgui.visualizers.IFrameResourceMap)1 CorpusConfig (annis.service.objects.CorpusConfig)1 MatchAndDocumentCount (annis.service.objects.MatchAndDocumentCount)1 AsyncWebResource (com.sun.jersey.api.client.AsyncWebResource)1 VaadinSession (com.vaadin.server.VaadinSession)1 Button (com.vaadin.ui.Button)1 Notification (com.vaadin.ui.Notification)1 TabSheet (com.vaadin.ui.TabSheet)1