Search in sources :

Example 1 with QueryJob

use of de.catma.queryengine.QueryJob in project catma by forTEXT.

the class AnalyzeView method executeSearch.

private void executeSearch(String searchInput, Consumer<QueryResultPanel> addToLayoutFunction) {
    QueryOptions queryOptions = new QueryOptions(new QueryId(searchInput), currentCorpus.getDocumentIds(), currentCorpus.getCollectionIds(), indexInfoSet.getUnseparableCharacterSequences(), indexInfoSet.getUserDefinedSeparatingCharacters(), indexInfoSet.getLocale(), project);
    QueryJob job = new QueryJob(searchInput, queryOptions);
    showProgress(true);
    ((BackgroundServiceProvider) UI.getCurrent()).submit("Searching...", job, new ExecutionListener<QueryResult>() {

        public void done(QueryResult result) {
            try {
                QueryResultPanel queryResultPanel = new QueryResultPanel(project, result, new QueryId(searchInput.toString()), kwicProviderCache, closingPanel -> handleRemoveQueryResultPanel(closingPanel));
                addToLayoutFunction.accept(queryResultPanel);
                addQueryResultPanelSetting(queryResultPanel.getQueryResultPanelSetting());
            } finally {
                showProgress(false);
            }
        }

        public void error(Throwable t) {
            showProgress(false);
            if (t instanceof QueryException) {
                QueryJob.QueryException qe = (QueryJob.QueryException) t;
                String input = qe.getInput();
                int idx = ((RecognitionException) qe.getCause()).charPositionInLine;
                if ((idx >= 0) && (input.length() > idx)) {
                    char character = input.charAt(idx);
                    String message = MessageFormat.format("<html><p>There is something wrong with your query <b>{0}</b> approximately at positon {1} character <b>{2}</b>.</p> <p>If you are unsure about how to construct a query try the Query Builder!</p></html>", input, idx + 1, character);
                    HTMLNotification.show("Info", message, Type.TRAY_NOTIFICATION);
                } else {
                    String message = MessageFormat.format("<html><p>There is something wrong with your query <b>{0}</b>.</p> <p>If you are unsure about how to construct a query try the Query Builder!</p></html>", input);
                    HTMLNotification.show("Info", message, Type.TRAY_NOTIFICATION);
                }
            } else {
                ((ErrorHandler) UI.getCurrent()).showAndLogError("Error during search!", t);
            }
        }
    });
}
Also used : ThemeResource(com.vaadin.server.ThemeResource) Panel(com.vaadin.ui.Panel) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) HTMLNotification(de.catma.ui.component.HTMLNotification) LoadingCache(com.google.common.cache.LoadingCache) WordCloudDisplaySettingHandler(de.catma.ui.module.analyze.visualization.vega.WordCloudDisplaySettingHandler) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) IndexedProject(de.catma.indexer.IndexedProject) KwicProvider(de.catma.indexer.KwicProvider) RecognitionException(org.antlr.runtime.RecognitionException) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Locale(java.util.Locale) SliderPanel(org.vaadin.sliderpanel.SliderPanel) VaadinIcons(com.vaadin.icons.VaadinIcons) QueryId(de.catma.queryengine.QueryId) ProgressBar(com.vaadin.ui.ProgressBar) IconButton(de.catma.ui.component.IconButton) ExecutionListener(de.catma.backgroundservice.ExecutionListener) QueryOptions(de.catma.queryengine.QueryOptions) IndexInfoSet(de.catma.document.source.IndexInfoSet) ClosableTab(de.catma.ui.component.tabbedview.ClosableTab) QueryBuilder(de.catma.ui.module.analyze.querybuilder.QueryBuilder) MarginInfo(com.vaadin.shared.ui.MarginInfo) List(java.util.List) Type(com.vaadin.ui.Notification.Type) Corpus(de.catma.document.corpus.Corpus) RefreshQueryResultPanel(de.catma.ui.module.analyze.queryresultpanel.RefreshQueryResultPanel) Optional(java.util.Optional) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) QueryJob(de.catma.queryengine.QueryJob) SliderMode(org.vaadin.sliderpanel.client.SliderMode) KwicPanel(de.catma.ui.module.analyze.visualization.kwic.KwicPanel) FormatStyle(java.time.format.FormatStyle) QueryResultPanelSetting(de.catma.ui.module.analyze.queryresultpanel.QueryResultPanelSetting) DoubleTreePanel(de.catma.ui.module.analyze.visualization.doubletree.DoubleTreePanel) QueryResultPanel(de.catma.ui.module.analyze.queryresultpanel.QueryResultPanel) VerticalLayout(com.vaadin.ui.VerticalLayout) LocalDateTime(java.time.LocalDateTime) ComboBox(com.vaadin.ui.ComboBox) WizardContext(de.catma.ui.dialog.wizard.WizardContext) DistributionDisplaySettingHandler(de.catma.ui.module.analyze.visualization.vega.DistributionDisplaySettingHandler) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) VegaPanel(de.catma.ui.module.analyze.visualization.vega.VegaPanel) Label(com.vaadin.ui.Label) ClassResource(com.vaadin.server.ClassResource) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) QueryException(de.catma.queryengine.QueryJob.QueryException) AnalyzeResourcePanel(de.catma.ui.module.analyze.resourcepanel.AnalyzeResourcePanel) ListDataProvider(com.vaadin.data.provider.ListDataProvider) QueryResult(de.catma.queryengine.result.QueryResult) Iterator(java.util.Iterator) Consumer(java.util.function.Consumer) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TabCaptionChangeListener(de.catma.ui.component.tabbedview.TabCaptionChangeListener) DateTimeFormatter(java.time.format.DateTimeFormatter) QueryTree(de.catma.queryengine.querybuilder.QueryTree) Collections(java.util.Collections) Component(com.vaadin.ui.Component) QueryResult(de.catma.queryengine.result.QueryResult) QueryException(de.catma.queryengine.QueryJob.QueryException) QueryJob(de.catma.queryengine.QueryJob) RefreshQueryResultPanel(de.catma.ui.module.analyze.queryresultpanel.RefreshQueryResultPanel) QueryResultPanel(de.catma.ui.module.analyze.queryresultpanel.QueryResultPanel) QueryId(de.catma.queryengine.QueryId) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) QueryOptions(de.catma.queryengine.QueryOptions)

Aggregations

MaterialTheme (com.github.appreciated.material.MaterialTheme)1 LoadingCache (com.google.common.cache.LoadingCache)1 EventBus (com.google.common.eventbus.EventBus)1 ListDataProvider (com.vaadin.data.provider.ListDataProvider)1 VaadinIcons (com.vaadin.icons.VaadinIcons)1 ClassResource (com.vaadin.server.ClassResource)1 ThemeResource (com.vaadin.server.ThemeResource)1 MarginInfo (com.vaadin.shared.ui.MarginInfo)1 Alignment (com.vaadin.ui.Alignment)1 Button (com.vaadin.ui.Button)1 ComboBox (com.vaadin.ui.ComboBox)1 Component (com.vaadin.ui.Component)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 Notification (com.vaadin.ui.Notification)1 Type (com.vaadin.ui.Notification.Type)1 Panel (com.vaadin.ui.Panel)1 ProgressBar (com.vaadin.ui.ProgressBar)1 UI (com.vaadin.ui.UI)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1