use of annis.service.objects.MatchAndDocumentCount in project ANNIS by korpling.
the class CountMatchesAndDocumentsSqlGenerator method extractData.
@Override
public MatchAndDocumentCount extractData(ResultSet rs) throws SQLException, DataAccessException {
MatchAndDocumentCount c = new MatchAndDocumentCount();
int tupleSum = 0;
int docSum = 0;
while (rs.next()) {
tupleSum += rs.getInt("tupleCount");
docSum += rs.getInt("docCount");
}
c.setMatchCount(tupleSum);
c.setDocumentCount(docSum);
return c;
}
use of annis.service.objects.MatchAndDocumentCount 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
//
}
use of annis.service.objects.MatchAndDocumentCount in project ANNIS by korpling.
the class CountCallback method run.
@Override
public void run() {
Future futureCount = ui.getQueryState().getExecutedTasks().get(QueryUIState.QueryType.COUNT);
final MatchAndDocumentCount countResult;
MatchAndDocumentCount tmpCountResult = null;
if (futureCount != null) {
UniformInterfaceException cause = null;
try {
tmpCountResult = (MatchAndDocumentCount) futureCount.get();
} catch (InterruptedException ex) {
log.warn(null, ex);
} catch (ExecutionException root) {
if (root.getCause() instanceof UniformInterfaceException) {
cause = (UniformInterfaceException) root.getCause();
} else {
log.error("Unexcepted ExecutionException cause", root);
}
} finally {
countResult = tmpCountResult;
}
ui.getQueryState().getExecutedTasks().remove(QueryUIState.QueryType.COUNT);
final UniformInterfaceException causeFinal = cause;
ui.accessSynchronously(new Runnable() {
@Override
public void run() {
if (causeFinal == null) {
if (countResult != null) {
String documentString = countResult.getDocumentCount() > 1 ? "documents" : "document";
String matchesString = countResult.getMatchCount() > 1 ? "matches" : "match";
ui.getSearchView().getControlPanel().getQueryPanel().setStatus("" + countResult.getMatchCount() + " " + matchesString + "\nin " + countResult.getDocumentCount() + " " + documentString);
if (countResult.getMatchCount() > 0 && panel != null) {
panel.getPaging().setPageSize(pageSize, false);
panel.setCount(countResult.getMatchCount());
}
}
} else {
ui.getQueryController().reportServiceException(causeFinal, true);
}
// end if cause != null
ui.getSearchView().getControlPanel().getQueryPanel().setCountIndicatorEnabled(false);
}
});
}
}
use of annis.service.objects.MatchAndDocumentCount in project ANNIS by korpling.
the class AnnisRunner method doCount.
public void doCount(String annisQuery) {
MatchAndDocumentCount count = queryDao.countMatchesAndDocuments(analyzeQuery(annisQuery, "count"));
if (!benchmarks.isEmpty()) {
Benchmark lastBench = benchmarks.get(benchmarks.size() - 1);
lastBench.count = count.getMatchCount();
}
out.println(count);
}
use of annis.service.objects.MatchAndDocumentCount in project ANNIS by korpling.
the class QueryServiceImpl method count.
@GET
@Path("search/count")
@Produces("application/xml")
@Override
public Response count(@QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames) {
requiredParameter(query, "q", "AnnisQL query");
requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names");
Subject user = SecurityUtils.getSubject();
List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames);
for (String c : corpusNames) {
user.checkPermission("query:count:" + c);
}
QueryData data = queryDataFromParameters(query, rawCorpusNames);
long start = new Date().getTime();
MatchAndDocumentCount count = queryDao.countMatchesAndDocuments(data);
long end = new Date().getTime();
logQuery("COUNT", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start);
return Response.ok(count).type(MediaType.APPLICATION_XML_TYPE).build();
}
Aggregations